如何解决如何处理InfegrationFlows上的异常?
我通过Spring Cloud DataFlow连接了此流程。一个微服务从队列中获取电子邮件,然后发送到另一个应该发送电子邮件的微服务。
我希望能够捕获失败的电子邮件,并在.transform()和异常消息之前保留原始消息。
如何做到?
@Bean
public IntegrationFlow sendMailFlow() {
return IntegrationFlows.from(Sink.INPUT)
.transform(Transformers.converter(converter))
.handle(Mail.outboundAdapter(EmailSinkApplication.this.props.getServer())
.port(EmailSinkApplication.this.props.getPort())
.credentials(EmailSinkApplication.this.props.getUser(),EmailSinkApplication.this.props.getPass())
.protocol(EmailSinkApplication.this.props.getProto())
.javaMailProperties(p -> {
p.put("mail.smtp.starttls.enable","true");
p.put("mail.smtp.auth","true");
}),e -> e.id("sendMailEndpoint"))
.get();
}
解决方法
我建议您实现ChannelInterceptor
并将逻辑添加到afterSendCompletion()
中。在该拦截器bean上使用@GlobalChannelInterceptor
,将patterns
指定为Sink.INPUT
。因此,您将在该try..catch
频道的整个流程中得到一个Sink.INPUT
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。