Dynamically Creating Connection Factories

Normally client applications use JNDI to look up a Connection Factory object. However, some situations require clients to connect to the server directly. To connect to the EMS server directly, the application must dynamically create a connection factory.

The following examples show how to create a connection factory in each supported language for JMS connections. Each API also supports connection factories for JMS XA connections.

In each example, the serverUrl parameter in these expressions is a string defining the protocol and the address of the running instance of the EMS Server. The serverUrl parameter has the form:

   serverUrl = protocol://host:port

The supported protocols are tcp and ssl. For example:

   serverUrl = tcp://server0:7222

For a fault-tolerant connection, you can specify two or more URLs. For example:

   serverUrl = tcp://server0:7222,tcp://server1:7344

See Configure Clients for Shared State Failover Connections for more information. For details on using SSL for creating secure connections to the server, see Configure SSL in EMS Clients and Create Connection Factories for Secure Connections.

  • Java

    To dynamically create a TibjmsConnectionFactory object in a Java client:

       ConnectionFactory factory = new 
          com.tibco.tibjms.TibjmsConnectionFactory(serverUrl);

    See the tibjmsMsgProducer.java sample client for a working example.

  • C

    To dynamically create a tibemsConnectionFactory type in a C client:

       factory = tibemsConnectionFactory_Create();
       status = tibemsConnectionFactory_SetServerURL(
                    factory, serverUrl);

    See the tibemsMsgProducer.c sample client for a working example.

  • C#

    To dynamically create a ConnectionFactory object in a C# client:

       ConnectionFactory factory = new
          TIBCO.EMS.ConnectionFactory(serverUrl);

    See the csMsgProducer.cs sample client for a working example.