Broker 10.15 | webMethods Broker Documentation | webMethods Broker Client C API Programmer's Guide | Using Broker Clients | Disconnecting and Reconnecting | Reconnecting a Broker Client | Using the awNewOrReconnect Function
 
Using the awNewOrReconnect Function
You may find it convenient to use the awNewOrReconnectBrokerClient function to create or reconnect a client when your client application is expected to be executed repeatedly. The awNewOrReconnectBroker function will attempt to create a new Broker client. If the client already exists and was simply disconnected, it will be reconnected.
The following example illustrates how to reconnect a Broker client using the awNewOrReconnectBrokerClient function:
#include "aweb.h"
int main(int argc, char **argv)
{
char *broker_host = "localhost";
char *broker_name = NULL;
char *client_group = "default";
char *client_id = "123";
BrokerClient c;
BrokerError err;
. . .
/* The first time this program is executed, a Broker client
* will be created. Subsequent executions will simply reconnect
* the Broker client.
*/
err = awNewOrReconnectBrokerClient(broker_host, broker_name,
NULL, client_group, "Publish Sample #1",NULL, &c);
if (err != AW_NO_ERROR) {
printf("Error on newOrReconnect client\n%s\n",
awErrorToString(err));
return 0;
}
...
/* Do some processing */
...
/* Disconnect the client */
err = awDisconnectClient(c);
. . .
}