首页 > Java技术 > 采用atomikos实现分布式事务管理
201302月1

采用atomikos实现分布式事务管理

起因

       最近做一个电子商务平台,里面总共包含四个系统,分别是B2B2C商城、门户、论坛、sso系统,业务中涉及到需要将sso中的用户与各业务系统进行同步,需要考虑到分布式事务管理,在网上找了很多相关的资料,最终依然决定采用atomikos的jta事务管理,将具体的配置和大家分享下

数据源配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
	<!--配置三个数据源  分别是sso服务器、  商城、discuz论坛 begin-->
	<bean id="dataSourceSSO" class="com.atomikos.jdbc.AtomikosDataSourceBean"
		init-method="init" destroy-method="close">
		<property name="uniqueResourceName">
			<value>mysql/sso</value>
		</property>
		<property name="xaDataSourceClassName">
			<!--
				使用Mysql XADataSource(mysql>=5.0, Connector/J>=5.0才可以支持XADatasource)
			-->
			<value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value>
		</property>
		<property name="xaProperties">
			<props>
				<prop key="user">root</prop>
				<prop key="password">rootadmin</prop>
				<prop key="URL">jdbc:mysql://localhost:3306/sso?useUnicode=true&amp;characterEncoding=utf-8</prop>
				<prop key="pinGlobalTxToPhysicalConnection">true</prop>
				<prop key="autoReconnect">true</prop>
			</props>
		</property>
		<property name="poolSize">
			<value>10</value>
		</property>
		<property name="testQuery" value="SELECT 1"/>
	</bean>
	<bean id="dataSourceTshop" class="com.atomikos.jdbc.AtomikosDataSourceBean"
		init-method="init" destroy-method="close">
		<property name="uniqueResourceName">
			<value>mysql/tshop</value>
		</property>
		<property name="xaDataSourceClassName">
			<!--
				使用Mysql XADataSource(mysql>=5.0, Connector/J>=5.0才可以支持XADatasource)
			-->
			<value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value>
		</property>
		<property name="xaProperties">
			<props>
				<prop key="user">root</prop>
				<prop key="password">rootadmin</prop>
				<prop key="URL">jdbc:mysql://localhost:3306/shop?useUnicode=true&amp;characterEncoding=utf-8</prop>
				<prop key="pinGlobalTxToPhysicalConnection">true</prop>
				<prop key="autoReconnect">true</prop>
			</props>
		</property>
		<property name="poolSize">
			<value>10</value>
		</property>
		<property name="testQuery" value="SELECT 1"/>
	</bean>

	<bean id="dataSourceDiscuz" class="com.atomikos.jdbc.AtomikosDataSourceBean"
		init-method="init" destroy-method="close">
		<property name="uniqueResourceName">
			<value>mysql/Discuz</value>
		</property>
		<property name="xaDataSourceClassName">
			<value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value>
		</property>
		<property name="xaProperties">
			<props>
				<prop key="user">root</prop>
				<prop key="password">root</prop>
				<prop key="URL">jdbc:mysql://localhost:3306/ultrax2?useUnicode=true&amp;characterEncoding=utf-8</prop>
				<prop key="pinGlobalTxToPhysicalConnection">true</prop>
				<prop key="autoReconnect">true</prop>
			</props>
		</property>
		<property name="poolSize">
			<value>10</value>
		</property>
		<property name="testQuery" value="SELECT 1"/>
	</bean>
</beans>

文章作者: iitshare
本文地址:http://www.iitshare.com/atomikos-distributed-transaction.html
版权所有 © 转载时必须以链接形式注明作者和原始出处!

更多
本文目前尚无任何评论.

发表评论