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