Reputation: 137
I am using spring boot as per examples for TcpInboundGateway, but have discovered the behaviour is slightly different than a hand coded a piece of TCP code I am replacing.
Specifically when using netcat, nc exits before receiving an answer, because the TcpInboundGateway read steam is closed, before any write occurs, causing nc to exit.
Can closing the read stream be delayed until the write has completed?
Here is the code:
@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;
}
Upvotes: 2
Views: 426
Reputation: 137
So I figured out it was probably the stream terminator character. Did some fiddling and found that using ByteArrayRawSerializer solves my problem.
@Bean TcpNetServerConnectionFactory cf () {
TcpNetServerConnectionFactory tcpNetServerConnectionFactory = new TcpNetServerConnectionFactory(9876);
tcpNetServerConnectionFactory.setDeserializer(new ByteArrayRawSerializer());
return tcpNetServerConnectionFactory;
}
Upvotes: 2