Universal Messaging 10.1 | Developer Guide | Enterprise APIs | Enterprise Developer's Guide for C++ | Publish / Subscribe using Channel 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:

class myIterator {
nChannelIterator *iterator = null;

// construct your session and channel objects
// start the iterator at the beginning of the channel (event id 0)
iterator = myChannel->createIterator(0);

void start() {
while (true) {
nConsumeEvent *event = iterator->getNext();

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

int main(int argc, char** argv) {
myIterator *itr = new myIterator();
return 0;

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();
If you then provide a message selector string in the form of:

std::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.