Connect to the EMS Server

A connection with the EMS server is defined by the Connection object obtained from a Connection Factory.

For more information, see Connection Factories.

A connection is a fairly heavyweight object, so most clients will create a connection once and keep it open until the client exits. Your application can create multiple connections, if necessary.

The following examples show how to create a Connection object.

  • Java

    Use the TibjmsConnectionFactory object’s createConnection() method to create a Connection object:

       Connection connection =                 factory.createConnection(userName,password);

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

  • C

    Use the tibemsConnectionFactory_CreateConnection function to create a connection of type tibemsConnection:

       tibemsConnection connection = NULL;
       status = tibemsConnectionFactory_CreateConnection(factory,
                    &connection, userName, password);

    If there is no connection factory, a C client can use the tibemsConnection_Create function to dynamically create a tibemsConnection type:

       status = tibemsConnection_Create(&connection,
                    serverUrl,NULL,userName,password);

    The tibemsConnection_Create function exists for backward compatibility, but the recommended procedure is that you create tibemsConnection objects from factories.

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

  • C#

    Use the ConnectionFactory.CreateConnection method to create a Connection object:

       Connection connection =
                    factory.CreateConnection(userName, password);

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