Use a connection factory to create a connection

 

We can use the createConnection() method on a ConnectionFactory object to create a Connection object, as shown in the following example:

Connection connection;
connection = factory.createConnection();

Both QueueConnectionFactory and TopicConnectionFactory inherit the createConnection() method from ConnectionFactory. We can therefore use createConnection() to create a domain specific object, as shown in the following code:

QueueConnectionFactory QCF;
Connection connection;
connection = QCF.createConnection();

This code creates a QueueConnection object. An application can now perform a domain independent operation on this object, or an operation that is applicable only to the point-to-point domain. If the application attempts to perform an operation that is applicable only to the publish/subscribe domain, an IllegalStateException is thrown with the message MQJMS1112: JMS 1.1 Invalid operation for a domain specific object. This is because the connection was created from a domain specific connection factory.


uj25010_