Broker 10.5 | webMethods Broker Documentation | webMethods Broker Client C API Programmer's Guide | Using Broker Clients | Disconnecting and Reconnecting | Reconnecting a Broker Client
 
Reconnecting a Broker Client
 
Using the awNewOrReconnect Function
You can reconnect a previously disconnected Broker client that has a life cycle of explicit-destroy by calling the awReconnectClient function and specifying the same client ID that was used when your client was last connected, as shown in the example below. 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 awDisconnectClient was made.
Note: Automatic Reconnection describes how you can enable automatic reconnection for your Broker client in the event the connection to the Broker is lost.
The following example illustrates how to reconnect a Broker client.
#include "aweb.h"
. . .
int main(int argc, char **argv)
{
char *broker_host = "localhost";
char *broker_name = NULL;
char *client_group = "default";
char *client_id = NULL;
BrokerClient c;
BrokerError err;

/* Create a new client */
err = awNewBrokerClient(broker_host, broker_name,
NULL, client_group, "Publish Sample #1",NULL, &c);
...
/* Save the client ID */
err = awGetClientID(c, &client_id);
...

/* Disconnect the client */
err = awDisconnectClient(c);
...
/* Reconnect a client with the same client_id */
err = awReconnectBrokerClient(broker_host, broker_name,
client_id, NULL, &c);
if (err != AW_NO_ERROR) {
printf("Error on reconnect client\n%s\n", awErrorToString(err));
return 0;
}
. . .