Contact Us 1-800-596-4880

SwiftMQ Integration

This page describes how to use SwiftMQ with Mule.

Configuring a Mule JMS Connector

The best approach for integrating SwiftMQ is via JNDI. You will specify the following attributes:

Attribute Description Recommended Value

jndiInitialFactory

InitialContext factory

com.swiftmq.jndi.InitialContextFactoryImpl

jndiProviderUrl

JNDI Provider URL

smqp://localhost:4001/timeout=10000

jndiDestinations

JNDI lookup of queues/topics

true

forceJndiDestinations

Forces a JNDI exception if a destination was not found in JNDI

true

specification

Version of the JMS specification

1.1

connectionFactoryJndiName

Name of the JMS connection factory to use

ConnectionFactory

For example:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:spring="http://www.springframework.org/schema/beans"
      xmlns="http://www.mulesoft.org/schema/mule/core"
      xmlns:jms="http://www.mulesoft.org/schema/mule/jms"
    xsi:schemaLocation="
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
      http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.0/mule.xsd
      http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/3.0/mule-jms.xsd">

  <jms:connector name="jmsConnector"
                   connectionFactoryJndiName="ConnectionFactory"
                   jndiDestinations="true"
                   forceJndiDestinations="true"
                   jndiInitialFactory="com.swiftmq.jndi.InitialContextFactoryImpl"
                   jndiProviderUrl="smqp://localhost:4001/timeout=10000"
                   specification="1.1"/>
...

After you have configured the connector, copy swiftmq.jar into the Mule lib/user directory and start the SwiftMQ Router. You can now use SwiftMQ from Mule.

Configuring the Loan Broker ESB Example with SwiftMQ

The following example shows you how to modify the Loan Broker example to use SwiftMQ. The only change necessary is to modify the JMS connector in both example configuration files. With a SwiftMQ Router running on the local host, the connector would look like this:

<jms:connector name="jmsConnector"
                   connectionFactoryJndiName="ConnectionFactory"
                   jndiDestinations="true"
                   forceJndiDestinations="true"
                   jndiInitialFactory="com.swiftmq.jndi.InitialContextFactoryImpl"
                   jndiProviderUrl="smqp://localhost:4001/timeout=10000"
                   specification="1.1"/>

The Loan Broker ESB example uses the following JMS queues (Mule syntax):

jms://esb.loan.quotes
jms://esb.credit.agency
jms://esb.lender.service
jms://esb.banks

SwiftMQ does not allow dots '.' in queue names. Instead, use underscores '_' in SwiftMQ’s routerconfig.xml:

<swiftlet name="sys$queuemanager">
    <queue-controllers>
        <queue-controller name="01" persistence-mode="non_persistent" predicate="tmp$%"/>
        <queue-controller name="02" predicate="sys$%"/>
        <queue-controller name="03" predicate="swiftmq%"/>
        <queue-controller name="04" predicate="rt$%"/>
        <queue-controller name="05" predicate="unroutable"/>
        <queue-controller name="06" predicate="%$%"/>
        <queue-controller name="07" predicate="%"/>
    </queue-controllers>
    <queues>
        <queue name="esb_banks"/>
        <queue name="esb_credit_agency"/>
        <queue name="esb_lender_service"/>
        <queue name="esb_loan_quotes"/>
    </queues>
</swiftlet>

To match with the Loan Broker ESB example’s JMS queue names, define JNDI aliases in SwiftMQ’s routerconfig.xml:

<swiftlet name="sys$jndi">
    <aliases>
        <alias name="esb.banks" map-to="esb_banks@router1"/>
        <alias name="esb.credit.agency" map-to="esb_credit_agency@router1"/>
        <alias name="esb.lender.service" map-to="esb_lender_service@router1"/>
        <alias name="esb.loan.quotes" map-to="esb_loan_quotes@router1"/>
    </aliases>
    <jndi-replications/>
    <remote-queues/>
</swiftlet>

You now rebuild the Loan Broker ESB example with Ant or Maven so that the configuration changes can take effect, then start the SwiftMQ Router and the Loan Broker ESB example.

Note that the @ sign can be escaped with %40 in the Mule URI, so for an alternate configuration you can use the following:

<endpoint name="LoanBrokerRequestsREST" address="jetty:rest://localhost:8080/loanbroker"/>
    <vm:endpoint name="LoanBrokerRequests" path="loan.broker.requests"/>
    <jms:endpoint name="LoanQuotes" address="jms://esb_loan_quotes%40router1"/>
    <jms:endpoint name="CreditAgencyGateway" address="jms://esb_credit_agency%40router1"/>
    <!-- here we're telling Mule to invoke a remote Ejb directly (not host a
         proxy service for the remote object as with the other example in mule-config-with-ejb-container.xml example)
    -->
    <ejb:endpoint name="CreditAgency" host="localhost" port="1099" object="local/CreditAgency" method="getCreditProfile" />
    <!-- endpoint name="CreditAgency" address="ejb://localhost:1099/local/CreditAgency?method=getCreditProfile" / -->
    <endpoint name="LenderGateway" address="jms://esb.lender.service" />
    <endpoint name="LenderService" address="vm://lender.service" />
    <endpoint name="BankingGateway" address="jms://esb.banks%40router1" />
    <endpoint name="Bank1" address="axis:http://localhost:10080/mule/TheBank1?method=getLoanQuote"
              synchronous="true" />
    <endpoint name="Bank2" address="axis:http://localhost:20080/mule/TheBank2?method=getLoanQuote"
              synchronous="true" />
    <endpoint name="Bank3" address="axis:http://localhost:30080/mule/TheBank3?method=getLoanQuote"
              synchronous="true" />
    <endpoint name="Bank4" address="axis:http://localhost:40080/mule/TheBank4?method=getLoanQuote"
              synchronous="true" />
    <endpoint name="Bank5" address="axis:http://localhost:50080/mule/TheBank5?method=getLoanQuote"
              synchronous="true" />

Keep in mind that a SwiftMQ JNDI alias also decouples a queue from its physical location. You can move a queue to another router without affecting clients. So it’s always best practice to avoid physical queue names.