Universal Messaging Developer Guide : Enterprise APIs : Enterprise Developer's Guide for Java : Message Queues : Asynchronous Queue Consuming
Asynchronous Queue Consuming
Asynchronous queue consumers consume events from a callback on an interface that all asynchronous consumers 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 an asynchronous queue reader is shown below:


public class myAsyncQueueReader implements nEventListener {

nQueue myQueue = null;

public myAsyncQueueReader() throws Exception {

// construct your session and queue objects here

// begin consuming events from the queue

nQueueReaderContext ctx = new nQueueReaderContext(this, 10);
nQueueAsyncReader reader = myQueue.createAsyncReader(ctx);
}

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

public static void main(String[] args) {
try {
new myAsyncQueueReader();
} catch (Exception e) {
e.printStackTrace();
}
}
}

Asynchronous queue 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:
nEventProperteis 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 constructor for the nQueueReaderContext object shown in the example code, then your consumer will only consume messages that contain the correct value for the event property BONDNAME.
Copyright © 2013-2016 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback