Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software...
-
Upload
garry-paul -
Category
Documents
-
view
219 -
download
1
Transcript of Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software...
![Page 1: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/1.jpg)
Java Message Service
Sangeetha Chavala
![Page 2: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/2.jpg)
What is Messaging? Method of Communication
between software components/applications
peer-to-peer facility Not another Mail API!!!
![Page 3: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/3.jpg)
Messaging System Concepts Allows loosely coupled applications
to communicate - contrast with RPC
Asynchronous Reliable
![Page 4: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/4.jpg)
Messaging Systems Advantages Platform &Network Location
Independence Flexibility Scalability Anonymity Robustness Asynchronous
![Page 5: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/5.jpg)
What is the JMS API? A common JavaTM platform API for
creating, sending, receiving and reading messages
Design Goals
-Provides most of the functionality of common messaging systems
-makes client applications portable across messaging products
- Leverages Java Technology
![Page 6: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/6.jpg)
Common Models of Messaging
Point-to-Point Publish/Subscribe
![Page 7: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/7.jpg)
Point-to-Point Messaging Only one consumer of Queue
Message No timing dependencies between
Sender and Receiver
![Page 8: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/8.jpg)
Publish/Subscribe Messaging Broadcast Message to all
Subscribers
![Page 9: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/9.jpg)
JMS Application JMS Provider JMS Clients Messages Administered Objects Non-JMS Clients
![Page 10: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/10.jpg)
Messages
Message Components
Header Properties Body
![Page 11: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/11.jpg)
Message Header Used for Message Identification and Routing Destination Field -includes Subject or Topic (for Pub/Sub) -queue(for point-to-point) Also include other data -delivery mode -message ID -timestamp -priority -ReplyTo
![Page 12: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/12.jpg)
Message Properties Application-specific properties Messaging system provider-
specific properties Optional fields Properties are Name/Value pairs Values can be int, string, byte etc
![Page 13: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/13.jpg)
Message Body Holds content of message Five Types supported Each type defined by a message interface -StreamMessage -MapMessage -BytesMessage -TextMessage -ObjectMessage
![Page 14: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/14.jpg)
Message Body Interfaces StreamMessage -contains Java primitive values -Read sequentially MapMessage -Holds name/value pairs -Read sequentially or by name BytesMessage -uninterpreted bytes -used to match an existing message
format
![Page 15: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/15.jpg)
Message Body Interfaces TextMessage -contains java.util.StringBuffer -useful for XML messages ObjectMessage -contains arbitrary java object -must be serializable
![Page 16: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/16.jpg)
Example:Creating a Text Message To create a simple TextMessage:
TextMessage message = session .
createTextMessage( ); message . setText ( “greetings”);
![Page 17: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/17.jpg)
Building a JMS Client Steps 1) Create a Connection to the
provider 2) Create Sessions to
send/receive messages 3) Create MessageProducers 4) Create MessageConsumers
![Page 18: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/18.jpg)
1. Creating a Connection Connection provides access to
messaging system Performs resource allocation and
management ConnectionFactory used to create
Connection ConnectionFactory is located
through JNDI
![Page 19: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/19.jpg)
Get the Connection Factory
Context messaging = new InitialContext ( ) ; TopicConnectionFactory factory = (TopicConnectionFactory) messaging . lookup
( “TopicConnectionFactory” ) ;
JNDI is used to get a ConnectionFactory 2 Types ConnectionFactory - QueueConnectionFactory for P-to-P
- TopicConnectionFactory for Pub/Sub
![Page 20: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/20.jpg)
Create the Connection
TopicConnection topicConnection = factory . createTopicConnection
( ) ;
QueueConnection or TopicConnection
![Page 21: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/21.jpg)
2. Create Sessions
TopicSession session = topicConnection . createTopicSession (false, CLIENT_ACKNOWLEDGE);
First parameter controls transactions Second parameter specifies message
acknowledgement
![Page 22: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/22.jpg)
Locate a Topic
Topic weatherTopic = messaging . Lookup
( “WeatherData” ) ;
JNDI is used to locate the topic Queue or Topic
![Page 23: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/23.jpg)
Start the Connection
topicConnection . start ( ) ;
During initialization, message flow is inhibited; Connection must now be started before messages will be transmitted
![Page 24: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/24.jpg)
3. Create Message Producer
TopicPublisher publisher = session . createPublisher
(weatherTopic) ;
Publisher will publish messages to weathetData topic
![Page 25: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/25.jpg)
Publish a Message
TextMessage message = session . createMessage ( ) ; message . setText ( “text : 35
degrees” ) ; publisher . Publish (message) ;
![Page 26: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/26.jpg)
Specifying Quality of Service
Publish (Message message, int deliveryMode,
int priority, long timeToLive) ; Delivery Modes - NON-PERSISTENT - PERSISTENT Priority Time-to-Live
![Page 27: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/27.jpg)
4. Message Consumer Subscribing to topics - Durable Subscriptions - Non-durable Subsriptions Receiving Messages - Asynchronous - Synchronous
![Page 28: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/28.jpg)
Asynchronous Message Receipt
Uses Listening Mechanism setMessageListener (MessageListener listener)
Listener object must implement onMessage ( ) of MessageListener
interface
![Page 29: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/29.jpg)
Synchronous Message Receipt
Message receive ( ) ; Message receive (long timeout) ; Message receiveNoWait ( ) ;
![Page 30: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/30.jpg)
Point-to-Point Programming
Queue Browsing - session . createBrowser (Queue
queue); - session . createBrowser
(QueueSession session, Queue queue, String messageSelector) ;
![Page 31: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/31.jpg)
JMS Programming Techniques and Issues
1. Transactions - commit( ) ; - rollback( ) ; with respect to producer with respect to consumer2. Programmatic Message
Acknowledgement acknowledge ( );
![Page 32: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/32.jpg)
JMS Programming Techniques and Issues3. Message Routing - Routing via Hierarchical Topics bid_request bid_request.vehicles bid_request.vehicles.bicycle - Routing via Message Selection Property_MerchType = ‘Mountain Bike’
AND Property_ReqOvernight is NULL Selecting a Routing Approach
![Page 33: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/33.jpg)
Using JMS to Transport XML
StringBuffer body = new StringBuffer ( ) ;body.append (“?xml version=\”1.0\ “?>\n”) ;body.append (“<message>\n”);body.append
(“<sender>”+username+“</sender>\n”) ;body.append (“<content>”+s+ “</content>\
n”) ;body.append (“</message>\n”) ;msg.setText (body.toString( )) ;publisher . Publish (msg) ;
![Page 34: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/34.jpg)
Consuming XML Messages Work with XML payload as a text
stream Work with the XML payload
through the DOM Use SAX to process the XML in an
event-based manner
![Page 35: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/35.jpg)
Performing XML-based Routing - Use Message Properties
Request-Reply Programming - Replies are sent as full JMS message typically following some processing
in the called ‘client’
![Page 36: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/36.jpg)
JMS Implementations Standalone messaging servers
JMS services embedded within other environments such as an application server
![Page 37: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/37.jpg)
JMS and XML as an Integration Platform
Integration Types - Data Integration - Procedural or Process Integration Messaging simplifies Application
Integration - can’t use Objects - XML proves to be an optimal
format
![Page 38: Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.](https://reader036.fdocuments.net/reader036/viewer/2022062718/56649e7d5503460f94b7fc93/html5/thumbnails/38.jpg)
Topics discussed Messaging System Concepts JMS Features JMS Programming Techniques JMS and XML as an Integration
platform