I've added WireTap
configuration to my Spring Integration Java DSL.
I reviewed discussion What is the equivalent of logging-channel-adapter in java DSL and now my main Java Config file looks like
@Configuration
@Import(LoggerConfiguration.class)
@EnableIntegration
public class ProcessorConfiguration {
@Autowired
private WireTap wireTap;
@Bean
public QueueChannel inputChannel() {
return MessageChannels.queue(500)
.interceptor(wireTap)
.get();
}
@Bean
public PublishSubscribeChannel outputChannel() {
return MessageChannels.publishSubscribe()
.interceptor(wireTap)
.get();
}
...
}
And LoggerConfiguration
is
@Configuration
public class LoggerConfiguration {
public static final LoggingHandler.Level INFO = LoggingHandler.Level.INFO;
@Bean
public WireTap wireTap() {
return new WireTap(loggerChannel());
}
@Bean
public IntegrationFlow loggerChain() {
return IntegrationFlows.from(loggerChannel())
.handle(loggerHandler())
.get();
}
@Bean
public MessageChannel loggerChannel() {
return MessageChannels.direct().get();
}
public MessageHandler loggerHandler() {
LoggingHandler loggingHandler = new LoggingHandler(INFO.name());
...
return loggingHandler;
}
}
All of thes tones(!) of code ONLY to reach what I had in XML configuration in these simple lines
<int:channel id="inputChannel">
<int:queue capacity="500"/>
<int:interceptors>
<int:wire-tap channel="logger"/>
</int:interceptors>
</int:channel>
<int:publish-subscribe-channel id="outputChannel">
<int:interceptors>
<int:wire-tap channel="logger"/>
</int:interceptors>
</int:publish-subscribe-channel>
<int:logging-channel-adapter id="logger" log-full-message="true" level="INFO"/>
How can I configure wireTaps in Java DSL less verbose and simple?
Since you really don't have there a
flow
you can just end up with the:No reason to declare a "verbose"
IntegrationFlow
if there is only the simplehandle
logic.The Java DSL really can be combined with the raw Java & Annotation configuration and even the XML configs can live there as well.
WireTap
may not be declared as a@Bean
:The XML definition declares bean for the
<int:wire-tap>
via a Parser logic.With Java configuration we don't have so much choice, unless
@Bean
for the target class if we would like to have it as a bean.From other side the Java DSL has
.wireTap()
EIP-method. So, you don't need to declare all those beans. E.g. from our test-cases:As you see we don't have any extra
@Bean
there and even we don't need the extra channel for theWireTap
.Let me know how more simple would you like to see it!