Creating and Destroying Broker Clients
Creating a BrokerClient will establish a connection between your application and a Broker. This connection is identified by the following tuple:
The name of the host where the
Broker is executing.
The IP port number assigned to the
Broker.
The name of the
Broker.
Multiple
Broker clients within a single application that connect to the same
Broker will all share a single network connection, as described in
Sharing Connections.
Your application can create a Broker client by calling the BrokerClient constructor and specifying these parameters:
The name of the host where the
Broker to which you want to connect is executing.
The name of the
Broker to which you want to connect. You specify a
null value if you want to connect to the
default Broker. The default
Broker for a particular host is determined by your
webMethods Broker administrator.
A unique client ID that identifies your
Broker client. You can specify a
null value if you want the
Broker to generate a unique client ID for you. The client ID generated by the
Broker can be obtained after this call completes by calling the
BrokerClient.getClientId method.
The client group for your new
Broker client. Client groups define the event types your new
Broker client will be able to publish or retrieve, as well as the life cycle and queue storage type for your
Broker client. Client groups are defined by your
webMethods Broker administrator.
The name of the application that is creating the
Broker client. This name is used primarily by
webMethods Broker administration and analysis tools. The application name can be any meaningful string of characters you choose.
A
BrokerConnectionDescriptor to be used for the new
Broker client. If you specify a
null value, a new connection descriptor will be created for you. The
BrokerConnectionDescriptor class is covered in detail in
Broker Connection Descriptors.
The following example is from a sample application that shows the creation of a new BrokerClient object. In this example, a null Broker name is passed to indicate that the caller wants to connect to the default Broker on the host "localhost."
A null client ID is specified, indicating that the Broker should generate a unique client ID. A client group named "default" is requested and the application name is set to "Publish Sample #1." A null connection descriptor is passed, indicating that the caller wants a default connection to be established.
import COM.activesw.api.client.*;
class publish1
{ static String broker_host = "localhost";
static String broker_name = null;
static String client_group = "default";
. . .
public static void main(String args[])
{
BrokerClient c;
. . .
/* Create a client */
try {
c = new BrokerClient(broker_host, broker_name, null,
client_group, "Publish Sample #1",null);
} catch (BrokerException ex) {
system.out.println("Error on create client\n"+ex);
return;
}
. . .