I'm using Spring Integration to develop my integration scenarios. When I have to write some logs to provide some information, I write this way:
@Bean
IntegrationFlow blacklist(BlacklistService service) {
return m -> m
.wireTap(f -> f.handle(t -> log.info("Adding email source address in blacklist...")))
.<MessageHandlingException, Blacklist>transform(p -> SourceBlacklist.of((Email) p.getFailedMessage().getHeaders().get(IntegrationConstants.MailSender.EMAIL)))
.wireTap(f -> f.handle(t -> log.info("Email source address added to blacklist.")))
.handle(service, "voidSave");
}
I'm using a wiretap with lambda and handle to log my messages. Is there a better way to write log with Spring Integration using Java DSL?
Thanks.
You always can just switch on the logging for the org.springframework.integration
category.
From other side Spring Integration suggests logging in the integration flow as an adapter
- <logging-channel-adapter>
. So, what you need is just send message to the channel of that adapter. From the configuration perspective that looks like:
<wire-tap channel="logging" pattern="*"/>
<logging-channel-adapter id="logging"/>
The same we can configure with Java DSL, but we should rely on the target class - LoggingHandler
:
@ServiceActivator(inputChannel = "logging")
@Bean
public loggingHandler() {
return new LoggingHandler();
}
...
.transform()
.wireTap("logging")
.handle();
Although I can see your point and we really could add something convenient to framework directly.
Feel free to raise a GH issue (https://github.com/spring-projects/spring-integration-java-dsl/issues) on the matter and we continue to discuss the feature there.
But right now your solution doesn't look bad, to be honest.
UPDATE
The request for the Framework on the matter: https://github.com/spring-projects/spring-integration-java-dsl/issues/70
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With