Universal Messaging 9.7 | Universal Messaging 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 {
private:
nChannelIterator *iterator = null;

public:
myIterator(){
// 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();
go(event);
}
}

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

int main(int argc, char** argv) {
myIterator *itr = new myIterator();
itr->start();
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();
props->put("BONDNAME","bond1");
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.

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.