How do you integrate a Spring Boot HealthIndicator with an IntegrationFlow polling email with imap?
I can get exceptions from the IntegrationFlow via the errorChannel but how do I "clear" the exception once the IntegrationFlow starts working again, e.g., after a network outage.
@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();
};
}
}