Reputation: 3344
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?
Upvotes: 2
Views: 8371
Reputation: 121337
Since you really don't have there a flow
you can just end up with the:
@ServiceActivator(inputChannel = "loggerChannel")
public MessageHandler loggerHandler() {
LoggingHandler loggingHandler = new LoggingHandler(INFO.name());
...
return loggingHandler;
}
No reason to declare a "verbose" IntegrationFlow
if there is only the simple handle
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
:
@Bean
public PublishSubscribeChannel outputChannel() {
return MessageChannels.publishSubscribe()
.interceptor(new WireTap(loggerChannel()))
.get();
}
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:
@Bean
public IntegrationFlow wireTapFlow5() {
return f -> f
.wireTap(sf -> sf
.<String, String>transform(String::toUpperCase)
.channel(c -> c.queue("wireTapSubflowResult")))
.channel("nullChannel");
}
As you see we don't have any extra @Bean
there and even we don't need the extra channel for the WireTap
.
Let me know how more simple would you like to see it!
Upvotes: 3