【问题标题】:Can we provide a processor before onFallbackViaNetwork() in camel-hystrix-eip我们可以在camel-hystrix-eip中的onFallbackViaNetwork()之前提供一个处理器吗
【发布时间】:2018-11-06 22:26:35
【问题描述】:

我在我的项目中使用 camel-hystrix-eip,我想要一个处理器在我的回退之前,但它不工作

from("direct:sample").id("id:direct:sample").process(requestProcessor)
                .hystrix()
                .to(endPoint)
                .onFallbackViaNetwork()
                .to(fallback_endPoint)

我想使用处理器更改我的 fallback_endpoint,但似乎在 onFallbackViaNetwork() 之后我们必须立即提供to()。 请建议是否有任何方法。

我尝试了类似下面的方法,但它不起作用。

from("direct:sample").id("id:direct:sample").process(requestProcessor)
                .hystrix()
                .to(endPoint)
                .onFallbackViaNetwork()
                .process(fallbackProcessor)
                .to(fallback_endPoint)

实际上,我正在使用 requestProcessor 来覆盖实际的端点,并且在回退的情况下,fallback_endPoint 也会被覆盖,有什么办法可以避免这种情况。

【问题讨论】:

    标签: apache-camel hystrix


    【解决方案1】:

    onFallbackViaNetwork() 之后可以有处理器。您还可以使用toD EIP 将消息发送到动态端点。

    根据您的代码,您可以设置一个标头MyEndpoint,其中包含您的新端点字符串,然后使用.toD("${header.MyEndpoint}") 引用它。每当您需要设置动态端点时重复此模式。

    例如:

    from("direct:sample")
        .process(new Processor() {
            @Override
            public void process(Exchange exchange) throws Exception {
                // do something
                exchange.getIn().setHeader("EndpointHystrix", "mock:hystrix");
            }
        })
        .hystrix()
            .toD("${header.EndpointHystrix}")
        .onFallbackViaNetwork()
            .process(new Processor() {
                @Override
                public void process(Exchange exchange) throws Exception {
                    // do something more
                    exchange.getIn().setHeader("EndpointFallback", "mock:fallback");
                }
            })
            .toD("${header.EndpointFallback}")
        .end()
        .to("...");
    

    我在 Camel 2.20.0 和 2.21.0 中对此进行了测试。

    【讨论】:

      猜你喜欢
      • 2019-01-07
      • 2019-06-06
      • 2016-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-11
      • 1970-01-01
      相关资源
      最近更新 更多