【发布时间】:2017-06-05 05:51:22
【问题描述】:
我正在使用 spring-integration 开发一个自定义的双向 tcp 套接字服务器。
服务器将处理请求/响应任务,但我无法向特定连接 ID 发送任意消息
我也知道可能使用TcpSendingMessageHandler 和TcpReceivingChannelAdapter 是解决方案,但我找不到任何关于如何使用它的示例代码。
这是我的代码:
public class SocketServer {
private Logger logger = LoggerFactory.getLogger(SocketServer.class);
@Bean
public AbstractServerConnectionFactory connectionFactory() {
return new TcpNetServerConnectionFactory(2025);
}
@Bean
public TcpInboundGateway TcpInboundGateway(AbstractServerConnectionFactory connectionFactory) {
TcpInboundGateway inGate = new TcpInboundGateway();
inGate.setConnectionFactory(connectionFactory);
inGate.setRequestChannelName("directChannel");
return inGate;
}
@Bean
public DirectChannel directChannel() {
return new DirectChannel();
}
@MessageEndpoint
public class Echo {
@Transformer(inputChannel = "directChannel")
public String process(byte[] input) throws Exception {
return new String(input).toUpperCase();
}
}
public boolean sendMessage(String connectionId){
//TODO send Message
}
}
【问题讨论】:
标签: java spring sockets tcp spring-integration