我想在同一事务中的数据库表和JMS队列中插入记录。目前我正在使用Transaction scope来实现这一目标。
<transactional action="ALWAYS_BEGIN" doc:name="Transactional">
<db:insert config-ref="MySQL_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[INSERT INTO CUSTOMER(NAME, AGE) VALUES(#[payload.name],#[payload.age])]]></db:parameterized-query>
</db:insert>
<jms:outbound-endpoint queue="${queue.name}" connector-ref="Active_MQ" doc:name="JMS">
<jms:transaction action="ALWAYS_JOIN"/>
</jms:outbound-endpoint>
</transactional>
但是我得到了以下错误:
org.mule.api.transaction.TransactionException: Endpoint is transactional but transaction does not support it
现在我使用了XA-Transaction
<jms:activemq-xa-connector name="Active_MQ_XA" specification="1.1" brokerURL="${activemq.broker.url}" validateConnections="true" doc:name="Active MQ" />
<db:mysql-config name="MySQL_XA_Configuration" host="${db.host}" port="${db.port}" user="${db.user}" password="${db.password}" database="${db.name}" useXaTransactions="true" doc:name="MySQL Configuration" />
<jbossts:transaction-manager doc:name="JBoss Transaction Manager" />
<ee:xa-transactional action="ALWAYS_BEGIN" doc:name="Transactional">
<db:insert config-ref="MySQL_XA_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[INSERT INTO CUSTOMER(NAME, AGE) VALUES(#[payload.name],#[payload.age])]]></db:parameterized-query>
</db:insert>
<jms:outbound-endpoint queue="${queue.name}" connector-ref="Active_MQ_XA" doc:name="JMS">
<xa-transaction action="ALWAYS_JOIN"/>
</jms:outbound-endpoint>
</ee:xa-transactional>
这次我又得到了一个例外
java.lang.UnsupportedOperationException
at org.enhydra.jdbc.standard.StandardXAConnectionHandle.prepareStatement(StandardXAConnectionHandle.java:380)
at org.mule.module.db.internal.domain.xa.ConnectionWrapper.prepareStatement(ConnectionWrapper.java:312)
at org.mule.module.db.internal.domain.connection.DefaultDbConnection.prepareStatement(DefaultDbConnection.java:250)
at org.mule.module.db.internal.domain.autogeneratedkey.ColumnIndexAutoGeneratedKeyStrategy.prepareStatement(ColumnIndexAutoGeneratedKeyStrategy.java:36)
at org.mule.module.db.internal.domain.statement.QueryStatementFactory.create(QueryStatementFactory.java:59)
at org.mule.module.db.internal.domain.executor.AbstractSingleQueryExecutor.execute(AbstractSingleQueryExecutor.java:44)
at org.mule.module.db.internal.processor.UpdateMessageProcessor.doExecuteQuery(UpdateMessageProcessor.java:59)
at org.mule.module.db.internal.processor.AbstractSingleQueryDbMessageProcessor.executeQuery(AbstractSingleQueryDbMessageProcessor.java:42)
at org.mule.module.db.internal.processor.AbstractDbMessageProcessor.process(AbstractDbMessageProcessor.java:66)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:107)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.processor.BlockingProcessorExecutor.executeNext(BlockingProcessorExecutor.java:94)
at org.mule.processor.BlockingProcessorExecutor.execute(BlockingProcessorExecutor.java:56)
at org.mule.processor.TransactionalInterceptingMessageProcessor$1.process(TransactionalInterceptingMessageProcessor.java:49)
at org.mule.processor.TransactionalInterceptingMessageProcessor$1.process(TransactionalInterceptingMessageProcessor.java:46)
at org.mule.execution.ExecuteCallbackInterceptor.execute(ExecuteCallbackInterceptor.java:16)
at org.mule.execution.CommitTransactionInterceptor.execute(CommitTransactionInterceptor.java:35)
at org.mule.execution.CommitTransactionInterceptor.execute(CommitTransactionInterceptor.java:22)
at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:30)
at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:14)
at org.mule.execution.BeginAndResolveTransactionInterceptor.execute(BeginAndResolveTransactionInterceptor.java:67)
at org.mule.execution.ResolvePreviousTransactionInterceptor.execute(ResolvePreviousTransactionInterceptor.java:44)
at org.mule.execution.SuspendXaTransactionInterceptor.execute(SuspendXaTransactionInterceptor.java:50)
at org.mule.execution.ValidateTransactionalStateInterceptor.execute(ValidateTransactionalStateInterceptor.java:40)
at org.mule.execution.IsolateCurrentTransactionInterceptor.execute(IsolateCurrentTransactionInterceptor.java:41)
at org.mule.execution.ExternalTransactionInterceptor.execute(ExternalTransactionInterceptor.java:48)
at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:28)
at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:13)
at org.mule.execution.TransactionalErrorHandlingExecutionTemplate.execute(TransactionalErrorHandlingExecutionTemplate.java:110)
at org.mule.execution.TransactionalErrorHandlingExecutionTemplate.execute(TransactionalErrorHandlingExecutionTemplate.java:30)
at org.mule.processor.TransactionalInterceptingMessageProcessor.process(TransactionalInterceptingMessageProcessor.java:55)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:107)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.processor.BlockingProcessorExecutor.executeNext(BlockingProcessorExecutor.java:85)
at org.mule.processor.BlockingProcessorExecutor.execute(BlockingProcessorExecutor.java:56)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:107)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:107)
at org.mule.execution.MessageProcessorExecut...
有人可以解决这个问题吗?
答案 0 :(得分:0)
似乎useXaTransactions="true"
无法处理mysql数据库连接器。我已配置显式mySqlXADataSource
。它对我有用。
<jbossts:transaction-manager doc:name="JBoss Transaction Manager" />
<spring:beans>
<spring:bean id="mySqlXADataSource" name="MySqlXADataSource" class="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource">
<spring:property name="user" value="${db.user}" />
<spring:property name="password" value="${db.password}" />
<spring:property name="url" value="${mysql.driver.url}" />
</spring:bean>
</spring:beans>
<db:mysql-config name="MySQL_XA_Configuration" dataSource-ref="mySqlXADataSource" doc:name="MySQL Configuration" />
<jms:activemq-xa-connector name="Active_MQ_XA" specification="1.1" brokerURL="${activemq.broker.url}" validateConnections="true" doc:name="Active MQ" />
<ee:xa-transactional action="ALWAYS_BEGIN" doc:name="Transactional">
<db:insert config-ref="MySQL_XA_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[INSERT INTO CUSTOMER (NAME,AGE)VALUES(#[payload.customer.name],#[payload.customer.age])]]></db:parameterized-query>
</db:insert>
<jms:outbound-endpoint queue="${queue.name}" connector-ref="Active_MQ_XA" doc:name="JMS">
<xa-transaction action="ALWAYS_JOIN"/>
</jms:outbound-endpoint>
</ee:xa-transactional>