Java message service
This presentation is the property of its rightful owner.
Sponsored Links
1 / 38

Java Message Service PowerPoint PPT Presentation


  • 99 Views
  • Uploaded on
  • Presentation posted in: General

Java Message Service. Sangeetha Chavala. What is Messaging?. Method of Communication between software components/applications peer-to-peer facility Not another Mail API!!!. Messaging System Concepts.

Download Presentation

Java Message Service

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Java message service

Java Message Service

Sangeetha Chavala


What is messaging

What is Messaging?

  • Method of Communication between software components/applications

  • peer-to-peer facility

  • Not another Mail API!!!


Messaging system concepts

Messaging System Concepts

  • Allows loosely coupled applications to communicate - contrast with RPC

  • Asynchronous

  • Reliable


Messaging systems advantages

Messaging Systems Advantages

  • Platform &Network Location Independence

  • Flexibility

  • Scalability

  • Anonymity

  • Robustness

  • Asynchronous


What is the jms api

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


Common models of messaging

Common Models of Messaging

  • Point-to-Point

  • Publish/Subscribe


Point to point messaging

Point-to-Point Messaging

  • Only one consumer of Queue Message

  • No timing dependencies between Sender and Receiver


Publish subscribe messaging

Publish/Subscribe Messaging

  • Broadcast Message to all Subscribers


Jms application

JMS Application

  • JMS Provider

  • JMS Clients

  • Messages

  • Administered Objects

  • Non-JMS Clients


Messages

Messages

Message Components

  • Header

  • Properties

  • Body


Message header

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


Message properties

Message Properties

  • Application-specific properties

  • Messaging system provider-specific properties

  • Optional fields

  • Properties are Name/Value pairs

  • Values can be int, string, byte etc


Message body

Message Body

  • Holds content of message

  • Five Types supported

  • Each type defined by a message interface

    -StreamMessage

    -MapMessage

    -BytesMessage

    -TextMessage

    -ObjectMessage


Message body interfaces

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


Message body interfaces1

Message Body Interfaces

  • TextMessage

    -contains java.util.StringBuffer

    -useful for XML messages

  • ObjectMessage

    -contains arbitrary java object

    -must be serializable


Example creating a text message

Example:Creating a Text Message

  • To create a simple TextMessage:

    TextMessage message =

    session . createTextMessage( );

    message . setText ( “greetings”);


Building a jms client

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


1 creating a connection

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


Get the connection factory

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


Create the connection

Create the Connection

TopicConnection topicConnection =

factory . createTopicConnection ( ) ;

  • QueueConnection or TopicConnection


2 create sessions

2. Create Sessions

TopicSession session =

topicConnection . createTopicSession

(false, CLIENT_ACKNOWLEDGE);

  • First parameter controls transactions

  • Second parameter specifies message acknowledgement


Locate a topic

Locate a Topic

Topic weatherTopic =

messaging . Lookup ( “WeatherData” ) ;

  • JNDI is used to locate the topic

  • Queue or Topic


Start the connection

Start the Connection

topicConnection . start ( ) ;

  • During initialization, message flow is inhibited; Connection must now be started before messages will be transmitted


3 create message producer

3. Create Message Producer

TopicPublisher publisher =

session . createPublisher (weatherTopic) ;

  • Publisher will publish messages to weathetData topic


Publish a message

Publish a Message

TextMessage message =

session . createMessage ( ) ;

message . setText ( “text : 35 degrees” ) ;

publisher . Publish (message) ;


Specifying quality of service

Specifying Quality of Service

Publish (Message message, int deliveryMode,

int priority, long timeToLive) ;

  • Delivery Modes

    - NON-PERSISTENT

    - PERSISTENT

  • Priority

  • Time-to-Live


4 message consumer

4. Message Consumer

  • Subscribing to topics

    - Durable Subscriptions

    - Non-durable Subsriptions

  • Receiving Messages

    - Asynchronous

    - Synchronous


Asynchronous message receipt

Asynchronous Message Receipt

  • Uses Listening Mechanism

    setMessageListener (MessageListener

    listener)

  • Listener object must implement

    onMessage ( ) of MessageListener interface


Synchronous message receipt

Synchronous Message Receipt

Message receive ( ) ;

Message receive (long timeout) ;

Message receiveNoWait ( ) ;


Point to point programming

Point-to-Point Programming

  • Queue Browsing

    - session . createBrowser (Queue queue);

    - session . createBrowser (QueueSession

    session, Queue queue,

    String messageSelector) ;


Jms programming techniques and issues

JMS Programming Techniques and Issues

1. Transactions

- commit( ) ;

- rollback( ) ;

with respect to producer

with respect to consumer

2. Programmatic Message Acknowledgement

acknowledge ( );


Jms programming techniques and issues1

JMS Programming Techniques and Issues

3. 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


Using jms to transport xml

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) ;


Consuming xml messages

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


Java message service

  • 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’


Jms implementations

JMS Implementations

  • Standalone messaging servers

  • JMS services embedded within other environments such as an application server


Jms and xml as an integration platform

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


Topics discussed

Topics discussed

  • Messaging System Concepts

  • JMS Features

  • JMS Programming Techniques

  • JMS and XML as an Integration platform


  • Login