Java Reference
In-Depth Information
consumer.receive();
//do something
}
...
If you require the use of shared durable subscriptions, you will be happy to know that they received the same
treatment as non-durable subscriptions in the JMS 2.0 release. As background, a durable subscription is useful for
applications that need to receive all messages published on a topic, even those that have no consumer assigned.
A shared, non-durable subscription is used by clients that need the ability to share the task of receiving messages
from a durable subscription among multiple different consumers. Much like shared non-durable subscriptions; it is
possible for shared-durable subscriptions to have multiple consumers. Again, each message from the subscription
will only be sent to one of the consumers, not each of them.
To facilitate this enhancement for shared durable subscriptions, each of the APIs for creating consumers has
been updated, as follows:
If using the classic API, Session has been updated to include several
createSharedDurableConsumer methods, each returning a MessageConsumer object. The
createSharedDurableConsumer method that is used depends upon the specified criteria.
If using the simplified API,
JMSContext contains several createSharedDurableConsumer
methods, each returning a JMSConsumer object. The createSharedDurableConsumer method
that is used depends upon the specified criteria.
JMSContext includes several
createSharedDurableConsumer methods, each returning a JMSConsumer object. The
createSharedDurableConsumer method that is used depends upon the specified criteria.
The following example demonstrates how to create a shared durable subscription using the simplified API.
...
@Resource(name = "jms/connectionFactory")
private ConnectionFactory connectionFactory;
@Resource(lookup = "jms/Topic")
Topic topic;
...
public void createSharedDurable(){
String topicName = "JavaEE";
JMSContext context = connectionFactory.createContext();
JMSConsumer consumer = context.createSharedConsumer(topic, topicName);
consumer.receive();
// do something
}
...
If using the legacy domain-specific API for pub/sub, the
Summary
JMS 2.0 is a completely overhauled release of the API, which applies modern programming techniques to make the
use of JMS even easier. Using the simplified API, dozens of code lines can be cut from JMS applications, making code
development and maintainability even easier. Going along with the Java 7 simplifications, JMS resources are now
autocloseable, making the API more efficient. Additionally, features such as the ability to easily access message body
content and set the delay on message sending help to provide developers with more fine-grained control. Although
it has been a number of years since the API has been updated, this is one update that is certainly welcome since it
modernizes the API, and adds simplification and more ability throughout.
 
Search WWH ::




Custom Search