Java Reference
In-Depth Information
When using the simplified API, the following method can be called on the JMSProducer prior to invocation of the
synchronous sending methods:
setAsync(CompletionListener completionListener)
The asynchronous sending of a message results in a message being sent without waiting for an acknowledgment
of receipt before returning. When an acknowledgment is eventually sent, the JMS provider notifies the application by
invoking the onCompletion method of the CompletionListener object that resides within the application. Conversely,
if no receipt is sent, then the onException method of the CompletionListener is invoked.
Although JMS 2.0 offers asynchronous message sending, messages cannot be sent in an asynchronous manner
from within a Java EE EJB or web container. As a result, violating applications will trigger a JMSException or
JMSRuntimeException . Since this topic focuses on Java EE 7 new features, this section will not delve any deeper into
the asynchronous sending of messages. However, if you plan to use this feature in a different environment, please see
more information at http://jms-spec.java.net/ .
Multiple Consumers on the Same Subscription
Prior to JMS 2.0, a durable or non-durable topic subscription was only permitted to have one consumer at a time.
This limited scalability since the processing work could not be distributed. In the 2.0 release, multiple consumers
were allowed on the same subscription. With regards to non-durable subscriptions, otherwise known as “shared
non-durable subscriptions,” this type of subscription is useful for those cases where the work of receiving messages
from a non-durable topic subscription needs to be shared amongst multiple consumers in order to distribute the
payload. It should be noted that each message from the subscription is only delivered to one of the consumers on that
subscription.
To facilitate this enhancement for non-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
createSharedConsumer
methods, which return a MessageConsumer object. The createSharedConsumer message that is
used depends upon the criteria specified.
If using the simplified API,
JMSContext contains several createSharedConsumer methods,
which return a JMSConsumer object. The createSharedConsumer message that is used depends
upon the criteria specified.
If using the legacy domain-specific API for pub/sub,
TopicSession has been updated to
include several createSharedConsumer methods, which return a MessageConsumer object. The
createSharedConsumer message that is used depends upon the criteria specified.
The following example demonstrates the creation of a subscription that accepts more than one consumer, using
the simplified API.
...
@Resource(name = "jms/connectionFactory")
private ConnectionFactory connectionFactory;
@Resource(lookup = "jms/Topic")
Topic topic;
...
public void createSharedNonDurable(){
String topicName = "JavaEE";
JMSContext context = connectionFactory.createContext();
JMSConsumer consumer = context.createSharedConsumer(topic, topicName);
 
Search WWH ::




Custom Search