Universal Messaging Developer Guide : Enterprise APIs : Enterprise Developer's Guide for C# : Publish / Subscribe using Channel Topics : Synchronous Consumers
Synchronous Consumers
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 nConsumeEvent's isEndOfChannel() method.
An example of how to use a channel iterator is shown below:

public class myIterator {

nChannelIterator iterator = null;

public myIterator() {
// 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) {
Console.WriteLine("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:

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.
Copyright © 2013-2016 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback