Atomikos - Spring 통합
Spring Integration
Configuring Atomikos as the Spring JTA Transaction Manager
The Basic Case (Pre-3.3)
The Advanced Case (As of 3.3)
Spring-Demarcated Transactions for POJOs
Receiving JMS Messages
With the Atomikos MessageDrivenContainer
With Spring's MessageListenerContainer
Sending JMS Messages
With the Atomikos JmsSenderTemplate
With Spring's JmsTemplate
Accessing the Database
Configuring Atomikos DataSource
Spring's JdbcTemplate
Spring's HibernateTemplate
Spring JMS Pitfalls
JMX Administration of Atomikos Transactions
Setting Atomikos System Properties in Spring
Optimizing the Init and Close Order for Recovery
Configuring Atomikos as the Spring JTA Transaction Manager
You basically have two big options: the basic case (with JTA property file lookup) or the advanced case (where everything is specified in the Spring configuration).
The Basic Case (Pre-3.3)
Atomikos can easily be configured as the Spring JTA transaction manager. The following code snippet shows how to specify this in your Spring configuration file:
"AtomikosTransactionManager"
class="com.atomikos.icatch.jta.UserTransactionManager"
init-method="init" destroy-method="close">
"forceShutdown" value="false" />
"AtomikosUserTransaction"
class="com.atomikos.icatch.jta.UserTransactionImp">
"transactionTimeout" value="300" />
"JtaTransactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
"transactionManager" ref="AtomikosTransactionManager" />
"userTransaction" ref="AtomikosUserTransaction" />
The Advanced Case (As of 3.3)
The advanced case adds the possibility to specify everything, including JTA properties and optional log administrators to manage the transaction logs.
"localLogAdministrator"
class="com.atomikos.icatch.admin.imp.LocalLogAdministrator"/>
"userTransactionService"
class="com.atomikos.icatch.config.UserTransactionServiceImp"
init-method="init" destroy-method="shutdownForce">
"com.atomikos.icatch.service">
com.atomikos.icatch.standalone.UserTransactionServiceFactory
"initialLogAdministrators">
"AtomikosTransactionManager"
class="com.atomikos.icatch.jta.UserTransactionManager"
init-method="init" destroy-method="close"
depends-on="userTransactionService">
"startupTransactionService" value="false"/>
"forceShutdown" value="false" />
"AtomikosUserTransaction"
class="com.atomikos.icatch.jta.UserTransactionImp"
depends-on="userTransactionService">
"transactionTimeout" value="300" />
"JtaTransactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager"
depends-on="userTransactionService">
"transactionManager" ref="AtomikosTransactionManager" />
"userTransaction" ref="AtomikosUserTransaction" />
At the time of writing, avoiding property file lookup also requires you to set the system property
com.atomikos.icatch.service
- since this property will NOT be read from the regular init properties that you supply. This will be fixed in a later release. Until then, you can find a Spring config workaround here:http://fogbugz.atomikos.com/default.asp?community.6.1921 Spring-Demarcated Transactions for POJOs
We support most of the Spring demarcation attributes except
PROPAGATION_NESTED
since that one depends on the Spring DataSourceTransactionManager
strategy (incompatible with JTA/XA). Receiving JMS Messages
You can receive messages either with the Atomikos receiver sessions, or with the Spring message listener containers.
With the Atomikos MessageDrivenContainer
See the examples in the Atomikos download for how to configure...
With Spring's MessageListenerContainer
You can also use Spring's message listener; the following XML fragment shows a complete example on how to configure this:
"xaFactory"
class="org.apache.activemq.ActiveMQXAConnectionFactory">
"brokerURL" value="tcp://localhost:61616" />
"ConnectionFactory"
class="com.atomikos.jms.AtomikosConnectionFactoryBean"
init-method="init" destroy-method="close">
"uniqueResourceName" value="amq1" />
"xaConnectionFactory" ref="xaFactory" />
"AtomikosTransactionManager"
class="com.atomikos.icatch.jta.UserTransactionManager"
init-method="init" destroy-method="close">
"forceShutdown" value="false" />
"AtomikosUserTransaction"
class="com.atomikos.icatch.jta.UserTransactionImp">
"transactionTimeout" value="300" />
"JtaTransactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
"transactionManager" ref="AtomikosTransactionManager" />
"userTransaction" ref="AtomikosUserTransaction" />
"MessageListener" class="jtatest.TextOutputMessageListener" />
"MessageListenerContainer"
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
"transactionManager" ref="JtaTransactionManager" />
"connectionFactory" ref="ConnectionFactory" />
"messageListener" ref="MessageListener" />
"destinationName" value="requestQueue" />
"concurrentConsumers" value="1" />
"receiveTimeout" value="3000" />
"sessionTransacted" value="true"/>
Note that the sessionTransacted property of the listener container must be set to true or it won't work!
Sending JMS Messages
For sending, again you have the option to use either the Atomikos classes or the Spring facilities...
With the Atomikos JmsSenderTemplate
See the examples in the Atomikos download for how to configure...
With Spring's JmsTemplate
The following XML snippet shows how to configure the Spring JmsTemplate to work with Atomikos.
"xaFactory" class="org.activemq.ActiveMQXAConnectionFactory">
"brokerURL">
tcp://localhost:61616
"topicConnectionFactoryBean"
class="com.atomikos.jms.AtomikosConnectionFactoryBean"
init-method="init" destroy-method="close">
"uniqueResourceName">
TOPIC_BROKER
"xaConnectionFactory">
"xaFactory"/>
"topic" class="org.activemq.message.ActiveMQTopic">
"physicalName">
TIMETABLE_TOPIC
"jmsTemplate"
class="org.springframework.jms.core.JmsTemplate">
"connectionFactory">
"topicConnectionFactoryBean"/>
"defaultDestination">
"topic"/>
"receiveTimeout" value="1000"/>
"sessionTransacted" value="true"/>
Note that the sessionTransacted attribute must be set to true! For performance, you can also wrap the connection factory in Spring's SingleConnectionFactory instead. This will reuse the same connection for sending in the JmsTemplate.
Accessing the Database
The database can be accessed in a variety of ways.
Configuring Atomikos DataSource
See the examples/demos included in the download for how to configure a data source in Spring.
Spring's JdbcTemplate
It suffices to make sure that the template's
datasource
is an Atomikos instance... Spring's HibernateTemplate
The following XML fragment shows how to configure the HibernateTemplate for JTA transactions with Atomikos.
"sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
"mappingResources">
...
...
"dataSource">"datasource"/>
"hibernateProperties">
"hibernate.dialect">...
"hibernate.connection.isolation">3
"hibernate.current_session_context_class">jta
"hibernate.transaction.factory_class">
org.hibernate.transaction.JTATransactionFactory
"hibernate.transaction.manager_lookup_class">
com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup
"hibernateTemplate"
class="org.springframework.orm.hibernate3.HibernateTemplate">
"sessionFactory">"sessionFactory"/>
Spring JMS Pitfalls
You should take care to set sessionTransacted to true for the JmsTemplate and the listener containers.
JMX Administration of Atomikos Transactions
From release 3.3 on, Atomikos can be configured for administration in JMX. The following shows how this works with Spring and JDK 1.5 or higher.
"jmxTransactionService"
class="com.atomikos.icatch.admin.jmx.JmxTransactionService">
"heuristicsOnly" value="true"/>
"mbeanServer"
class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
"exporter" class="org.springframework.jmx.export.MBeanExporter">
"beans">
"server">
"mbeanServer"/>
Also see JMX Instrumentation of Active Transactions for additional VM settings.
Setting Atomikos System Properties in Spring
The Spring Bean configuration of the class UserTransactionServiceImp described above can be used to set the Atomikos JTA properties. However there are three JVM (or System) properties that cannot be set through the constructor of the UserTransactionServiceImp class or via any programmatic means. These properties are:
com.atomikos.icatch.file
com.atomikos.icatch.no_file
com.atomikos.icatch.hide_init_file_path
Fortunately, it is possible to set the value of system properties within a Spring configuration file through the use of Spring's MethodInvokingFactoryBean class. For example:
/etc/myapp/jta.properties
true
In order for this to work, the Atomikos beans must add the Spring attribute "depend-on=" and add the Id of this bean. This will ensure the system property values are set prior to the initialization of Atomikos.
Optimizing the Init and Close Order for Recovery
In order to maximize recovery and shutdown/restart ability, it is highly recommended that you configure your Spring configuration with the following init dependencies:
Make the transaction manager depends on all your JDBC and JMS connection factories: this ensures that connections are kept until AFTER the transaction manager has terminated all transactions during shutdown.
Make any MessageDrivenContainer depend on the transaction manager, to ensure that all JMS listener sessions have terminated before the transaction manager starts shutting down.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
[Spring] Servlet(서블릿)이란? Servlet, Servlet Container 알아보기✔️ HTML Form으로 데이터를 주고받을 때 해당 data가 form형식이므로, HTTP 메시지의 Content Type는 application/x-www-form-unreloaded이고, username=kim...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.