如果出现错误,我们需要延迟重试骆驼SFTP Producer一定次数。通过使用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();
如果你想控制每个Exception的行为,你可以这样做:
onException(MyRetryableServiceException.class)
.useOriginalMessage()
.redeliveryDelay(1000)
.backOffMultiplier(1.5)
.maximumRedeliveries(3)
.retryAttemptedLogLevel(LoggingLevel.WARN)
.useExponentialBackOff();
当抛出MyRetryableServiceException
时,消息将按照maximumRedeliveries
重新传递。您可以在单个例外中定义多个onException
或包装您想要重试的那些...
这优先于默认错误处理程序,请参阅exception-clause和camel error handling
其他所有内容都将进入处理的默认错误,该错误将重试所有类型的异常(之前的camel 2.x,没有从版本> = 2.0重试)。除非你覆盖它。
因此,一种可能的解决方案是定义OnException
以跳过重试验证错误,如果使用camel <2.0,则保留默认错误处理程序以重试其他错误处理程序
您可以使用noErrorHandler();
禁用默认错误处理程序或自定义它,例如:
errorHandler(
deadLetterChannel("seda:errors")
.logNewException(true)
.log("Unable to process ${body}")
.maximumRedeliveries(1)
.retryAttemptedLogLevel(LoggingLevel.WARN)
.useExponentialBackOff()
);