Create factories at runtime

 

If a JNDI namespace is not available, it is possible to create factory objects at runtime. However, using this method reduces the portability of the JMS application because it requires references to WebSphere MQ specific classes.

The following code creates a QueueConnectionFactory with all default settings:

factory = new com.ibm.mq.jms.MQQueueConnectionFactory();

(We can omit the com.ibm.mq.jms. prefix if you import the com.ibm.mq.jms package instead.)

A connection created from the above factory uses the Java™ bindings to connect to the default queue manager on the local machine. The set methods described in MQConnectionFactory can be used to customize the factory with WebSphere MQ specific information.

The only way to create a TopicConnectionFactory object at runtime is to construct it using the MQTopicConnectionFactory constructor. For example:

MQTopicConnectionFactory fact = new MQTopicConnectionFactory();
This creates a default TopicConnectionFactory object with the bindings transportType and all other default settings.

It is possible to change the transportType for the TopicConnectionFactory using its setTransportType() method. For example:

fact.setTransportType(JMSC.MQJMS_TP_BINDINGS_MQ);     // Bindings mode
fact.setTransportType(JMSC.MQJMS_TP_CLIENT_MQ_TCPIP); // Client mode
fact.setTransportType(JMSC.MQJMS_TP_DIRECT_TCPIP);    // Direct TCP/IP mode
The full JMS TopicConnectionFactory interface has been implemented. Refer to MQTopicConnectionFactory for more details. Note that certain combinations of property settings are not valid for TopicConnectionFactory objects. See Properties for more details.


uj24370_