java - Camel SFTP Producer 重试特定类型的错误
问题描述
如果出现错误,我们需要对骆驼 SFTP 生产者延迟重试一定次数。通过使用 maximumReconnectAttempts 和 reconnectDelay,camel 尝试重试所有类型的错误,但只想重试某些类型的错误,如 socketException 或 connectionexception 或 jschExceptions 并避免重试身份验证异常。这是我们为此使用的示例代码。我们如何配置为仅重试某些类型的错误而不是全部?
from("file:///test/dummy/moveFailed=error&antInclude=*.txt&initialDelay=60000").routeId("test")
.log(LoggingLevel.DEBUG, " Message sending to Destination")
.setHeader(Exchange.FILE_NAME, simple("Test${date:now:yyyyMMdd}.CSV"))
.to("sftp://username@host/destinationpassword=password123&reconnectDelay=3000&maximumReconnectAttempts=5")
.log(LoggingLevel.INFO,"event=${in.header.event} || File successfully transmitted to Destination")
.end();
解决方案
如果您想控制每个异常的行为,您可以执行以下操作:
onException(MyRetryableServiceException.class)
.useOriginalMessage()
.redeliveryDelay(1000)
.backOffMultiplier(1.5)
.maximumRedeliveries(3)
.retryAttemptedLogLevel(LoggingLevel.WARN)
.useExponentialBackOff();
当 aMyRetryableServiceException
被抛出时,消息将按照 重新传递maximumRedeliveries
。您可以定义多个onException
或将要重试的那些包装在单个异常中...
其他所有内容都将转到处理的默认错误,该错误将重试所有类型的异常(以前的骆驼 2.x,版本 >= 2.0 不重试)。除非你覆盖它。
因此,一种可能的解决方案是定义OnException
跳过重试身份验证错误,如果您使用的是骆驼 < 2.0,则保留默认错误处理程序以重试其他错误处理程序
您也可以禁用默认错误处理程序noErrorHandler();
或对其进行自定义,例如:
errorHandler(
deadLetterChannel("seda:errors")
.logNewException(true)
.log("Unable to process ${body}")
.maximumRedeliveries(1)
.retryAttemptedLogLevel(LoggingLevel.WARN)
.useExponentialBackOff()
);
推荐阅读
- xcode - QtCreator 问题选项卡为空
- java - 如何在 Spring Boot 应用程序中实现安全性?
- python - 如何将 sklearn 目标转换器(用于输出变量)添加到 keras 神经网络管道?
- javascript - window.opener 的“关闭”属性
- c - malloc 使用什么系统调用?
- python - 是否可以使用 Counter 函数来查看更大列表中列表中元素的出现?
- android-studio - Android Studio 使用 JavaPoet 库显示非常具体的错误错误
- javascript - Electron desktopCapture 没有从单个应用程序中获取音频
- python - 如何解决 Windows 10 上的这个 mod-wsgi 安装错误?
- django - 内联表单工厂在 Django 中 POST 后不加载所有文档