Broker 10.5 | webMethods Broker Documentation | webMethods Broker Client Java API Programmer's Guide | Using Broker Clients | Disconnecting and Reconnecting | Reconnecting a Broker Client | Using the newOrReconnect Method
 
Using the newOrReconnect Method
You might find it convenient to use the BrokerClient.newOrReconnect method to create or reconnect a client when your client application is expected to be executed repeatedly. The newOrReconnect method shown in the following example, attempts to create a new Broker client. If the client already exists and was simply disconnected, it will be reconnected.
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;
. . .
client_id = "123";
/* The first time this program is executed, a Broker client
* will be created. Subsequent executions will simply reconnect
* the Broker client.
*/
try {
c = BrokerClient.newOrReconnect(broker_host, broker_name, null,
client_group, "Publish Sample #1",null);
} catch (BrokerException ex) {
. . .
}
/* Do some processing */
. . .
/* Disconnect the client */
try {
c.disconnect();
} catch (BrokerException ex) {
. . .
}
. . .