High Quality Enterprise Messaging.

Outbound Configuration

Define Administered Objects (Queues and Topics)

Administered JMS objects such as queues and topics are used for outbound messaging and must be JavaBeans according to the Connector 1.5 specification. They are created by application server specific admin tools, JavaBean properties are set and then stored in the application server's JNDI tree.

SwiftMQ's javax.jms.Queue objects are implemented by class "com.swiftmq.jms.QueueImpl". This class has 1 JavaBean property "queueName" of type java.lang.String. This property has to be set to the fully qualified name of the resp. queue, e.g. "testqueue@router1".

SwiftMQ's javax.jms.Topic objects are implemented by class "com.swiftmq.jms.TopicImpl". This class has 1 JavaBean property "topicName" of type java.lang.String. This property has to be set to the resp. topic name, e.g. "testtopic".

The following example creates a queue in the Glassfish application server, sets the "queueName" JavaBean property to "orderqueue@router1" and stores it under context "java:/comp/env/jms" and name "orderQueue" in the application server's JNDI tree:

  asadmin create-admin-object --user admin --password xxxxxx \
    --restype javax.jms.Queue \
    --raname SwiftMQ_JMS_Resource_Adapter \
    --property queueName=orderqueue@router1 jms/OrderQueue

Create Connection Pools

After SwiftMQ's RA deployment and creation of administered objects (queues/topics, see above), you have to configure connection pools to use SwiftMQ's RA for outbound messaging and synchronous receive from MDBs/EJBs. A connection pool is an entity of the application server and contains instances of managed connections which are created from a managed connection factory. They are not visible to applications. For each type of JMS connection factory (ConnectionFactory, QueueConnectionFactory, TopicConnectionFactory) you should create a distinct pool.

Each connection pool must be configured with properties to enable the underlying managed connection factory to create the physical JMS connection. In SwiftMQ's RA these properties are (change for Connector 1.6 Resource Adapter: All property names start with a lowercase character):

Property Name (1.5) Property Name (1.6) Type Mandatory Default Value
ConnectionFactoryName connectionFactoryName java.lang.String No see below
UserName userName java.lang.String No null
Password password java.lang.String No null

ConnectionFactoryName

The name of SwiftMQ's JMS connection factory to use. Remember that SwiftMQ's RA has a JNDI context, pointing to the SwiftMQ router. The value of this property is used to lookup the connection factory there. If the RA uses an external router, simply use the predefined connection factory like "ConnectionFactory". If a SwiftMQ router is started intraVM, use an intraVM connection factory like "IVMConnectionFactory". Both connection factories implement queue and topic connection factories as well.

The default value depends on the type of the JMS connection. If the type is "javax.jms.ConnectionFactory", then the default value is "ConnectionFactory", if the type is "javax.jms.QueueConnectionFactory", then the default value is "QueueConnectionFactory", and if the type is "javax.jms.TopicConnectionFactory", then the default value is "TopicConnectionFactory".

UserName

The SwiftMQ user name to use to connect. If none is specified, the login takes place as "anonymous".

Password

The password for the SwiftMQ user.

To create connection pools one must use the application server's admin tools or define it in their configuration files. The following example creates a connection pool in the Glassfish application server for each type of JMS connection. The pools are named "swiftmq-connection-pool1", "swiftmq-connection-pool2", "swiftmq-connection-pool3":

      asadmin create-connector-connection-pool --user admin --password xxxxxx \
        --steadypoolsize 20 --maxpoolsize 100 --poolresize 2 \
        --maxwait 60000 --raname SwiftMQ_JMS_Resource_Adapter \
        --connectiondefinition javax.jms.ConnectionFactory \
        --property UserName=admin:Password=secret swiftmq-connection-pool1

      asadmin create-connector-connection-pool --user admin --password xxxxxx \
        --steadypoolsize 20 --maxpoolsize 100 --poolresize 2 \
        --maxwait 60000 --raname SwiftMQ_JMS_Resource_Adapter \
        --connectiondefinition javax.jms.QueueConnectionFactory \
        --property UserName=admin:Password=secret swiftmq-connection-pool2

      asadmin create-connector-connection-pool --user admin --password xxxxxx \
        --steadypoolsize 20 --maxpoolsize 100 --poolresize 2 \
        --maxwait 60000 --raname SwiftMQ_JMS_Resource_Adapter \
        --connectiondefinition javax.jms.TopicConnectionFactory \
        --property UserName=admin:Password=secret swiftmq-connection-pool3

Create Connection Factories

Until now we have deployed the RA, have defined administered objects such as queues and topics, and have created one or more connection pools for managed connections. The last step is to create connection factories which application components (MDBs, EJBs) can use to create connections. These connections are actually "handles" which are linked to a managed connection instance during its creation and released from it during its close.

The following example creates 3 connection factories in the J2EE 1.4 application server, one for each of the above connection pools:

      asadmin create-connector-resource --user admin --password xxxxxx \
        --poolname swiftmq-connection-pool1 \
        --description "SwiftMQ Unified CF" jms/ConnectionFactory

      asadmin create-connector-resource --user admin --password xxxxxx \
        --poolname swiftmq-connection-pool2 \
        --description "SwiftMQ Queue CF" jms/QueueConnectionFactory

      asadmin create-connector-resource --user admin --password xxxxxx \
        --poolname swiftmq-connection-pool3 \
        --description "SwiftMQ Topic CF" jms/TopicConnectionFactory

Ready to use!

Now you are ready to use the connection factories to send and synchronously receive messages. All you have to do is the usual JMS stuff. The following example snippet is a MDB which forwards the received message to a SwiftMQ queue:

    public void onMessage(Message inMessage)
    {
      try
      {
        InitialContext ctx = new InitialContext();
        ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/ConnectionFactory");
        Connection connection = cf.createConnection();
        Destination dest = (Destination) ctx.lookup("jms/OrderQueue");
        Session session = connection.createSession(true, 0);
        MessageProducer producer = session.createProducer(dest);
        TextMessage msg = session.createTextMessage("FWD: " + ((TextMessage) inMessage).getText());
        producer.send(msg);
        producer.close();
        session.close();
        connection.close();
      } catch (Exception e)
      {
        e.printStackTrace();
      }
    }