ConnectionFactories and Connection objects

A ConnectionFactory object provides a template that an application uses to create a Connection object. The application uses the Connection object to create a Session object.

For .NET, an XMS application first uses an XMSFactoryFactory object to get a reference to a ConnectionFactory object that is appropriate to the required type of protocol. This ConnectionFactory object can then produce connections only for that protocol type.

An XMS application can create multiple connections, and a multithreaded application can use a single Connection object concurrently on multiple threads. A Connection object encapsulates a communications connection between an application and a messaging server.

A connection serves several purposes:

  • When an application creates a connection, the application can be authenticated.
  • An application can associate a unique client identifier with a connection. The client identifier is used to support durable subscriptions in the publish/subscribe domain. The client identifier can be set in two ways:

    The preferred way of assigning a connections client identifier, is to configure in a client-specific ConnectionFactory object using properties and transparently assign it to the connection it creates.

    An alternative way of assigning a client identifier is to use a provider-specific value that is set on the Connection object. This value does not override the identifier that has been administratively configured. It is provided for the case where no administratively specified identifier exists. If an administratively specified identifier does exist, an attempt to override it with a provider-specific value causes an exception to be thrown. If an application explicitly sets an identifier, it must do it immediately after creating the connection and before any other action on the connection is taken; otherwise, an exception is thrown.

An XMS application typically creates a connection, one or more sessions, and a number of message producers and message consumers.

Creating a connection is relatively expensive in terms of system resources because it involves establishing a communications connection, and it might also involve authenticating the application.