Universal Messaging 10.1 | Developer Guide | Enterprise APIs | Enterprise Developer's Guide for C# | Message Queues | Asynchronously Consuming a Queue
 
Asynchronously Consuming a Queue
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 : nEventListener {

nQueue myQueue = null;

public myAsyncQueueReader() {
// 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) {
Console.WriteLine("Consumed event "+event.getEventID());
}

public static void Main(String[] args) {
new myAsyncQueueReader();
}
}
Subscription with a Filtering Selector
Asynchronous queue consumers can also be created using a selector, which allows the subscription to be filtered based on event properties and their values.
For example, assume some events are being published with the following event properties:

nEventProperties props = new nEventProperties();
props.put("BONDNAME", "bond1");
A developer can create a message selector string such as:

String selector = "BONDNAME='bond1'";
Passing this string into the constructor for the nQueueReaderContext object shown in the example code will ensure that the subscriber will only consume messages that contain the correct value for the event property BONDNAME.

Copyright © 2013-2017 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.
Innovation Release