Broker 10.5 | webMethods Broker Documentation | webMethods Broker Client Java API Programmer's Guide | Using Request-Reply | The Requestor | Using publishRequestAndWait
 
Using publishRequestAndWait
After the preliminary processing described in the example above in The Requestor has been completed, the callback approach involves these steps:
1. Use BrokerClient.registerCallback to register a general callback object.
2. Use BrokerClient.publishRequestAndWait to publish the request and wait for the reply. You can also use the BrokerClient.deliverRequestAndWait method if you want to send the request event to a specific Broker client.
Note:
No event subscription is necessary in this model because the reply event will be delivered, not published.
The following example illustrates how to use BrokerClient.publishRequestAndWait:
public static void main(String args[])
{
BrokerClient c;
BrokerEvent e, events[];
int i;
SampleCallback1 general_callback =
new SampleCallback1(num_to_receive);
. . .
/* Register general callback */
try {
c.registerCallback(general_callback,null);
} catch (BrokerException ex) {
. . .
}
/* publish the request and wait for a reply */
try {
events[] = c.publishRequestAndWait(e, 6000);
} catch (BrokerException ex) {
. . .
}
/* Process received events */
for( i = 0; i < events.length; i++) {
if (events[i].isNullReply()) {
/* process null reply */
} else if (events[i].isErrorReply()) {
/* process error reply */
} else {
/* process reply */
}
}
. . .