2016-01-13 112 views
0

回滚事务不起作用。Apache Camel和Apache ActiveMQ中的XA事务

我试图设置在豆ActiveMQComponent参数:

  • cacheLevelName =>CACHE_CONSUMER
  • transacted =>true

如何解决这个错误?

登录:

[ad #8 - JmsConsumer[Caosqueue]] TransactionErrorHandler  WARN Transaction rollback (0x67756120) redelivered(false) for (MessageId: ID:stws2327-61437-1452674698638-1:3:1:1:1 on ExchangeId: ID-stws2327-61436-1452674698403-0-3) due exchange was marked for rollbackOnly 
[ad #8 - JmsConsumer[Caosqueue]] EndpointMessageListener  WARN Execution of JMS message listener failed. Caused by:  [org.apache.camel.RuntimeCamelException - org.apache.camel.RollbackExchangeException: Intended rollback. Exchange[Message: two]] 

路线:

<!-- Next route--> 
<route autoStartup="true" errorHandlerRef="myErrorHandler" id="OperDayRoute"> 
    <from uri="jms:Caosqueue?transacted=true" /> 
    <transacted ref="PROPAGATION_REQUIRED" /> 
    <setHeader headerName="body"> 
    <simple>${body}</simple> 
    </setHeader> 
    <to uri="sql:{{sql.insertBody}}"/> 
    <convertBodyTo type="java.lang.String" /> 
    <choice> 
    <when> 
     <simple>${headers.CamelSqlUpdateCount} != 1</simple> 
     <log message="PROCESSING RESULT IS ${body} - OK" /> 
    </when> 
    <otherwise> 
     <log message="PROCESSING RESULT IS ${body} - NO OK!" /> 
     <camel:rollback markRollbackOnly="true" /> 
     <throwException ref="IllegalRez" /> 
    </otherwise> 
    </choice> 
</route> 

回答

0

这是没有问题的。 Camel默认报告日志级别为WARN的日志中的回滚。如果您愿意,您可以将其更改为DEBUG

在Spring XML:

<bean id="transactionErrorHandler" class="org.apache.camel.spring.spi.TransactionErrorHandlerBuilder"> 
    <property name="rollbackLoggingLevel" value="DEBUG"/> 
    <property name="transactionTemplate" ref="PROPAGATION_REQUIRED"/> 
</bean> 

<!-- the standard spring transaction template for required --> 
<bean id="PROPAGATION_REQUIRED" class="org.springframework.transaction.support.TransactionTemplate"> 
    <property name="transactionManager" ref="jmsTransactionManager"/> 
</bean> 

应自动骆驼回升。如果没有,您可以通过route元素的errorHandlerRef属性在您的路线中明确设置它。

+0

https://github.com/Dugayoyo/camel/blob/master/context - 完整的上下文。并记录当我运行这个 - https://github.com/Dugayoyo/camel/blob/master/log –

+0

如果你正在使用XA事务,那么你应该禁用本地JMS事务在骆驼端点(即transacted = false),因为它将是启动XA事务的XA连接工厂本身。此外,您在配置中缺少XA资源管理器:https://access.redhat.com/documentation/en-US/Red_Hat_JBoss_Fuse/6.0/html/EIP_Transaction_Guide/files/XaJms-Sample.html。 – raulk