使用Atomikos来进行分布式事务(XA)开发
结合Spring使用
和Spring集成的时候,不需要JNDI服务器
注意,不支持Spring的事务传播性:PROPAGATION_NESTED
JTA事务管理器配置样例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
<bean id="localLogAdministrator" class="com.atomikos.icatch.admin.imp.LocalLogAdministrator" /> <bean id="userTransactionService" class="com.atomikos.icatch.config.UserTransactionServiceImp" init-method="init" destroy-method="shutdownForce"> <constructor-arg> <!-- 配置Atomikos属性 --> <props> <prop key="com.atomikos.icatch.service">com.atomikos.icatch.standalone.UserTransactionServiceFactory</prop> </props> </constructor-arg> <property name="initialLogAdministrators"> <list> <ref bean="localLogAdministrator" /> </list> </property> </bean> <!-- Atomikos 事务管理器配置 --> <bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close" depends-on="userTransactionService"> <property name="startupTransactionService" value="false" /> <!-- close()时是否强制终止事务 --> <property name="forceShutdown" value="false" /> </bean> <!-- Atomikos UserTransaction配置 --> <bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp" depends-on="userTransactionService"> <property name="transactionTimeout" value="300" /> </bean> <!-- JTA事务管理器 --> <bean id="jtaTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager" depends-on="userTransactionService"> <property name="transactionManager" ref="atomikosTransactionManager" /> <property name="userTransaction" ref="atomikosUserTransaction" /> </bean> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<bean id="xaFactory" class="org.apache.activemq.ActiveMQXAConnectionFactory"> <property name="brokerURL" value="tcp://localhost:61616" /> </bean> <bean id="jmsFactory" class="com.atomikos.jms.AtomikosConnectionFactoryBean" init-method="init" destroy-method="close"> <property name="uniqueResourceName" value="amq" /> <property name="xaConnectionFactory" ref="xaFactory" /> </bean> <bean id="tipsMessageListener" class="cc.gmem.demo.TipsMessageListener" /> <!-- 接收消息 --> <jms:listener-container container-type="default" connection-factory="jmsFactory" transaction-manager="jtaTransactionManager" session-transacted="true"> <jms:listener destination="TIPS.10000.BATCH" ref="tipsMessageListener" method="onMessage" /> </jms:listener-container> <!-- 发送消息 --> <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"> <property name="connectionFactory"> <ref bean="jmsFactory" /> </property> <property name="receiveTimeout" value="1000" /> <property name="sessionTransacted" value="true" /> </bean> |
不使用Spring,单独和Hibernate集成
Hibe… 阅读全文
12 years ago
0