Universal Messaging 9.7 | Universal Messaging Developer Guide | Enterprise APIs | Enterprise Developer's Guide for Java | 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 {

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

public myQueueBrowser() throws Exception {

// construct your session and queue objects here

// create the queue reader

reader = myQueue.createReader(new
nQueueReaderContext());

ctx = nQueueReader.createContext(10);
}

public void start() throws Exception {
boolean 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) {
System.out.println("Consumed event "+event.getEventID());
}

public static void main(String[] args) {
try {
myQueueBrowser qbrowse = new myQueueBrowser();
qbrowse.start();
} catch (Exception e) {
e.printStackTrace();
}
}
}

Queue browsers can also be created using a selector, which defines a set of event properties and their values that a browser is interested in. For example if events are being published with the following event properties:
nEventProperteis props =new nEventProperties();
props.put(“BONDNAME”,”bond1”);
If you then provide a message selector string in the form of:
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.

Copyright © 2013-2015 | 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.