Universal Messaging 10.11 | Developer Guide | Enterprise APIs | Enterprise Developer's Guide for Java | Publish / Subscribe Using Channels/Topics | Asynchronous Subscriber
 
Asynchronous Subscriber
Asynchronous channel subscribers consume events from a callback on an interface that all asynchronous subscribers must implement. We call this interface an nEventListener.
The listener interface defines one method called 'go' which when called will pass events to the consumer as they are delivered from the Universal Messaging Realm Server.
An example of such a simple listener is shown below:

public class mySubscriber implements nEventListener {

public mySubscriber() throws Exception {
// construct your session
// and channel objects here
// begin consuming events from the channel at event id 0
// i.e. the beginning of the channel
myChannel.addSubscriber(this , 0);
}

public void go(nConsumeEvent event) {
System.out.println("Consumed event "+event.getEventID());
}

public static void main(String[] args) {
new mySubscriber();
}
}
Asynchronous consumers can also be created using a selector, which defines a set of event properties and their values that a subscriber is interested in. For example if events are being published with the following event properties:
nEventProperties props =new nEventProperties();
props.put(“BONDNAME”,”bond1”);
If you then provide a message selector string in the form of:
String selector = "BONDNAME='bond1'";
And pass this string into the addSubscriber method shown in the example code, then your consumer will only consume messages that contain the correct value for the event property BONDNAME.