In this section, we'll look at each of the important JMS interfaces for point-to-point programming and some of their methods.
In the next section (Point-to-point programming ), we'll look at some sample code that performs point-to-point message processing.
Remember: The point-to-point and pub/sub interfaces are included in JMS version 1.1 only for backward compatibility. If you are doing new development, use the common interfaces covered in the previous two sections (New in JMS 1.1: Common interfaces and Client programming with common interfaces ).
QueueConnectionFactory is an administered object that is retrieved from JNDI to create a connection to a provider. It contains a
createQueueConnection() method, which returns a
QueueConnection encapsulates an active connection to a provider. Some of its methods are:
createQueueSession(boolean, int): Returns a
booleanparameter indicates whether the
QueueSessionis transacted or not; the
intindicates the acknowledgment mode (see Acknowledgment ).
Connection): Activates the delivery of messages from the provider.
Connection): Temporarily stops delivery of messages; delivery can be restarted with
Connection): Closes the connection to the provider and releases all resources held in its behalf.
QueueSession is the single-threaded context for sending and receiving PTP messages. Some of its methods are:
createSender(Queue): Returns a
QueueSenderobject to send messages to the specified
createReceiver(Queue): Returns a
QueueReceiverobject to receive messages from the specified
Session): Returns a
QueueBrowserobject to browse messages on the specified
Session): Commits all consumed or produced messages for the current transaction.
Session): Rolls back all consumed or produced messages for the current transaction.
Session): A variety of methods that return a
<MessageType>Message-- for example,
TextMessage, and so on.
Queue encapsulates a point-to-point destination. It is an administered object that is retrieved from JNDI.
QueueSender is used to send point-to-point messages. Some of its methods are:
send(Message): Sends the indicated
MessageProducer): Sets the delivery mode for subsequent messages sent; valid values are
MessageProducer): Sets the priority for subsequent messages sent; valid values are 0 through 9.
MessageProducer): Sets the duration before expiration, in milliseconds, of subsequent messages sent.
QueueReceiver is used to receive point-to-point messages. Some of its methods are:
MessageConsumer): Returns the next message that arrives; this method blocks until a message is available.
MessageConsumer): Receives the next message that arrives within
longmilliseconds; this method returns
nullif no message arrives within the time limit.
MessageConsumer): Receives the next message if one is immediately available; this method returns
nullif no message is available.
MessageConsumer): Sets the
MessageListenerobject receives messages as they arrive, that is, asynchronously (see
QueueReceiver is used to receive messages, the messages are removed from the queue when they are received.
QueueBrowser is used to look at messages on a queue without removing them. The method for doing that is
which returns a
java.util.Enumeration that can be used to scan the messages in the queue; changes to the queue (arriving and expiring of messages) may or may not be visible.