Broker 10.15 | webMethods Broker Documentation | webMethods Broker Client Java API Programmer's Guide | Using Broker Clients | Disconnecting and Reconnecting | Reconnecting a Broker Client
 
Reconnecting a Broker Client
 
Using the newOrReconnect Method
You can reconnect a previously disconnected Broker client that has a life cycle of explicit-destroy by calling the BrokerClient.reconnect method and specifying the same client ID that was used when your client was last connected, as shown in the following example. If the Broker client's life cycle is explicit-destroy, the client state and event queue storage will have been preserved by the Broker since previous call to BrokerClient.disconnect was made.
Note: Automatic Re-connection describes how you can enable automatic re-connection for your Broker client in the event the connection to the Broker is lost.
static String broker_host = "localhost";
static String broker_name = null;
static String client_group = "default";
. . .
public static void main(String args[])
{
BrokerClient c;
String client_id;
. . .
/* Create a client */
try {
c = new BrokerClient(broker_host, broker_name, null,
client_group, "Publish Sample #1",null);
} catch (BrokerException ex) {
. . .
}
/* Save the client ID */
client_id = c.getClientId();
. . .
/* Disconnect the client */
try {
c.disconnect();
} catch (BrokerException ex) {
. . .
}
. . .
/* Reconnect the client with the same client_id */
try {
c = BrokerClient.reconnect(broker_host, broker_name,
client_id, null);
} catch (BrokerException ex) {
. . .
}
. . .