Java Messaging Service - PowerPoint PPT Presentation

1 / 27
About This Presentation
Title:

Java Messaging Service

Description:

no persistent connection between parties, including MOM. Enterprise Message vs RPC ... Indirect communication through MOM. Best for single, possibly n-tiered, system ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 28
Provided by: roberta138
Category:
Tags: java | messaging | mom | older | service

less

Transcript and Presenter's Notes

Title: Java Messaging Service


1
Java Messaging Service
  • Notes prepared from GBC Professional Development
    Seminar Understanding the Java Messaging Service
    David Chappell Rick Kuzyk, Sonic Software.

2
Messaging
  • Data exchange requirements between disparate
    applications
  • B2C components (and clients)
  • catalogs
  • order
  • payment
  • fulfillment
  • support

3
Messaging
  • Data exchange requirements between disparate
    applications
  • B2B components (and clients)
  • wholesale??retail
  • accounts payable and receivable
  • Disconnected users (mobile, handheld)
  • package delivery
  • maintenance
  • web phones

4
Messaging
  • Data exchange requirements between disparate
    applications
  • B2B components (and clients)
  • wholesale??retail
  • accounts payable and receivable
  • Disconnected users (mobile, handheld)
  • package delivery
  • maintenance
  • web phones

5
Enterprise Messaging (MOM)
  • Message oriented middleware (MOM)
  • Asynchronous messaging sender need not wait for
    reply
  • decoupled sender and receiverno direct
    communication
  • no persistent connection between parties,
    including MOM

6
Enterprise Message vs RPC
Enterprise Messaging RPC
Asynchronous Synchronous (Req/Rpy)
Tolerates partial failure Partial failure can affect entire application
Transparent support for distributed systems Best for single, possibly n-tiered, system
Indirect communication through MOM Direct communication between processes
Applications decoupled Applications coupled
7
Enterprise messaging
Application A
Application A
MOM
Messaging API
Messaging API
Messaging Clients
Messaging Clients
8
Tightly coupled RPC
App C
App A
n(n-1)/2 connections
RPC infrastructure
RPC infrastructure
App D
RPC infrastructure
9
JMS Messaging
JMS Client
JMS Client
JMS Client
Router
Local "server"
Message server
JMS Client
JMS Client
JMS Client
JMS Client
JMS Client
JMS Client
Local "server"
Local "server"
Decentralized (IP multicast)
Hub and spoke
10
JMS
  • JMS Messaging client
  • Uses the JMS API to create, send, receive
    messages
  • Interfaces and classes or the API client
    runtime
  • JMS Message server
  • handles deliver of messages sent by clients to
    other messaging clients who register an interest
  • JMS provider JMS client runtime message
    server.
  • supports the JMS API and reliable delivery
  • J2EE provides glue that lets certain objects to
    run as a JMS messaging client

11
JMS and J2EE
  • These objects can function as JMS messaging
    clients via J2EE
  • enterprise beans (EJB)
  • servlets
  • JSP pages
  • J2EE application client
  • message-driven bean an EJB that can consume JSP
    messages

12
J2EE
Client application
EJB Container
Application Client Container
Web Container
J2EE platform
JMS Server
JDBC Server
13
JMS Client classes
Connection Binds a JMS client to a message server. multiple per client associated with either pub/sub or PTP
Session Context for sending/receiving messages multiple per Connection
Producer sends messages to Destinations
Destination identifier for a message
Message package sent from a producer to a consumer
14
JMS Components
Message server
Destination
Message
Message
15
JMS Components
JMS Client
JMS Client
Consumer
Producer
Bind to Destination
Bind to Destination
Message server
Destination
SendMessage
ConsumeMessage
16
JMS Client objects
  • Producer
  • Binds to a destination to send messages
  • Determines message TTL, priority, persistence
  • Consumer
  • Binds to a destination to receive messages
  • Receives messages asynchronously through a
    message listener or synchronously by polling

17
JMS Client objects
  • Messages
  • Headers
  • Property list (some predefined) Consumers can
    select on properties
  • Body

18
JMS Message types
Message type Body
Message Empty
TextMessage Java String
ObjectMessage Serializable Java object
MapMessage Name/value pairs
StreamMessage Stream of Java primitives
BytesMessage Uninterpreted bytes
19
Messaging Domains
  • Publish and subscribe (pub/sub)
  • Many consumers per message
  • Messages have a topic that identifies the
    relation of publisher to subscriber
  • Point-to-point (PTP, p2p)
  • One consumer per message
  • Messages queued. Consumers can browse queue
    without consuming

20
Pub/Sub model
Publisher
Topic
Subscriber
New books
HW
21
P2P model
Sender
Que
Receiver
Submit
Grade
PARTY!
22
Connections and sessions
  • jndi new InitialCOntext(env)tFactory
    (TopicConnectionFactory)jndi.lookup("TopicConne
    ctionFactory")qFactory QueueConnectionFactory
    )jndi.lookup("QueueConnectionFactory")
  • tConnect tFactory.createTopicConnection(unserna
    me, password)qConnect qFactory.createQueueConn
    ection(unsername, password)
  • tSession
  • tConnect.createTopicSession(false,
    Session.AUTO_ACKNOWLEDGE)qSession
  • qConnect.createQueueSession(false,
    Session.AUTO_ACKNOWLEDGE)
  • tConnect.start()
  • qConnect.start()

23
Destinations
  • Pub/sub topics
  • May be predetermined by server
  • May be created on a server by a JMS client
  • Topic hw9Topic tSession.createTopic("hw9")
  • May be looked up in a db via Java Naming and
    Directory Interface (JNDI)
  • Topic hw9Topic (Topic)jndi.lookup("hw9")

24
Destinations
  • P2P queues
  • Queue must exist in server
  • Queue hwQ tSession.createQueue("HW") // or
  • Queue hwQ (Queue) jndi.lookup("HW")

25
Creating and populating a message
Queue SessionqSession
qSession.createTextMessage()
Text MessagetextMsg
String thisHW"hw9"textMsg.createContent("GreatJ
ob on" thisHW)
26
JMS message headers
  • Assigned by system
  • JMSDestination
  • JMSDeliveryMode
  • JMSMessageID
  • JMSTimestamp
  • JMSExpiration
  • JMS Priority
  • Assigned by developer
  • JMSReplyTo
  • JMSCorrelationID
  • JMSType

27
Message properties
  • Name/value pairs assigned by application
  • Values must be Java primitives
  • Setting
  • message.setStringProperty("studentName", "Nemo")
    //prop
  • message.setJMSReplyTo(hw9Q) //header
  • Can filter on props or headers
  • javax.jms.QueueReceiver rcvr
    qSession.createReceiver(hw9Q, "JMSPriority gt
    10")
Write a Comment
User Comments (0)
About PowerShow.com