Universal Messaging 9.12 | Developer Guide | Enterprise APIs | Enterprise Developer's Guide for C# | Message Queues | Synchronously Consuming a Queue
 
Synchronously Consuming a Queue
Synchronous queue consumers consume events by calling pop() on the Universal Messaging queue reader object. Each pop call made on the queue reader will synchronously retrieve the next event from the queue.
An example of a synchronous queue reader is shown below:

public class mySyncQueueReader {

nQueueSyncReader reader = null;
nQueue myQueue = null;

public mySyncQueueReader() {
// construct your session and queue objects here
// construct the queue reader
nQueueReaderContext ctx = new nQueueReaderContext(this, 10);
reader = myQueue.createReader(ctx);
}

public void start() {
while (true) {
// pop events from the queue
nConsumeEvent event = reader.pop();
go(event);
}
}

public void go(nConsumeEvent event) {
Console.WriteLine("Consumed event "+event.getEventID());
}

public static void Main(String[] args) {
mySyncQueueReader sqr = new mySyncQueueReader();
sqr.start();
}

}

Subscription with a Filtering Selector
Synchronous 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:

nEventProperteis 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-2019 | 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.