如何在骆驼JMS路线中设置事务

如何在骆驼JMS路线中设置事务

问题描述:

在发生异常时,如何在JMS路由中设置事务以回滚或不消耗消息.下面是我的路线. MQ是ActiveMQ.

How do I setup transaction in JMS route to rollback or not consume a message when an exception occurs. Below is my route. MQ is ActiveMQ.

from("jms:queue:myQueue")
        .routeId("myRoute")
        .doTry()
            .toF("reactive-streams:myStream")
        .doCatch(Exception.class)
            .process(exchange -> exchange.getFromEndpoint().stop())
        .end();`

只需添加事务处理即可!另外,必须启用连接池和camel-jms-starter(用于默认工厂).

Simply adding transacted did the job! Also, had to enable connection pooling and camel-jms-starter (for default factories).

from("jms:queue:myQueue?transacted=true")
        .routeId("myRoute")
        .doTry()
            .toF("reactive-streams:myStream")
        .doCatch(Exception.class)
            .process(exchange -> exchange.getFromEndpoint().stop())
        .end();