2
我使用的春天开机即按照TcpInboundGateway例子之前,但已经发现的行为稍有不同比手工编码的一块TCP代码,我取代。Spring集成:TcpInboundGateway读取流封闭@MessageEndpoint写入到输出流
使用netcat的,接收应答之前NC退出时,因为TcpInboundGateway读蒸汽被关闭时,任何写入之前发生,导致NC退出具体。
可以在关闭读取流被延迟,直到写入完成?
下面是代码:
@Configuration
@EnableIntegration
@ComponentScan
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) throws Exception {
ConfigurableApplicationContext ctx = SpringApplication.run(Application.class);
}
@Bean
TcpNetServerConnectionFactory cf() {
return new TcpNetServerConnectionFactory(9876);
}
@Bean
TcpInboundGateway tcpGate() {
TcpInboundGateway gateway = new TcpInboundGateway();
gateway.setConnectionFactory(cf());
gateway.setRequestChannel(requestChannel());
return gateway;
}
@Bean
public MessageChannel requestChannel() {
return new DirectChannel();
}
@MessageEndpoint
public static class Echo {
@ServiceActivator(inputChannel = "requestChannel")
public String echo(byte [] in) {
return "echo: " + new String(in);
}
}
@Autowired
private Environment env;
}
所以我想通了它可能是流终结符字符。 做了一些摆弄,发现使用ByteArrayRawSerializer解决了我的问题。 @Bean TcpNetServerConnectionFactory cf(){ TcpNetServerConnectionFactory tcpNetServerConnectionFactory = new TcpNetServerConnectionFactory(9876); tcpNetServerConnectionFactory.setDeserializer(new ByteArrayRawSerializer()); return tcpNetServerConnectionFactory; } – 2015-02-24 13:44:26
这是一般都比较好编辑您的问题,而不是把代码在这些意见;他们不会很好地呈现代码。既然你有决议,你也可以回答你自己的问题。 – 2015-02-24 13:48:05