Universal Messaging 10.1 | Developer Guide | Enterprise APIs | Enterprise Developer's Guide for C++ | Publish / Subscribe using Channel Topics | Asynchronous Subscriber
 
Asynchronous Subscriber
Asynchronous channel subscribers consume events from a callback on an interface that all asynchronous subscribers must implement. We call this interface an nEventListener.
The listener interface defines one method called 'go' which when called will pass events to the consumer as they are delivered from the Universal Messaging Realm Server.
An example of such a simple listener is shown below:

class subscriber : public nEventListener{

public:
mySubscriber(){
// construct your session
// and channel objects here
// begin consuming events from the channel at event id 0
// i.e. the beginning of the channel
myChannel->addSubscriber(this , 0);
}

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

int main(int argc, char** argv) {
new mySubscriber();
return 0;
}
}
Asynchronous consumers can also be created using a selector, which defines a set of event properties and their values that a subscriber 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 addSubscriber method shown in the example code, then your consumer will only consume messages that contain the correct value for the event property BONDNAME.