如何在骆驼中延迟重试 [英] How to retry with delay in Camel

查看:34
本文介绍了如何在骆驼中延迟重试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有兴趣在 Camel 中使用 RedeliveryPolicy 在返回某个异常时重试将消息重新传递到端点.但是我似乎找不到很多如何配置它的示例.

I am interested in using RedeliveryPolicy in Camel to retry redelivery of a message to an endpoint when a certain exception is returned. But I cannot seem to find many examples of how to configure it.

目前我正在尝试:

    from("direct:entry")
            .onException(ResourceNotFoundException.class)
                .redeliveryPolicy(new RedeliveryPolicy().delayPattern("delayPattern=0:" + aocmDelay + ",10:1000;15:2000:19:10000"))
                .handled(true)
            .end()
            .to("direct:destination");

我的目标端点因 ResourceNotFoundException 而失败,但未调用 onException 处理并且重新传递未生效.关于我做错了什么的任何想法?

I have the destination endpoint failing with a ResourceNotFoundException but the onException handling is not being called and the redelivery does not take effect. Any ideas of what I am doing wrong?

推荐答案

您需要设置重新投递策略的单个属性.

You need to set the single properties of a redelivery policy.

from("direct:entry")
    .onException(ResourceNotFoundException.class)
        .maximumRedeliveries(20)
        .delayPattern("1:2000;10:1000;15:2000;19:10000")
        .handled(true)
        .end()
    .to("direct:destination");

补充意见:

  • 您需要定义最大重新投递尝试次数(如果未在其他地方定义),否则使用默认值零
  • 在延迟模式中,您有两个错别字
    delayPattern=0:" + aocmDelay + ",10:1000;15:2000:19:10000
    ________________________________;_______________;________
  • 重新发送计数从 1 开始,如果您定义 0:1000;1:5000,则第一次重新发送延迟 5 秒而不是 1 秒
  • you need to define the maximum redelivery attempts (if not defined elsewhere) otherwise the default of zero is used
  • in the delay pattern you had two typos
    delayPattern=0:" + aocmDelay + ",10:1000;15:2000:19:10000
    ________________________________;_______________;________
  • the redelivery count starts with 1, if you define 0:1000;1:5000 the first redelivery is delayed by five seconds not by one

这篇关于如何在骆驼中延迟重试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆