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 C and C++, there is a single type of ConnectionFactory which has a
property that enables you to select which type of protocol you want to use
for a connection. 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 only produce connections 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 serves several purposes:
- A Connection object encapsulates a communications connection between an
application and a messaging server.
- 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. There
are two ways of setting the client identifier:
- The preferred way of assigning a connection's client identifier is for
it to be configured in a client-specific ConnectionFactory object using properties
and transparently assigned 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 this immediately after creating the connection,
and before any other action on the connection is taken, otherwise an exception
is thrown.
- A C application can register an exception listener function and context
data with a connection. A C++ application can register an exception listener
with a connection.
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.