Reputation: 2288
how can i define a simple bridge that just bridges from one directChannel to another with java annotations
in xml one can do it like this (taken from http://docs.spring.io/spring-integration/reference/html/messaging-channels-section.html)
<int:bridge input-channel="input" output-channel="output"/>
with annotations i would have expected the definition to look like something this
@Bean
@BridgeFrom("inboundChannel")
@BridgeTo("outboundChannel")
public MessageChannel bridge() {
return new DirectChannel();
}
but this gives me the error
IllegalArgumentException: '@BridgeFrom' is eligible only for 'MessageChannel' '@Bean' methods
any suggestions how i would translate the above xml-definition into a java-config-definition?
Upvotes: 1
Views: 2770
Reputation: 174719
It should be
@Bean
@BridgeTo("output")
public MessageChannel input() {
return new DirectChannel();
}
or
@Bean
@BridgeFrom("input")
public MessageChannel output() {
return new DirectChannel();
}
Your work-around is ok, but a little less efficient.
EDIT
If you want to bridge two channels, the configuration for which you don't have control, or you want to bridge between "library" configs in different ways, this is a more efficient version of what you have...
@Bean
@ServiceActivator(inputChannel="inboundChannel")
public MessageHandler bridge() {
BridgeHandler handler = new BridgeHandler();
handler.setOutputChannelName("outboundChannel");
return handler;
}
Note that the output channel goes on the handler, not the service activator annotation. See here for this style of configuration.
Upvotes: 3
Reputation: 2288
i found a workaround using a @ServiceActivator, but i'm not sure if that is 100% equivalent.
@ServiceActivator(inputChannel = "inboundChannel", outputChannel = "outboundChannel")
public Message<?> bridge(Message<?> m) {
return m;
}
Upvotes: 0