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 . Here are the session methods used to specify a message selector when creating a consumer:

// P2P Session's Message Consumer Methods
public QueueSession extends Session{
  QueueBrowser createBrowser(Queue queue, String messageSelector)
  throws JMSException, InvalidSelectorException,  
         InvalidDestinationException;
  QueueReciever createReceiver(Queue queue, String messageSelector)
  throws JMSException, InvalidSelectorException, 
         InvalidDestinationException;
  ...
}

The QueueBrowser and QueueReceiver types of the QueueSession interface are explored in Chapter 5. The durable subscriber (shown here) is covered in Chapter 4 :

// Pub/Sub Session's Message Consumer Methods
public TopicSession extends Session {
  TopicSubscriber createSubscriber(Topic topic, 
                                   String messageSelector, 
                                   boolean noLocal)
                        throws JMSException, 
                               InvalidSelectorException,  
                               InvalidDestinationException;

  TopicSubscriber createDurableSubscriber(Queue queue, 
                                          String name,
                                          String messageSelector,
                                          boolean noLocal)
                         throws JMSException, 
                                InvalidSelectorException, 
                                InvalidDestinationException;
  ...
}

The message selector used for a consumer can always be obtained by calling the getMessageSelector( ) method on a QueueReceiver, QueueBrowser, or TopicSubscriber. The getMessageSelector( ) method returns the message selector for that consumer as a String.

Once a consumer's message selector has been established, it cannot be changed. The consumer must be closed or deleted (durable subscriber) and a new consumer created with a new message selector.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset