Broker 10.15 | webMethods Broker Documentation | webMethods Broker Client Java API Programmer's Guide | Subscribing to and Receiving Events | Receiving Events in the Get-Events Model | Getting Multiple Events
 
Getting Multiple Events
Your application can use the BrokerClient.getEvents method to retrieve up to 160 events with a single call, instead of calling BrokerEvent.getEvent to retrieve events one at a time.
Using the BrokerClient.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 example below shows how you can alter the above sample application to use the BrokerClient.getEvents method. This method accepts these parameters:
*The maximum number of events you want to be returned (up to 160).
*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.
long receive_attempts = 10;
long number_received;
BrokerClient c;
BrokerEvent e[];
. . .
/* Loop getting events */
count = 1;
while(count <= num_to_receive) {
try {
e = c.getEvents(20, -1);
} catch (BrokerException ex) {
System.out.println("Error on getting events\n"+ex);
return;
}
/* process the received events */
. . .
++count;
}
. . .
Note:
The BrokerClient.getEvents method automatically acknowledges all outstanding events for the Broker client. See Using Sequence Numbers for information on acknowledging events.