如何在 Camel JMS Route 中设置事务

如何在 Camel JMS Route 中设置事务

问题描述:

如何在 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();