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 实施和(最终)为javax.transaction.TransactionManager实现添加配置选项和发现,提供基于 JCA 的 JDBC/JMS 连接管理,支持池和交易器。
关于 JDBC 连接池 和 JMS 连接池 的部分仍然有效。使用基于 JCA 的池的唯一更改是在注册 JDBC 数据源和 JMS 连接工厂时使用 pool=transx 属性。
-
Pax-jdbc-pool-transx使用org.ops4j.pax.transx.jdbc.ManagedDataSourceBuilderfrompax-transx-jdbc -
Pax-jms-pool-transx使用org.ops4j.pax.transx.jms.ManagedConnectionFactoryBuilderfrompax-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 恢复需要 用户名和密码 属性才能工作(就像使用 aries.xa.username 和 aries.xa.password 属性)在 Fuse 6.x 中。
在蓝图中使用此 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 配置(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 时)