Broker 10.15 | webMethods Broker Documentation | webMethods Broker Client Java API Programmer's Guide | Transaction Semantics | Using Broker Transaction Clients | Operating within a Transaction | Getting Events
 
Getting Events
Your application can use the BrokerTransactionalClient.getEvents method to retrieve one or multiple events with a single call, instead of calling BrokerEvent.getEvent to retrieve events one at a time.
Using the BrokerTransactionalClient.getEvents method, the subscribing client is given events only once per session. To get events again before acknowledging, disconnect your subscriber and connect again.
The following example contains an excerpt that shows the use of the BrokerTransactionalClient.getEvents method for retrieving events in one given transaction. This method accepts these parameters:
*max_events. The maximum number of events you want to be returned (up to 160).
*int msecs. The number of milliseconds to wait for an event, if none are currently available. This can be set to -1 if you want to block indefinitely.
. . .
// Create subscriber
try {
sub = BrokerTransactionalClient.newOrReconnect(broker_host,
broker_name,subid, client_group_s, "TxTest-Sub",
null);
} catch (BrokerException ex){
System.out.println ("Failed to create pub client\n" + ex);
System.exit(1);
}
 
// Loop getEvent and expect to receive events
for (int i=0; i<count; i++){
try {
rc_ev = sub.getEvent(5000);
System.out.println("Received Event\n" + rc_ev.toString());
}catch (BrokerException ex) {
System.out.println ("Error on getEvent\n" + ex);
}
}
. . .