JMS- Quick Refresher


Extracts from the original Sun J2EE 1.3 JMS documentation

Amplify’d from docs.oracle.com

A connection factory is the object
a client uses to create a connection with a provider. A connection factory
encapsulates a set of connection configuration parameters that has been defined
by an administrator. A pair of connection factories come preconfigured with
the J2EE SDK and are accessible as soon as you start the service. Each connection
factory is an instance of either the QueueConnectionFactory or
the TopicConnectionFactory interface.

j2eeadmin -addJmsFactory jndi_name queue
j2eeadmin -addJmsFactory jndi_name topic
Context ctx = new InitialContext();
QueueConnectionFactory queueConnectionFactory = 
  (QueueConnectionFactory) ctx.lookup("QueueConnectionFactory");
TopicConnectionFactory topicConnectionFactory = 
  (TopicConnectionFactory) ctx.lookup("TopicConnectionFactory");
3.1.1   Connection Factories

3.1.2   Destinations

A destination is the object a client
uses to specify the target of messages it produces and the source of messages
it consumes. In the PTP messaging domain, destinations are called queues,
and you use the following J2EE SDK command to create them:

j2eeadmin -addJmsDestination queue_name queue
Queue myQueue = (Queue) ctx.lookup("MyQueue");
3.2   Connections

A connection encapsulates a virtual connection
with a JMS provider. A connection could represent an open TCP/IP socket between
a client and a provider service daemon. You use a connection to create one
or more sessions.

QueueConnection queueConnection =
  queueConnectionFactory.createQueueConnection();
TopicConnection topicConnection = 
  topicConnectionFactory.createTopicConnection();
A session is a single-threaded context
for producing and consuming messages. You use sessions to create message producers,
message consumers, and messages. Sessions serialize the execution of message
listeners; for details, see Section 3.5.1,
“Message Listeners.”
Sessions, like connections, come in two forms,
implementing either the QueueSession or the TopicSession
interface. For example, if you created a TopicConnection object,
you use it to create a TopicSession:
3.3   Sessions
3.4   Message Producers

A message producer is an object created
by a session and is used for sending messages to a destination. The PTP form
of a message producer implements the QueueSender interface. The
pub/sub form implements the TopicPublisher interface.

QueueSender queueSender = queueSession.createSender(myQueue);
TopicPublisher topicPublisher = topicSession.createPublisher(myTopic);
topicPublisher.publish(message);
3.5.1   Message Listeners
queueConnection.start();
Message m = queueReceiver.receive();
topicConnection.start();
Message m = topicSubscriber.receive(1000); // time out after a second

A message listener is an object that
acts as an asynchronous event handler for messages. This object implements
the MessageListener interface, which contains one method, onMessage.
In the onMessage method, you define the actions to be taken when
a message arrives.

3.5.2   Message Selectors

If your messaging application needs to filter the messages it receives, you can use a JMS API message selector, which allows a message consumer to specify the messages it is interested in. Message selectors assign the work of filtering messages to the JMS provider rather than to the application. For an example of the use of a message selector, see Chapter 8.

3.6   Messages

A JMS message has three parts:

3.6.3   Message Bodies

Table 3.2:    JMS Message Types

TextMessage

MapMessage

BytesMessage

StreamMessage

ObjectMessage

Read more at docs.oracle.com

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s