Red Hat Training

A Red Hat training course is available for Red Hat Fuse

Chapter 2. Configuring the Connection Factory

Abstract

The JMS binding component needs to have access to your JMS provider's connection factory. This is configured in the XML file and the specifics depend on the JMS provider in use.
Important
The Java Business Integration components of Red Hat JBoss Fuse are considered deprecated. You should consider migrating any JBI applications to OSGi.
When working with a JMS broker, a client application needs a ConnectionFactory object to create connections to the broker. The ConnectionFactory object is a JMS object that is provided along with the JMS broker. Each JMS provider has a unique ConnectionFactory object that uses properties specific to a particular JMS implementation.
When using the Red Hat JBoss Fuse JMS binding component, you must configure each service unit with the information it needs to load a ConnectionFactory object. Often the ConnectionFactory object is looked up through JNDI. However, the information needed depends on the JMS provider you are using.
Commonly used JMS providers include Red Hat JBoss A-MQ, Apache ActiveMQ, IBM's WebShere® MQ, BEA's WebLogic®, and Progress Software's SonicMQ®. JBoss A-MQ and Apache ActiveMQ can be configured using simple Spring XML. Other JMS providers must be configured using either JNDI or using custom Spring beans. This chapter provides basic information for configuring the ConnectionFactory objects for each of these platforms.

2.1. Using Apache ActiveMQ Connection Factories

Overview

The recommended method for creating connections to Apache ActiveMQ, is by using the Jencks AMQPool. It provides support for using a scalable pool of connections for managing overhead. You can download the needed jar from http://repo1.maven.org/maven2/org/jencks/jencks-amqpool/2.0/jencks-amqpool-2.0.jar. Once the jar is downloaded, you need to add it to your classpath. The easiest way to do this is to place the jar into your InstallDir\lib folder.
Note
The examples included with Red Hat JBoss Fuse use the standard Apache ActiveMQ connection factory. This is fine for testing purposes, but is not robust enough for enterprise deployments.
The Jencks AMQPool supplies three connection factories:

Namespace

To add the AMQPool configuration elements to your endpoint's configuration, you need to add the following XML namespace declaration to your beans element:
xmlns:amqpool="http://jencks.org/amqpool/2.0"

Simple pool

The simple pooling connection factory supports pooling, but does not support transactions. It is specified using the amqpool:pool element. The attributes used to configure the simple pooled connection factory are described in Table 2.1, “Attributes for Configuring the Simple AMQPool Connection Factory”.

Table 2.1. Attributes for Configuring the Simple AMQPool Connection Factory

AttributeDescriptionRequired
id Specifies a unique identifier by which other elements refer to this element.yes
url Specifies the URL used to connect to the JMS broker.yes
maxConnections Specifies the maximum number of simultaneous connections to the broker. The default value is 1, but you can safely increase it to 8 in all conditions.no
maximumActive Specifies the maximum number of active sessions for a particular connection. The default value is 500.no
Example 2.1, “Configuring a Simple AMQPool Connection Factory” shows a configuration snippet for configuring the simple AMQPool connection factory.

Example 2.1. Configuring a Simple AMQPool Connection Factory

<beans xmlns:amqpool="http://jencks.org/amqpool/2.0"
       ... >
  ...
  <amqpool:pool id="connectionFactory" 
                url="tcp://localhost:61616" 
                maxConnections="8" />
</beans>

XA pool

The XA pooling connection factory supports XA transactions and late enlistment. It is specified using the amqpool:xa-pool element. The attributes used to configure the XA pooled connection factory are described in Table 2.2, “Attributes for Configuring the XA AMQPool Connection Factory”.

Table 2.2. Attributes for Configuring the XA AMQPool Connection Factory

AttributeDescriptionRequired
id Specifies a unique identifier by which other elements refer to this element.yes
url Specifies the URL used to connect to the JMS broker.yes
transactionManager Specifies a reference to an element that configures an XA transaction manager.yes
maxConnections Specifies the maximum number of simultaneous connections to the broker. The default value is 1, but you can safely increase it to 8 in all conditions.no
maximumActive Specifies the maximum number of active sessions for a particular connection. The default value is 500.no
Example 2.2, “Configuring an XA AMQPool Connection Factory” shows a configuration snippet for configuring an XA AMQPool connection factory.

Example 2.2. Configuring an XA AMQPool Connection Factory

<beans xmlns:amqpool="http://jencks.org/amqpool/2.0"
       xmlns:jencks="http://jencks.org/2.0"
       ... >
  ...
  <amqpool:xa-pool id="connectionFactory" 
                   url="tcp://localhost:61616" 
                   maxConnections="8" 
                   transactionManager="#transactionManager" />

  <jencks:transactionManager id="transactionManager"
                             transactionLogDir="./data/txlog"
                             defaultTransactionTimeoutSeconds="600" />

</beans>

JCA pool

The JCA pooling connection factory is intended to be used inside of J2EE environments or in conjunction with the Jencks JCA environment. It is specified using the amqpool:jca-pool element. The attributes used to configure the JCA pooled connection factory are described in Table 2.3, “Attributes for Configuring the JCA AMQPool Connection Factory”.

Table 2.3. Attributes for Configuring the JCA AMQPool Connection Factory

AttributeDescriptionRequired
id Specifies a unique identifier by which other elements refer to this element.yes
url Specifies the URL used to connect to the JMS broker.yes
transactionManager Specifies a reference to an element that configures an XA transaction manager.yes
name Specifies a unique name by which the JMS broker can be identified.yes
maxConnections Specifies the maximum number of simultaneous connections to the broker. The default value is 1, but you can safely increase it to 8 in all conditions.no
maximumActive Specifies the maximum number of active sessions for a particular connection. The default value is 500.no
Example 2.3, “Configuring a JCA AMQPool Connection Factory” shows a configuration snippet for configuring the JCA AMQPool connection factory.

Example 2.3. Configuring a JCA AMQPool Connection Factory

<beans xmlns:amqpool="http://jencks.org/amqpool/2.0"
       xmlns:jencks="http://jencks.org/2.0"
       ... >
  ...
  <amqpool:jca-pool id="connectionFactory" 
                   url="tcp://localhost:61616" 
                   maxConnections="8" 
                   transactionManager="#transactionManager"
                   name="joeFred" />

  <jencks:transactionManager id="transactionManager"
                             transactionLogDir="./data/txlog"
                             defaultTransactionTimeoutSeconds="600" />

</beans>