Obtaining Subscription Identifiers
The example below shows how you could use the BrokerEvent.getSubscriptionIds method to obtain the subscription identifier of a retrieved event.
Note:
If the filter string specified for two or more subscriptions have overlapping criteria, it is possible for a retrieved event to be associated with more than one subscription identifier. For more information on event filters, see
Using Event Filters.
This example assumes that the subscriptions described in the example in
Specifying Subscription IDs have already been made and that there is only one subscription identifier associated with any retrieved event. The
BrokerEvent.getSubscriptionIds method accepts no parameters.
Note:
Events that are delivered to your
Broker client do not have subscriptions or subscription IDs. For more information on delivering events, see
Delivering Events.
. . .
BrokerClient c;
BrokerEvent e;
int subscriptions[];
...
while(1) {
try {
e = c.getEvent(-1);
} catch (BrokerException ex) {
System.out.println("Error on getting event\n"+ex);
return;
}
/* get the event’s subscription identifier */
subscriptions = e.getSubscriptionIds();
if((subscriptions != null) && (subscriptions.length > 0)){
switch( subscriptions[0] ) {
case 1:
/* process Sample::SimpleEvent1 . . . */
break;
case 2:
/* process Sample::SimpleEvent2 . . .*/
break;
default:
break;
}
}
}
. . .