大佬教程收集整理的这篇文章主要介绍了如何将 Spring Boot HealthIndicator 添加到 Imap 接收器 IntegrationFlow,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
如何将 Spring Boot Healthindicator 与带有 imap 的 IntegrationFlow 轮询电子邮件集成?
我可以通过 errorChannel 从 IntegrationFlow 获取异常,但是一旦 IntegrationFlow 再次开始工作,例如在网络中断后,我该如何“清除”异常。
@SpringBootApplication
public class MyApplication {
@Bean
IntegrationFlow mailFlow() {
return IntegrationFlows
.from(Mail.imAPInboundAdapter(receiver()).get(),e -> e.autoStartup(true)
.poller(Pollers.fixedrate(5000)))
.channel(mailChannel()).get();
}
@Bean
public ImapMailReceiver receiver() {
String mailServerPath = format("imaps://%s:%s@%s/INBox",mailUser,encode(mailPassword),mailServer);
ImapMailReceiver result = new ImapMailReceiver(mailServerPath);
return result;
}
@Bean
DirectChannel mailChannel() {
return new DirectChannel();
}
@autowired
@QualifIEr("errorChannel")
private PublishSubscribeChannel errorChannel;
@Bean
public IntegrationFlow errorHandlingFlow() {
return IntegrationFlows.from(errorChannel).handle(message -> {
MessagingException ex = (MessagingException) message.getPayload();
log.error("",ex);
}).get();
}
@Bean
Healthindicator mailReceiverHealthindicator() {
return () -> {
/*
* How to error check the imap polling ???
*/
return Health.up().build();
};
}
}
我会使用 AtomicReference<Exception>
bean 并在该 errorHandlingFlow
中设置它的值。当 HealthIndicator
有值时,AtomicReference
impl 会将 down()
咨询到 PollerSpec
。
可以使用 Mail.imapInboundAdapter()
配置 ReceiveMessageAdvice
的 /**
* Specify AOP {@link Advice}s for the {@code pollingTask}.
* @param advice the {@link Advice}s to use.
* @return the spec.
*/
public PollerSpec advice(Advice... advice) {
:
afterReceive()
它的 AtomicReference
impl 可以将 HealthIndicator
清理干净,因此您的 up()
将返回 afterReceive()
。
关键是只有当 invocation.proceed()
没有因异常而失败时才会调用此 <div class="list-group" id="mod">
<div class="list-group" id="details">
</div>
</div>
<script>//filling the first list-group #mod
$(document).ready(function(){
$.getJSON('http://localhost:8888/php/json-data-modules.php',function(data) {
$.each(data.modules,function(index,module) {
$('#mod').append('<button type=btn'+module.moduleName+'" class="list-group-item list-group-item-action">'+module.moduleName+'</button>');
});
});
});
//filing the second list-group with new details
$(document).ready(function(){
$("this").on("click",function(){
$.each(data.modules,module) {
$('#details').append('"class="list-group-item list-group-item-action">'+module.credits+'');
$('#details').append('" class="list-group-item list-group-item-action">'+module.location+'');
});
});
});
。如果有新消息要处理,它会被独立调用。
以上是大佬教程为你收集整理的如何将 Spring Boot HealthIndicator 添加到 Imap 接收器 IntegrationFlow全部内容,希望文章能够帮你解决如何将 Spring Boot HealthIndicator 添加到 Imap 接收器 IntegrationFlow所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。