【问题标题】:Apache camel onCompletion call back doesn't trigger after route is completed路由完成后,Apache camel onCompletion 回调不会触发
【发布时间】:2018-12-07 08:10:06
【问题描述】:

我在骆驼中有以下路线设置。我在这里发布了完整的代码。 调用 ProcessorTwo 后,我希望调用 ProcessorOnComplete,但它根本没有被触发。我在这里缺少什么?

public class CamelRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        from("disruptor:routingChannel?concurrentConsumers=10")
            .onCompletion()
            .process(new ProcessorOnComplete())
            .end()
            .to("disruptor:processingOne?concurrentConsumers=10")
            .process(new ProcessorOne())
            .to("disruptor:processingTwo?concurrentConsumers=10")
            .process(new ProcessorTwo())
            .stop();
    }
}

public class ProcessorOne implements Processor {
    @Override
    public void process(Exchange exchange) throws Exception {
        System.out.println("Procesing one");
    }
}

public class ProcessorTwo implements Processor {
    @Override
    public void process(Exchange exchange) throws Exception {
        System.out.println("Procesing two");
    }
}

public class ProcessorOnComplete implements Processor {
    @Override
    public void process(Exchange exchange) throws Exception {
        System.out.println("Completion Mayuran");
    }
}

public class Main {
    public static void main(String[] args) throws Exception {
        CamelContext camelContext = new DefaultCamelContext();
        camelContext.addRoutes(new CamelRoute());
        camelContext.start();
        
        ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
        
        producerTemplate.sendBody("disruptor:routingChannel", "Message");
        
        Thread.sleep(1000*1000);
    }
}

【问题讨论】:

  • 您尝试过不使用stop() EIP 吗?这将停止当前消息的处理,因此可能会阻止 onCompletion 启动。此时停止 EIP 无论如何都没有用
  • 是的,我已经尝试了很多试错方案,我无法理解调用 onCompletion 的情况。

标签: java apache-camel disruptor-pattern


【解决方案1】:

onCompletion() 在我测试时运行,前提是我有发送到中断队列的消息的消费者。

如果 Exchange 是 InOnly 并且您没有任何东西消耗发送到 disruptor:processingOnedisruptor:processingTwo 的消息,您将看到您描述的行为

onCompletion 正在等待处理中断队列中的消息。

处理器ProcessorOne()ProcessorTwo() 被调用,因为camel 不等待响应,因为交换是InOnly。

如果 Exchange 是 InOut,那么路由将等待来自第一个破坏者的响应,并且可能会在 30 秒后超时。因此您不会看到来自处理器的消息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-29
    • 2016-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多