이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 3. JMS Transactions


Abstract

JMS endpoints create special problems when transactions are enabled. Their behavior is effected by the type of transaction manager in use, the caching level in use, and the message exchange pattern in use.

3.1. Configuring the JMS Component

Overview

To enable transactions in a JMS component (thus enabling JMS endpoints to play the role either of a transactional resource or a transactional client), you need to:
  • set the transacted property
  • provide the JMS component with a reference to a suitable transaction manager
In addition, you may want to adjust the JMS component's cache level setting. External transaction managers can impact caching performance.

Camel JMS component configuration

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 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 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.
  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.
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, “JMS Transaction Manager Configuration” 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 chapter "JMS" in "EIP Component Reference".

Cache levels and performance

The settings for JMS cache level can impact performance when you are using transactions. The default cache level is CACHE_AUTO. This default auto detects if an external transaction manager is in use and sets the cache level as follows:
  • CACHE_CONSUMER if only local JMS resources are in use
  • CACHE_NONE if an external transaction manager is in use
This behavior guarantees that there will not be any conflicts between caching and the transaction manager because some XA transaction managers require that caching is disabled. However, this behavior may not produce optimal performance.
If your transaction manager does not require that caching be disabled, you can raise the cache level to improve performance. Consult your transaction manager's documentation to determine what caching level it can support. Then override the default cache level by setting the JMS component's cacheLevelName property to the new cache level.
See chapter "JMS" in "EIP Component Reference" for information on setting the cache level of the JMS component.

Example

Example 3.1, “JMS Transaction Manager Configuration” 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.

Example 3.1. JMS Transaction Manager Configuration

<beans xmlns="http://www.springframework.org/schema/beans" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
  ...
  <bean id="jmstx" class="org.apache.camel.component.jms.JmsComponent"> 
    <property name="configuration" ref="jmsConfig" /> 
  </bean> 

  <bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration"> 
      <property name="connectionFactory" ref="jmsConnectionFactory"/> 
      <property name="transactionManager" ref="jmsTransactionManager"/> 
      <property name="transacted" value="true"/>
      <property name="cacheLevelName" value="CACHE_CONNECTION"/>
  </bean> 

  <bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager">
    <property name="connectionFactory" ref="jmsConnectionFactory" />
  </bean>
  
  <bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL" value="vm://broker1?brokerConfig=xbean:tutorial/activemq.xml"/>
  </bean>

</beans>
Copy to Clipboard Toggle word wrap
To use this JMS component in a route you would use the URI prefix jmstx: as shown in Example 3.2, “URI for Using Transacted JMS Endpoint”.

Example 3.2. URI for Using Transacted JMS Endpoint

from("jmstx:queue:rawStockQuotes")
    .process(myFormatter)
    .to("jmstx:queue:formattedStockQuotes");
Copy to Clipboard Toggle word wrap
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat