Universal Messaging 9.12 | Developer Guide | Enterprise APIs | Enterprise Developer's Guide for Java | Publish / Subscribe Using Channels/Topics | Channel Iterator
 
Channel Iterator
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.
If you are using iterators so that you know when all events have been consumed from a channel please note that this can also be achieved using an asynchronous subscriber by calling the nConsumeEvents isEndOfChannel() method.
An example of how to use a channel iterator is shown below:

public class myIterator {

nChannelIterator iterator = null;

public myIterator() throws Excepetion {
// construct your session and channel objects
// 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();
}

}
Synchronous 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:

nEventProperties 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.

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