Broker 10.15 | webMethods Broker Documentation | webMethods Broker Client C 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 Requestor has been completed, the get-event design involves these steps:
1. Use awPublishEvent to publish the request.
2. Enter a processing loop and receive events with awGetEvent.
3. Use awGetEventTag to check each received event for a tag that matches the request event's tag.
The following example shows how the awGetEvent function could be used to receive a reply event.
. . .
BrokerClient c;
BrokerEvent e;
BrokerBoolean b;
int request_tag;
. . .
/* Create a client */
err = awNewBrokerClient(broker_host, broker_name, NULL
"default", "R
eqestor", NULL, &c);
/* Check for errors */
. . .
/* Check if can publish */
err = awCanPublish(c, "Sample::Request", &b);
/* Check for errors */
. . .
/* Check if can subscribe */
err = awCanSubscribe(c, "Sample::Reply", &b);
/* Check for errors */
. . .
/* Create the request event */
err = awNewBrokerEvent(c, "Sample::Request", &e);
/* Check for errors */
. . .
/* Create tag and set tag field */
request_tag = awMakeTag(c);
err = awSetEventTag(e, request_tag);
/* Check for errors */
. . .BrokerClient c;BrokerEvent e;BrokerBoolean done;
long received_tag, request_tag;
. . .
/* Create BrokerClient, check subscription and publish permissions,
* create request BrokerEvent, create tag, set tag field
*/
. . .
/* Publish the request */
err = awPublishEvent(c, e);
/* check for errors ... */
. . .
/* Loop getting events */
done = 0;
while(!done) {
err = awGetEvent(c,AW_INFINITE,&e);
if (err != AW_NO_ERROR) {
printf(" Error on awGetEvent\n");
return 0;
}
err = awGetEventTag(e,&received_tag);
if (err != AW_NO_ERROR) {
printf(" Error on awGetEventTag\n");
} else if (request_tag == received_tag) {
if (awIsNullReplyEvent(e)) {
printf("Null reply received.\n");
}else if (awIsAckReplyEvent(e)) {
printf("Ack reply received.\n");
}else if ( awIsErrorReplyEvent(e)) {
printf("Error reply received.\n");
} else {
/* process the event */
. . .
}
done = awIsLastReplyEvent(e);
}
awDeleteEvent(e);
}
. . .