8.3. 关于 pax-transx 项目
pax-transx
项目为 OSGi 中的 JTA/JTS 事务管理提供支持,以及 JDBC 和 JMS 资源池。它关闭 pax-jdbc
和 pax-jms
间的差距。
-
pax-jdbc
添加了javax.sql.(XA)ConnectionFactory
服务的配置选项和发现,并附带一些 JDBC 池实施 -
pax-jms
执行与javax.jms.(XA)ConnectionFactory
服务相同的功能,并随附一些 JMS 池实施 -
pax-transx
添加了javax.transaction.TransactionManager
实施的配置选项和发现,并通过池ing 和 tranasction 支持提供基于 JCA 的 JDBC/JMS 连接管理。
关于 JDBC 连接池 和 JMS 连接池 的部分仍然有效。在注册 JDBC 数据源和 JMS 连接因素时,需要更改使用基于 JCA 的池的唯一更改是使用 pool=transx
属性。
-
pax-jdbc-pool-transx
使用org.ops4j.pax.transx.jdbc.ManagedDataSourceBuilder
frompax-transx-jdbc
-
pax-jms-pool-transx
使用org.ops4j.pax.transx.jms.ManagedConnectionFactoryBuilder
frompax-transx-jms
虽然池数据源/连接工厂以 构建器风格 (无 Java™ bean 属性)创建,但 JDBC 支持这些属性:
-
name
-
userName
-
password
-
commitBeforeAutocommit
-
preparedStatementCacheSize
-
transactionIsolationLevel
-
minIdle
-
maxPoolSize
-
aliveBypassWindow
-
houseKeepingPeriod
-
connectionTimeout
-
idleTimeout
-
maxLifetime
JMS 支持这些属性:
-
name
-
userName
-
password
-
clientID
-
minIdle
-
maxPoolSize
-
aliveBypassWindow
-
houseKeepingPeriod
-
connectionTimeout
-
idleTimeout
-
maxLifetime
XA 恢复工作需要 用户名和密码
属性(就像使用 Fuse 6. xa.
password 中的 ries.xa.password
属性相同)。
在 Blueprint 中使用此 JDBC 配置(mind pool=transx
):
<!-- Database-specific, non-pooling, non-enlisting javax.sql.XADataSource --> <bean id="postgresql" class="org.postgresql.xa.PGXADataSource"> <property name="url" value="jdbc:postgresql://localhost:5432/reportdb" /> <property name="user" value="fuse" /> <property name="password" value="fuse" /> <property name="currentSchema" value="report" /> <property name="connectTimeout" value="5" /> </bean> <!-- Expose database-specific data source with service properties No need to expose pooling, enlisting, non database-specific javax.sql.DataSource - it'll be registered automatically by pax-jdbc-config with the same properties as this <service>, but with higher service.ranking --> <service id="pool" ref="postgresql" interface="javax.sql.XADataSource"> <service-properties> <!-- "pool" key is needed for pax-jdbc-config to wrap database-specific data source inside connection pool --> <entry key="pool" value="transx" /> <!-- <service>/@id attribute doesn't propagate, but name of the datasource is required using one of: --> <entry key="osgi.jndi.service.name" value="jdbc/postgresql" /> <!-- or: --> <!--<entry key="dataSourceName" value="jdbc/postgresql" />--> <!-- Other properties, that normally are needed by e.g., pax-jdbc-pool-transx --> <entry key="pool.maxPoolSize" value="13" /> <entry key="pool.userName" value="fuse" /> <entry key="pool.password" value="fuse" /> </service-properties> </service>
并使用此 JMS 配置在 Blueprint 中(mind pool=transx
):
<!-- Broker-specific, non-pooling, non-enlisting javax.jms.XAConnectionFactory --> <bean id="artemis" class="org.apache.activemq.artemis.jms.client.ActiveMQXAConnectionFactory"> <argument index="0" value="tcp://localhost:61616" /> <!-- credentials needed for JCA-based XA-recovery --> <argument index="1" value="admin" /> <argument index="2" value="admin" /> <property name="callTimeout" value="2000" /> <property name="initialConnectAttempts" value="3" /> </bean> <!-- Expose broker-specific connection factory with service properties No need to expose pooling, enlisting, non broker-specific javax.jms.XAConnectionFactory - it'll be registered automatically by pax-jms-config with the same properties as this <service>, but with higher service.ranking --> <service id="pool" ref="artemis" interface="javax.jms.XAConnectionFactory"> <service-properties> <!-- "pool" key is needed for pax-jms-config to wrap broker-specific connection factory inside connection pool --> <entry key="pool" value="transx" /> <!-- <service>/@id attribute doesn't propagate, but name of the connection factory is required using one of: --> <entry key="osgi.jndi.service.name" value="jms/artemis" /> <!-- or: --> <!--<entry key="name" value="jms/artemis" />--> <!-- Other properties, that normally are needed e.g., pax-jms-pool-transx --> <entry key="pool.maxPoolSize" value="13" /> <entry key="pool.userName" value="admin" /> <entry key="pool.password" value="admin" /> </service-properties> </service>
您有一个 JDBC 数据源和 JMS 连接工厂注册,该注册了使用基于 JCA 的资源管理。基于 transx 的池将正确与 pax-transx-tm-narayana
整合到了 XA 恢复。
需要的功能有:
-
pax-jdbc-pool-tranx
-
pax-jms-pool-tranx
-
pax-transx-jdbc
-
pax-transx-jms
-
pax-jms-artemis
(在使用 A-MQ 7 时)