Broker 10.15 | webMethods Broker Documentation | webMethods Broker Client Java API Programmer's Guide | Using Request-Reply | The Requestor
 
The Requestor
 
Using the Get-event Approach
Callbacks with Tags
Using publishRequestAndWait
You have several processing models to choose from when designing a requestor application. These design alternatives include:
*Use BrokerClient.publish to send the request event, use BrokerClient.getEvent to receive possible reply events, and check each event received for a matching tag.
*Create a callback object for the response event and register it with BrokerClient.registerCallbackWithTag, specifying the tag you will use. Use BrokerClient.publish to send the request event and then use one of the Broker Server dispatching methods to dispatch received events.
*Use BrokerClient.publishRequestAndWait to send the request event and wait until a reply event is received.
The following example shows the code that implements the following preliminary steps:
1. Create a BrokerClient object.
2. Check for publication permission for the request event type.
3. Check for subscription permission for the reply event type. This is done even though the reply event will be delivered because it indicates if the requestor's client group will allow it to receive the reply event type.
4. Create a request BrokerEvent object.
5. Create a tag for the request event using the BrokerClient.makeTag method.
6. Set the request event's tag field using the BrokerEvent.setEventTag method.
. . .
BrokerClient c;
BrokerEvent e;
boolean permission;
int request_tag;
. . .
/* Create a client */
try {
c = new BrokerClient(broker_host, broker_name, null,
client_group, "Publish Sample #1",null);
} catch (BrokerException ex) {
. . .
}
/* Check if can subscribe */
try {
permission = c.canSubscribe("Sample::Reply");
} catch (BrokerException ex) {
. . .
}
/* Check if can publish */
try {
permission = c.canPublish("Sample::Request");
} catch (BrokerException ex) {
. . .
}
/* Create the request event */
try {
e = new BrokerEvent(c, "Sample::Request");
} catch (BrokerException ex) {
. . .
}
/* Create tag and set request event’s tag field */
request_tag = c.makeTag();
try {
e.setTag(tag);
} catch (BrokerException ex) {
. . .
}
. . .