Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.このコンテンツは選択した言語では利用できません。
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:
- Create a
beanelement that has itsclassattribute set toorg.apache.camel.component.jms.JmsComponent.This bean creates an instance of the JMS component. - Set the bean's
idattribute to a unique, short, string.The id will be used to create route endpoint's that use this JMS component. - Add an empty
propertychild to the bean. - Add a
nameattribute with the value ofconfigurationto thepropertyelement. - Add a
refattribute whose value is the id of aJmsConfigurationbean to thepropertyelement.TheJmsConfigurationbean is used to configure the JMS component. - Create a
beanelement that has itsclassattribute set toorg.apache.camel.component.jms.JmsConfiguration.This bean creates an instance of the JMS component configuration. - Add a
propertychild to the bean to configure the JMS connection factory.- Set the
nameattribute toconnectionFactory. - Set the
refattribute to the id of a bean that configures a JMS connection factory.
- Add an empty
propertychild to the bean that specifies the transaction manager the component will use.- Set the
nameattribute totransactionManager. - Set the
refattribute to the id of a bean that configures transaction manager the endpoint will use.
- Add an empty
propertychild to the bean that configures the component to participate in transactions.- Set the
nameattribute totransacted. - Set the
valueattribute totrue.The transacted property determines if the endpoint can participate in transactions.
- Optionally add an empty
propertychild to the bean to change the default cache level.- Set the
nameattribute tocacheLevelName. - Set the
valueattribute to to a valid cache level. For example, the recommended cache level for an ActiveMQ messaging resource isCACHE_CONSUMER, which gives optimum performance. For more details, see the section called “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, “JMS Transaction Manager Configuration” the JmsComponent bean's id equals jmstx, so endpoint that use the configured JMS component use the jmstx: prefix.
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_CONSUMERif only local JMS resources are in useCACHE_NONEif 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.
Note
When the transactional resource is ActiveMQ, it is generally safe to set the cache level to
CACHE_CONSUMER and this setting is recommended, because it improves performance significantly.
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
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");
from("jmstx:queue:rawStockQuotes")
.process(myFormatter)
.to("jmstx:queue:formattedStockQuotes");