简体   繁体   English

如果在路由中定义了死信通道错误处理程序,Camel 故障转移负载均衡器不会故障转移到下一个目标

[英]Camel Failover Load Balancer not failing over to next target if a Dead Letter Channel Error Handler is defined in the route

I have defined a camel route using a failover load balancer like this:我已经使用这样的故障转移负载平衡器定义了骆驼路由:

from(activemq:foo)
    .errorHandler(deadLetterChannel(activemq:foo.dlq).onPrepareFailure(failureProcessor))
    .process(processor)
    .loadBalance()
        .failover(2, true, true)
            .to(activemq:queue1, activemq:queue2)
    .end();

With the above-defined route, if delivery to queue1 fails, the exception is handled by the error handler and message is put directly into foo.dlq without load balancer failing over to the next target.使用上面定义的路由,如果传递到 queue1 失败,异常由错误处理程序处理,消息直接放入 foo.dlq,负载均衡器不会故障转移到下一个目标。

How do I define a route:如何定义路线:
Which should failover to all the routes and if delivery to all of them fails (fails entirely), it should then send the control to error handler which should put the message to DLQ.哪个应该故障转移到所有路由,如果向所有路由传递失败(完全失败),它应该将控制发送到错误处理程序,错误处理程序应该将消息发送到 DLQ。

I think you should turn inheritErrorHandler (2nd param) to off in your load balancer, ie:我认为您应该在负载均衡器inheritErrorHandler (第二个参数)关闭,即:

.loadBalance()
   .failover(2, false, true)

This way, any failure on one of the two nodes gets propagated to the loadBalancer processor rather than to the DLQ.这样,两个节点之一上的任何故障都会传播到 loadBalancer 处理器而不是 DLQ。

But if the whole loadbalancing process fails (that is: if both nodes fail), the DLQ will be kicked in.但是如果整个负载均衡过程都失败了(即:如果两个节点都失败了),DLQ就会被踢进去。

Hint: if you indent your code, the propagation logic is a bit more clear:提示:如果你缩进你的代码,传播逻辑会更清楚一点:

from("...")
  .errorHandler(...)
  .loadBalance().failover(2, false, true) // level 1
    .to("...") // level 2
    .to("...") // level 2
  .end();

You have two identation levels;您有两个身份级别; each level having its own error handling:每个级别都有自己的错误处理:

  • errors of level 2 are managed by the load balancer级别 2 的错误由负载均衡器管理
  • errors of level 1 are managed by the DLQ 1 级错误由 DLQ 管理

I'm surprised.我很惊讶。 I have just run the following test (in Camel 3.9) - with 2 dummy http endpoints:我刚刚运行了以下测试(在 Camel 3.9 中) - 使用 2 个虚拟 http 端点:

from("timer://demo?period=60s")
    .errorHandler( deadLetterChannel("log:DLQ") )
    .log("Run")
    .loadBalance().failover(2, false, false)
        .to("direct:node1")
        .to("direct:node2")
    .end()
    .log("success");

from("direct:node1")
    .errorHandler( noErrorHandler() )
    .log("Attempt on node#1")
    .to("http://localhost:8881/ws");

from("direct:node2")
    .errorHandler( noErrorHandler() )
    .log("Attempt on node#2")
    .to("http://localhost:8882/ws");

And here is the output:这是 output:

INFO  | route1                         | Camel (Test) thread #0 - t | Run
INFO  | route2                         | Camel (Test) thread #0 - t | Attempt on node#1
INFO  | route3                         | Camel (Test) thread #0 - t | Attempt on node#2
INFO  | DLQ                            | Camel (Test) thread #0 - t | Exchange[ExchangePattern: InOnly, BodyType: null, Body: [Body is null]]

You clearly see that there is one attempt on each node, and the exchange finally goes to the DLQ你清楚的看到每个节点都有一次尝试,最后交换到了DLQ

If i enable inheritErrorHandler, the output is now:如果我启用inheritErrorHandler,output现在是:

INFO  | route1                         | Camel (Test) thread #0 - t | Run
INFO  | route2                         | Camel (Test) thread #0 - t | Attempt on node#1
INFO  | DLQ                            | Camel (Test) thread #0 - t | Exchange[ExchangePattern: InOnly, BodyType: null, Body: [Body is null]]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM