Home > Articles > Programming > Java

  • Print
  • + Share This
From the author of

Message-Driven Bean Client Interfaces

The client of a message-driven bean does not know that an EJB will actually handle the message on the receiving end. Instead, a message-driven bean client is constructed exactly in the manner in which a regular JMS client is constructed.

Message-Driven Bean Client Interface Logical Architecture

The core architecture behind JMS is depicted in Figure 4. Here we see that the Java Naming and Directory Interface (JNDI) is used to create an initial context to a JMS connection factory that is then used to create connections to JMS-based service providers. Given a JMS connection, a particular session context can be retrieved to create message producers and message consumers. In the case of message-driven bean clients, they are actually producers of the messages that will be received by the message-driven bean (that is, the message consumer).

Figure 4 The JMS core architecture.

Point-to-Point Message-Queuing Model

Figure 5 depicts the basic JMS architecture elements that support point-to-point message queuing. The message-queuing architecture is really an extension of the core JMS architecture with features to specifically implement message-queuing behavior. Connection factories, connections, sessions, message producers, message consumers, and endpoint destinations are all extended with point-to-point message-queuing model interfaces.

Figure 5 JMS point-to-point message queuing.

JMS clients use JNDI to obtain an initial reference to a named QueueConnectionFactory object. One of the QueueConnectionFactory.createQueueConnection() methods is used to create an instance of a QueueConnection object. The createQueueConnection() method can be called with a username and password or by using the parameterless version of the method with a default user identity assumed.

The QueueConnection interface is a type of Connection interface that represents a connection to a JMS point-to-point messaging queue service. The createQueueSession() method is called by JMS clients to create a QueueSession instance. Whether transactions are to be implemented by the QueueSession object is designated by a boolean parameter to createQueueSession(). Also, the acknowledgment mode is specified in the call to createQueueSession() using one of the static session identifiers, such as Session.AUTO_ACKNOWLEDGE, Session.CLIENT_ACKNOWLEDGE, or Session.DUPS_OK_ACKNOWLEDGE.

QueueSession.createQueue() creates an instance of a Queue object given a provider-specific name for that queue. The Queue interface encapsulates an interface to a queue destination using JMS's point-to-point messaging queue model and has a getQueueName() method to return the queue name.

The QueueSession.createSender() method creates a QueueSender message producer that is used to send messages to a Queue. Messages can be sent to a Queue using the various QueueSender.send() methods. Variations of these methods enable the delivery of messages to the QueueSender object's associated Queue or to a newly specified Queue object passed to the send() method. Delivery modes, priorities, and time to live for a message can also be specified during calls to QueueSender.send(). Messages to send to a Queue can be created using the various message-creation methods defined on the Session interface from which QueueSession extends.

Publish-Subscribe Model

Figure 6 depicts the basic JMS architecture elements that support publish-subscribe messaging. The publish-subscribe messaging architecture is also an extension of the core JMS architecture with features specialized to suit a publish-subscribe messaging model. Connection factories, connections, sessions, message producers, message consumers, and endpoint destinations are all extended with publish-subscribe message model interfaces.

Figure 6 JMS publish-subscribe messaging.

JMS clients use JNDI to obtain an initial reference to a named TopicConnectionFactory object. The TopicConnectionFactory.createTopicConnection() methods are used to create an instance of a TopicConnection object. The createTopicConnection() method can be called with a username and password or by using the parameterless version of the method with a default user identity assumed.

The TopicConnection interface is a type of Connection interface that represents a connection to a JMS publish-subscribe messaging service. The createTopicSession() method is called by JMS clients to create a TopicSession instance. Session transactions and acknowledgment mode are also established during the creation of a TopicSession.

TopicSession.createTopic() creates an instance of a Topic object, given a provider-specific name for a topic. The Topic interface encapsulates a topic destination to which publishers publish messages and from which subscribers subscribe to receive messages. Different service providers implement a hierarchy of topic names differently, but a Topic.getTopicName() can be used to obtain the String representation of the topic.

The TopicSession.createPublisher() method creates a TopicPublisher message producer that is used to publish messages to a particular Topic. Messages can be published to a Topic using the various TopicPublisher.publish() methods. Variations of these methods enable publishing of messages to a TopicPublisher object's associated Topic or to a newly specified Topic object passed to the publish() method. Delivery modes, priorities, and time to live for a message can also be specified during calls to TopicPublisher.publish(). Messages to publish to a Topic can be created using the various message-creation methods defined on the Session interface from which TopicSession extends.

  • + Share This
  • 🔖 Save To Your Account