Apache骆驼:检测是否是链中的最后一条路线

发布于 2025-02-06 12:32:00 字数 914 浏览 1 评论 0原文

我有以下情况。我正在使用链式路线key_123-> key_345-> key_678。闭塞方法 每条路线都被称为。在审查中,是否有可能检测它是否是链中的最后一条路线?因为我想要 仅在链条末端(在这种情况下为key_678路线)而不是在每条路线之后删除相关性_id。

代码:

    from("quartz://key_123?cron=0+0/10+*+*+*+?+*")
        .
        .
        .
    .to("activemq:topic:key_345");
    

    from("activemq:topic:key_345")
        .
        .
        .
    .to("direct:key_678");
    
    
    onCompletion().onCompleteOnly()
    .process(new Processor() {
        @Override
        public void process(Exchange exchange) throws Exception {
            CamelContext context = exchange.getContext();
            Boolean isRunAllowed = context.isRunAllowed();
            ServiceStatus status = context.getStatus();
            //TODO: Check if it is the last route in the chain.
            MDC.remove("correlation_id");
        }
    });

是否可以检测Apache Camel中链中的第一个也是最后一条路线?

I have the following scenario. I am working with chained routes key_123 --> key_345 --> key_678. The onCompletion method
is being called after every route. Is it possible in onCompletion to detect if it is the last route in the chain? Since I want
to remove the correlation_id just at the end of the chain (in this case key_678 route) and not after every route.

Code:

    from("quartz://key_123?cron=0+0/10+*+*+*+?+*")
        .
        .
        .
    .to("activemq:topic:key_345");
    

    from("activemq:topic:key_345")
        .
        .
        .
    .to("direct:key_678");
    
    
    onCompletion().onCompleteOnly()
    .process(new Processor() {
        @Override
        public void process(Exchange exchange) throws Exception {
            CamelContext context = exchange.getContext();
            Boolean isRunAllowed = context.isRunAllowed();
            ServiceStatus status = context.getStatus();
            //TODO: Check if it is the last route in the chain.
            MDC.remove("correlation_id");
        }
    });

Is it possible to detect the first and last route in the chain in Apache Camel?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文