Universal Messaging 10.3 | Developer Guide | Enterprise APIs | Enterprise Developer's Guide for C++ | Message Queues | Synchronous Queue Consuming
 
Synchronous Queue Consuming
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:

class mySyncQueueReader {

private:
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);
}

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

void go(nConsumeEvent *event) {
printf("Consumed event %d",event->getEventID());
}

int main(int argc, char** argv) {
mySyncQueueReader *sqr = new mySyncQueueReader();
sqr->start();
return 0;
}
}

Synchronous queue consumers can also be created using a selector, which defines a set of event properties (see Event Dictionaries) and their values that a consumer 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:

std: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.
An example of a synchronous queue consumer can be found on the examples page under "Queue Reader".