LibraryToggle FramesPrintFeedback

The easiest way to configure a JMS endpoint to participate in transactions is to create a new an instance of a Camel JMS component that has the proper settings. To do so:

  1. Create a bean element that has its class attribute set to org.apache.camel.component.jms.JmsComponent.

    This bean creates an instance of the Fuse Mediation Router's JMS component.

  2. Set the bean's id attribute to a unique, short, string.

    The id will be used to create route endpoint's that use this JMS component.

  3. Add an empty property child to the bean.

  4. Add a name attribute with the value of configuration to the property element.

  5. Add a ref attribute whose value is the id of a JmsConfiguration bean to the property element.

    The JmsConfiguration bean is used to configure the JMS component.

  6. Create a bean element that has its class attribute set to org.apache.camel.component.jms.JmsConfiguration.

    This bean creates an instance of the Fuse Mediation Router's JMS component configuration.

  7. Set the bean's id attribute to the value supplied for the ref attribute in Step 5.

  8. Add a property child to the bean to configure the JMS connection factory.

    1. Set the name attribute to connectionFactory.

    2. Set the ref attribute to the id of a bean that configures a JMS connection factory.

  9. Add an empty property child to the bean that specifies the transaction manager the component will use.

    1. Set the name attribute to transactionManager.

    2. Set the ref attribute to the id of a bean that configures transaction manager the endpoint will use.

    See Selecting a Transaction Manager.

  10. Add an empty property child to the bean that configures the component to participate in transactions.

    1. Set the name attribute to transacted.

    2. Set the value attribute to true.

      The transacted property determines if the endpoint can participate in transactions.

  11. Optionally add an empty property child to the bean to change the default cache level.

    1. Set the name attribute to cacheLevelName.

    2. Set the value attribute to to a valid cache level.

    See Cache levels and performance.

The JmsComponent bean's id specifies the URI prefix used by JMS endpoints that will use the transactional JMS component. For example, in Example 3.1 the JmsComponent bean's id equals jmstx, so endpoint that use the configured JMS component use the jmstx: prefix.

The JmsConfiguration class supports a large number of other properties, which are essentially identical to the JMS URI options described in JMS in Component Reference.

Example 3.1 shows the configuration of a JMS component, jmstx that supports Spring transactions. The JMS component is layered over an embedded instance of Apache ActiveMQ and the transaction manager is an instance of JmsTransactionManager.


To use this JMS component in a route you would use the URI prefix jmstx: as shown in Example 3.2.


Comments powered by Disqus