问题
I have the following spring-integration XML config
<ip:tcp-outbound-gateway id="outboundClient"
request-channel="requestChannel"
reply-channel="string2ObjectChannel"
connection-factory="clientConnectionFactory"
request-timeout="10000"
reply-timeout="10000"/>
How can I write the Java config equivalent of the above? I thought the equivalent would be
@Bean
public TcpOutboundGateway outboundClient() {
TcpOutboundGateway tcpOutboundGateway = new TcpOutboundGateway();
tcpOutboundGateway.setConnectionFactory(clientConnectionFactory());
tcpOutboundGateway.setRequiresReply(true);
tcpOutboundGateway.setReplyChannel(string2ObjectChannel());
tcpOutboundGateway.setRequestTimeout(10000);
tcpOutboundGateway.setSendTimeout(10000);
return tcpOutboundGateway;
}
But I couldn't find a way to set the request channel. Any help would be appreciated.
Thank you
回答1:
Your config looks good, but you should know in addition that any Spring Integration Consumer component consists of two main objects: MessageHandler
(TcpOutboundGateway
in your case) and EventDrivenConsumer
for subscriable
input-channel
or PollingConsumer
if input-channel
is Pollable
.
So, since you already have the first, handling, part you need another consuming. For this purpose Spring Integration suggests to mark your @Bean
with endpoint annotations:
@Bean
@ServiceActivator(inputChannel = "requestChannel")
public TcpOutboundGateway outboundClient() {
See more in the Spring Integration Reference Manual.
However to allow such a annotation process (or any other Spring Integration infrastructure) you have to mark your @Configuration
with @EnableIntegration
.
Also consider to use Spring Integration Java DSL to have more gain from JavaConfig.
来源:https://stackoverflow.com/questions/28796482/what-is-the-java-config-equivalent-to-tcp-outbound-gateway