Warning

This component has been deprecated in favor to servicemix-jms component.

The JMS components allow you to send and receive JMS messages. The JMS components assume that the NormalizedMessage they are given are ready for marshalling into/out of JMS, so they don't try to implement a SOAP stack or perform any complex message transformation other than to map NMS to JMS or vice versa.

If you wish to customize the marshalling from NMS to JMS or vice versa you can customize the JmsMarshaler used to perform the mapping.

Performance Note

If you wish to process messages in a high performance setting and want to use connection & thread pooling, transaction & exception & retry handling and want to support parallel processing of inbound messages we recommend you use the JCA support for inbound JMS messages.

Receiving JMS messages

The JmsReceiverComponent subscribes to the given destination using Spring's JmsTemplate and dispatches the message into the JBI container. Here's an example of subscribing to a JMS destination (in this case a topic) and forwarding the JBI message onto another JBI component - which in this case is the foo:transformer service.

<sm:activationSpec componentName="myJmsReceiver" service="foo:myJmsReceiver" destinationService="foo:transformer">
  <sm:component><bean class="org.apache.servicemix.components.jms.JmsReceiverComponent">
    <property name="template">
      <bean class="org.springframework.jms.core.JmsTemplate">
        <property name="connectionFactory">
          <ref local="jmsFactory"/>
        </property>
        <property name="defaultDestinationName" value="test.org.apache.servicemix.components.xslt.source"/>
        <property name="pubSubDomain" value="true"/>
      </bean>
    </property>
  </bean></sm:component>
</sm:activationSpec>

If you wish to use JCA or some other mechanism to subscribe to JMS you can use the JmsInBinding.

Sending JMS messages

The JmsSenderComponent will send JMS messages from the input message exchange. This component uses Spring's JmsTemplate to perform the sending. The following example demonstrates a component which when invoked will send a message to a given JMS topic

<sm:activationSpec componentName="myJmsSender" service="foo:myJmsSender">
  <sm:component><bean class="org.apache.servicemix.components.jms.JmsSenderComponent">
    <property name="template">
      <bean class="org.springframework.jms.core.JmsTemplate">
        <property name="connectionFactory">
          <ref local="jmsFactory"/>
        </property>
        <property name="defaultDestinationName" value="test.org.apache.servicemix.components.xslt.source"/>
        <property name="pubSubDomain" value="true"/>
      </bean>
    </property>
  </bean></sm:component>
</sm:activationSpec>

JMS bridges

Its a very common requirement to create a message bridge; routing messages from one messaging system to another. With ServiceMix we can connect any transport with any transport - but for now lets focus on JMS to JMS bridging. Imagine for example you wish to route messages from ActiveMQ to MQSeries, or from WebLogic JMS to ActiveMQ.

The following example demonstrates how to setup a JMS bridge in ServiceMix

<beans xmlns:sm="http://servicemix.apache.org/config/1.0" 
	   xmlns:foo="http://servicemix.org/demo/pipeline/">

  <!-- the JBI container and its components -->
  <sm:container id="jbi" embedded="true">
    <sm:activationSpecs>

      <sm:activationSpec componentName="myJmsReceiver" service="foo:myJmsReceiver" destinationService="foo:transformer">
        <sm:component><bean class="org.apache.servicemix.components.jms.JmsReceiverComponent">
          <property name="template">
            <bean class="org.springframework.jms.core.JmsTemplate">
              <property name="connectionFactory">
                <ref local="jmsFactory"/>
              </property>
              <property name="defaultDestinationName" value="demo.cheese.source"/>
              <property name="pubSubDomain" value="true"/>
            </bean>
          </property>
        </bean></sm:component>
      </sm:activationSpec>

      <sm:activationSpec componentName="transformer" service="foo:transformer" destinationService="foo:transformedSender">
        <sm:component><bean class="org.apache.servicemix.components.xslt.XsltComponent">
          <property name="xsltResource" value="classpath:org/apache/servicemix/components/xslt/transform.xsl"/>
        </bean></sm:component>
      </sm:activationSpec>

      <sm:activationSpec componentName="transformedSender" service="foo:transformedSender">
        <sm:component><bean class="org.apache.servicemix.components.jms.JmsSenderComponent">
          <property name="template">
            <bean class="org.springframework.jms.core.JmsTemplate">
              <property name="connectionFactory">
                <ref local="jmsFactory"/>
              </property>
              <property name="defaultDestinationName" value="demo.cheese.result"/>
              <property name="pubSubDomain" value="true"/>
            </bean>
          </property>
        </bean></sm:component>
      </sm:activationSpec>

    </sm:activationSpecs>
  </sm:container>

  <bean id="jmsFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
    <property name="connectionFactory">
      <bean class="org.apache.activemq.ActiveMQConnectionFactory">
        <property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
      </bean>
    </property>
  </bean>

</beans>

This example is performing an XSLT transform on the messages as well - you can perform arbitrary processing of the messages in the bridge, performing rules processing or content based routing. Obviously you could miss out the transformation step and just route the inbound message on one JMS provider to another JMS provider without any transform step.