Java Reference
In-Depth Information
Recall that in the pub-sub domain, a message is distributed to all currently subscribed con-
sumers. In general, this is much like a broadcast message in that anyone who isn't connec-
ted to the topic at the time doesn't receive a copy of the message. The exception to this rule
is what is known as the durable subscription .
Once a consumer obtains a durable subscription on a topic, all messages sent to the topic
are guaranteed to be delivered to the consumer. If the durable subscriber isn't connected
to a topic when a message is received, the MOM retains a copy of the message until the
subscriber connects and delivers the message. The following shows how to create a durable
subscriber in plain JMS:
MessageConsumer orderSubscriber = session.createDurableSubscriber( orderTopic,
"OrderProcessor");
Here, we're creating a durable subscription message consumer to the
javax.jms.Topic orderTopic with a subscription ID of OrderProcessor .
From now on, all messages to the topic will be held until a consumer with the subscription
ID OrderProcessor receives them. You can remove this subscription with the follow-
ing code:
session.unsubscribe("OrderProcessor");
If you want an MDB to be a durable subscriber, then ActivationConfigProperty
would look like this:
@ActivationConfigProperty(
propertyName="destinationType",
propertyValue="javax.jms.Topic"),
@ActivationConfigProperty(
propertyName="subscriptionDurability",
propertyValue="Durable"
For nondurable subscriptions, explicitly set the value of the subscriptionDurabil-
ity property to NonDurable . This is the default if no value is set.
messageSelector
The messageSelector property is the MDB parallel to applying a selector for a raw
JMS consumer. The current code consumes all messages at the destination. If you prefer,
you could filter the messages you retrieve by using a message selector —a criterion applied
Search WWH ::




Custom Search