NonStop JMS User's Manual (H06.03+, J06.03+, NonStop JMS 3.0+)
NSJMS and JMS Client Applications
NonStop Server for Java Message Service User’s Manual—522356-006
4-12
No-Local
No-Local
You can ignore messages that are sent or published on the subscriber’s own
connection by setting the third parameter of the createSubscriber() method to
true.
This code fragment causes messages published on the subscriber’s connection to be
ignored:
TopicSubscriber sub =
session.createSubscriber(topic,null,true);
Using Message Listeners
A message listener uses the onMessage() method to enable asynchronous
notification to the listener when a message is sent to a queue or published to a topic.
The message listener is registered by the JMS client when subscribing to a queue or
topic and is used instead of making calls to the receive() method.
This code fragment creates a message listener for a queue:
import javax.jms.*;
public class MyClass implements MessageListener
{
public void onMessage(Message message)
{
System.out.println("The message is "+message);
.
.
.
}
}
.
.
.
MyClass listener =new MyClass();
queueReceiver.setMessageListener(listener);
Note. Use of asynchronous delivery with a QueueReceiver or TopicSubscriber marks the
entire Session as asynchronous. It is an error to make an explicit call to the receive methods of
a QueueReceiver or TopicSubscriber that is associated with a Session that is using
asynchronous delivery.