Universal Messaging 10.11 | Developer Guide | Enterprise APIs | Enterprise Developer's Guide for C++ | Message Queues | Queue Browsing / Peeking
 
Queue Browsing / Peeking
Universal Messaging provides a mechanism for browsing (peeking) queues. Queue browsing is a non-destructive read of events from a queue. The queue reader used by the peek will return an array of events, the size of the array being dependent on how many events are in the queue, and the window size defined when your reader context is created. For more information, please see the Universal Messaging Client API documentation.
An example of a queue browser is shown below:


public class myQueueBrowser {
private:
nQueueSyncReader *reader;
nQueuePeekContext *ctx;
nQueue *myQueue;

public:
myQueueBrowser(){
// construct your session and queue objects here
// create the queue reader

reader = myQueue->createReader(new
nQueueReaderContext());

ctx = nQueueReader::createContext(10);
}

void start(){
bool more = true;
long eid =0;

while (more) {
// browse (peek) the queue
int size;
nConsumeEvent **evts = reader->peek(ctx,size);
for (int x=0; x < size; x++) {
go(evts[x]);
}
more = ctx->hasMore();
}
}

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

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

Queue browsers can also be created using a selector, which defines a set of event properties (see Event Dictionaries) and their values that a browser 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 nQueuePeekContext object shown in the example code, then your browser will only receive messages that contain the correct value for the event property BONDNAME.
An example of an queue browser can be found on the examples page under "Queue Peek".