Broker 10.5 | webMethods Broker Documentation | webMethods Broker Client Java API Programmer's Guide | Using Request-Reply | The Requestor | Using the Get-event Approach
 
Using the Get-event Approach
After the preliminary processing described in the example above in The Requestor has been completed, the get-event design involves these steps:
1. Use BrokerClient.publish to publish the request event.
2. Enter a processing loop and receive events with BrokerClient.getEvent.
3. Use BrokerEvent.getTag to check each received event for a tag that matches the request event's tag.
The following example illustrates receiving a reply event with BrokerClient.getEvent:
. . .
BrokerClient c;
BrokerEvent e;
boolean done;
int received_tag;
long request_tag;
. . .
/* Create BrokerClient, check subscription and publish permissions,
* create request BrokerEvent, create tag, set tag field
*/
. . .
/* Publish the request */
try {
c.publish(e);
} catch (BrokerException ex) {
. . .
}
/* Loop getting events */
done = 0;
while(!done) {
try { /* get an event */
e = c.getEvent();
} catch (BrokerException ex) {
. . .
}
try { /* get the event’s tag */
received_tag = e.getTag();
} catch (BrokerException ex) {
. . .
}
/* see if event matches request */
if (request_tag == received_tag) {
if (e.isNullReply())
/* handle null reply */
} else if (e.isErrorReply()) {
/* handle error reply */
} else {
/* process the event */
. . .
}
done = e.isLastReply();
}
}
. . .