Declaring a Message Selector
When a consumer is created with a message selector, the JMS
provider must validate that the selector statement is syntactically
correct. If the selector is not correct, the operation throws a javax.jms.InvalidSelectorException. For the
point-to-point model, message selectors can be applied to a QueueBrowser and the QueueReceiver, specifically within the createBrowser() and createReceiver() methods of the QueueSession:
public interface QueueSession extends Session {
public QueueBrowser createBrowser(Queue queue,
String messageSelector)
throws JMSException,
InvalidSelectorException,
InvalidDestinationException;
public QueueReceiver createReceiver(Queue queue,
String messageSelector)
throws JMSException,
InvalidSelectorException,
InvalidDestinationException;
...
}For the publish-and-subscribe model, message selectors can be
applied to a durable or nondurable TopicSubscriber (topic browsing is not
supported for the publish-and-subscribe model). When creating a topic
subscriber, you can specify the message selector in the createSubscriber() or createDurableSubscriber() methods of the
TopicSession:
public interface TopicSession extends Session {
public TopicSubscriber createSubscriber(Topic topic,
String messageSelector,
boolean noLocal)
throws JMSException,
InvalidSelectorException,
InvalidDestinationException;
public TopicSubscriber createDurableSubscriber(Queue queue,
String name,
String messageSelector, boolean noLocal) throws JMSException, InvalidSelectorException, ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access