Broker 10.5 | webMethods Broker Documentation | webMethods Broker Client Java API Programmer's Guide | Subscribing to and Receiving Events | Receiving Events in the Get-Events Model
Receiving Events in the Get-Events Model
Getting Multiple Events
Synchronous Get Events
Detecting Redelivered Events
Redelivery and Older Versions of webMethods Software
Subscription Identifiers
BrokerSubscription Objects
The simplest way to retrieve events is to use the get-events model, which involves these steps:
1. Create a BrokerClient object.
2. Use the BrokerClient to subscribe to one or more event types. If your client only expects to receive delivered events, no subscriptions are necessary.
3. Enter a processing loop in which the BrokerClient.getEvent method is called to retrieve the next event.
4. Extract the fields that you want from each received event using the methods described in Creating and Initializing Events. Return to step 3 and receive the next event.
5. Call BrokerClient.destroy when you are finished.
You can also retrieve events using the poll method or the callback method. For more information, see Getting Events using the poll Method or Using the Callback Model respectively.
The example below contains an excerpt from a sample application that shows the use of theBrokerClient.getEvent method. This method accepts a single parameter; 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.
. . .
BrokerClient c;
BrokerEvent e;
. . .
/* Loop getting events */
count = 1;
while(count <= num_to_receive) {
try {
e = c.getEvent(-1);
} catch (BrokerException ex) {
System.out.println("Error on getting event\n"+ex);
. . .
The BrokerClient.getEvent method automatically acknowledges all outstanding events for the Broker client. See Using Sequence Numbers for information on acknowledging events.