|
Events can
be synchronously consumed from a channel using a channel
iterator object. The iterator will sequentially move
through the channel and return events as and when the
iterator getNext() method is called.
An example of how to use a channel iterator is shown
below:
public class myIterator {
nChannelIterator iterator = null;
public myIterator() throws Exception {
// construct
your session
and channel objects
here
// start the iterator
at the beginning of the channel (event id 0)
iterator = myChannel.createIterator(0);
}
public void start() {
while (true) {
nConsumeEvent event = iterator.getNext();
go(event);
}
}
public void go(nConsumeEvent event) {
System.out.println("Consumed event "+event.getEventID());
}
public static void main(String[] args) {
myIterator itr = new myIterator();
itr.start();
}
}
Sychronous consumers can also be created using a selector,
which defines a set of event
properties and their values that a consumer 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 createIterator method
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 synchronously consuming events from a
channel can be found here.
For more information on Nirvana publish / subscribe,
please see the API
documentation. |