Broker 10.5 | webMethods Broker Documentation | webMethods Broker Client C API Programmer's Guide | Using Request-Reply | The Requestor | Callback Functions with Tags
 
Callback Functions with Tags
After the preliminary processing described in The Requestor has been completed, the callback design involves these steps:
1. Use awPublishEvent to publish the request.
2. Use awRegisterCallback to register a general callback.
3. Use awRegisterCallbackForTag to register a specific callback for the reply event with the request event's tag.
4. Use one of the callback dispatching functions, described on Dispatching Callback Functions, to receive events and dispatch the appropriate callback function.
The following example shows how you could use the callback function to receive a reply event with a callback function:
. . .
BrokerBoolean test_callback1(BrokerClient c, BrokerEvent e,void *data);
int main(int argc, char **argv)
{
BrokerClient c;
BrokerEvent e;
long request_tag;
BrokerBoolean done = 0;
. . .
/* Publish request */
err = awPublishEvent(c,e);
/* check for errors ... */
/* Register general callback */
err = awRegisterCallback(c,test_callback1,"general");
if (err != AW_NO_ERROR) {
printf("Error on awRegisterCallback\n");
return 0;
}
err = awRegisterCallbackForTag(c,request_tag,1,test_callback1,
"tag matched");
if (err != AW_NO_ERROR) {
printf("Error on awRegisterCallback #2\n");
return 0;
}
/* Dispatch loop */
while(!done) {
err = awDispatch(AW_INFINITE);
if (err != AW_NO_ERROR) {
printf(" Error on awDispatch\n");
return 0;
}
}
. . .
}
BrokerBoolean test_callback1(BrokerClient c, BrokerEvent e,void *data)
{
char *st;
if (awIsNullReplyEvent(e)) {
printf("Null reply received.\n");
} else if (awIsErrorReplyEvent(e)) {
printf("Error reply received.\n");
} else {
/* process the event */
. . .
}
return 1;
}