【发布时间】:2021-01-06 14:11:06
【问题描述】:
我一直在尝试使用 Spring Integration TCP 创建消费者和生产者。我在侦听部分取得了一些成功(我得到了通过 telnet 正常发送的消息),但是当我尝试将相同的消息发送到终端客户端时,没有任何反应。
这些是我的课程:
@EnableIntegration
@IntegrationComponentScan
@Configuration
public class TcpIntegration {
@Value("${tcp.port}")
private Integer port;
@MessagingGateway(defaultRequestChannel="toTcp")
public interface Gateway {
String viaTcp(String in);
}
@Bean
@ServiceActivator(inputChannel="toTcp")
public TcpSendingMessageHandler tcpOutGate(AbstractClientConnectionFactory connectionFactory) {
TcpSendingMessageHandler gate = new TcpSendingMessageHandler();
gate.setConnectionFactory(connectionFactory);
return gate;
}
@Bean
public TcpReceivingChannelAdapter tcpInGate(AbstractServerConnectionFactory connectionFactory) {
TcpReceivingChannelAdapter inGate = new TcpReceivingChannelAdapter();
inGate.setConnectionFactory(connectionFactory);
inGate.setOutputChannel(fromTcp());
return inGate;
}
@Bean
public MessageChannel fromTcp() {
return new DirectChannel();
}
@Bean
public AbstractClientConnectionFactory clientCF() {
return new TcpNetClientConnectionFactory("localhost", this.port);
}
@Bean
public AbstractServerConnectionFactory serverCF() {
return new TcpNetServerConnectionFactory(this.port);
}
}
TcpListener
@MessageEndpoint
@AllArgsConstructor
public class TcpListener {
private final Gateway gateway;
@ServiceActivator(inputChannel = "fromTcp")
public void convert(String payload) {
System.out.println(payload);
gateway.viaTcp(payload);
}
}
为什么它不起作用?
【问题讨论】:
标签: tcp spring-integration spring-integration-ip