在activemq端点上设置事务集的异常

时间:2015-12-04 04:24:13

标签: apache-camel activemq

我想了解为什么在"交易时会出现以下异常"在路线上设置。

 errorHandler(deadLetterChannel("activemq:EXCEPTION")
                .useOriginalMessage()
                .maximumRedeliveries(1));

 from("activemq:TRIGGER").routeId("Trigger")
                .transacted()
                .bean("helloService")
                .to("log:out");

我希望将任何被抛出的异常发送到EXCEPTION队列。我的理解是"交易"需要设置为使路由成为事务。当我删除配置时,我不会得到以下例外。

当Hello类的字符串设置为大于5个字符时,会创建异常。

示例代码: https://github.com/zachariahyoung/docker-camel

2015-12-03 21:59:26.706  WARN 9900 --- [nsumer[TRIGGER]] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 22001, SQLState: 22001
2015-12-03 21:59:26.706 ERROR 9900 --- [nsumer[TRIGGER]] o.h.engine.jdbc.spi.SqlExceptionHelper   : Value too long for column "TEXT VARCHAR(5)": "'sdsfasdfasdf' (12)"; SQL statement:
insert into hello (id, text) values (null, ?) [22001-190]
2015-12-03 21:59:26.707  WARN 9900 --- [nsumer[TRIGGER]] o.a.c.s.spi.TransactionErrorHandler      : Transaction rollback (0x7e2bd5e6) redelivered(true) for (MessageId: ID:CHARLA-49686-1449193952655-71:1:1:1:1 on ExchangeId: ID-CHARLA-63325-1449200820961-0-37) caught: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly
2015-12-03 21:59:26.708  WARN 9900 --- [nsumer[TRIGGER]] o.a.c.c.jms.EndpointMessageListener      : Execution of JMS message listener failed. Caused by: [org.apache.camel.RuntimeCamelException - org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly]

org.apache.camel.RuntimeCamelException: org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly
    at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1642) ~[camel-core-2.16.0.jar:2.16.0]
    at org.apache.camel.component.jms.EndpointMessageListener$EndpointMessageListenerAsyncCallback.done(EndpointMessageListener.java:186) ~[camel-jms-2.15.3.jar:2.15.3]
    at org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:107) ~[camel-jms-2.15.3.jar:2.15.3]
    at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:746) ~[spring-jms-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:684) ~[spring-jms-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:651) ~[spring-jms-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:315) [spring-jms-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:233) [spring-jms-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1150) [spring-jms-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1142) [spring-jms-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:1039) [spring-jms-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_45]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_45]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_45]
Caused by: org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly
    at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:526) ~[spring-orm-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:761) ~[spring-tx-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730) ~[spring-tx-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:150) ~[spring-tx-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.apache.camel.spring.spi.TransactionErrorHandler.doInTransactionTemplate(TransactionErrorHandler.java:174) ~[camel-spring-2.16.0.jar:2.16.0]
    at org.apache.camel.spring.spi.TransactionErrorHandler.processInTransaction(TransactionErrorHandler.java:134) ~[camel-spring-2.16.0.jar:2.16.0]
    at org.apache.camel.spring.spi.TransactionErrorHandler.process(TransactionErrorHandler.java:103) ~[camel-spring-2.16.0.jar:2.16.0]
    at org.apache.camel.spring.spi.TransactionErrorHandler.process(TransactionErrorHandler.java:112) ~[camel-spring-2.16.0.jar:2.16.0]
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190) ~[camel-core-2.16.0.jar:2.16.0]
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190) ~[camel-core-2.16.0.jar:2.16.0]
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:109) ~[camel-core-2.16.0.jar:2.16.0]
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:87) ~[camel-core-2.16.0.jar:2.16.0]
    at org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:103) ~[camel-jms-2.15.3.jar:2.15.3]
    ... 11 common frames omitted
Caused by: javax.persistence.RollbackException: Transaction marked as rollbackOnly
    at org.hibernate.jpa.internal.TransactionImpl.commit(TransactionImpl.java:74) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
    at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:517) ~[spring-orm-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    ... 23 common frames omitted

1 个答案:

答案 0 :(得分:0)

抛出异常因为camel正在传播回滚。如果你从另一个路线呼叫这条路线,骆驼也会回滚那条路线。您必须捕获标记路由的异常作为回滚并且告诉camel仅将此路由标记为回滚。在var data = Object.keys(this.props.item).map(function (prop) { if (prop === 'name') { return; } return ( <li>{prop}<p>{this.props.item[prop]}</p></li> ); }); return <div>{data}</div>; 之前添加:

.transacted()