Universal Messaging 10.3 | Developer Guide | Enterprise APIs | Enterprise Developer's Guide for C# | Message Queues | Browse (Peek) a Universal Messaging Queue
 
Browse (Peek) a Universal Messaging Queue
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 {

nQueueReader reader = null;
nQueuePeekContext ctx = null;
nQueue myQueue = null;

public myQueueBrowser() {
// construct your session and queue objects here
// create the queue reader
reader = myQueue.createReader(new nQueueReaderContext());
ctx = nQueueReader.createContext(10);
}

public void start() {
bool more = true;
long eid =0;
while (more) {
// browse (peek) the queue
nConsumeEvent[] evts = reader.peek(ctx);
for (int x=0; x < evts.Length; x++) {
go(evts[x]);
}
more = ctx.hasMore();
}
}

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

public static void Main(String[] args) {
myQueueBrowser qbrowse = new myQueueBrowser();
qbrowse.start();
}
}
Subscription with a Filtering Selector
Queue browsers can also be created using a selector, which allows the peek 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 nQueuePeekContext object shown in the example code will ensure that the browser will only receive messages that contain the correct value for the event property BONDNAME.
For more information on Universal Messaging Message Queues, please see the API documentation.