Java TcpInboundGateway服务器配置-超时时发送自定义消息

Java TcpInboundGateway服务器配置-超时时发送自定义消息,java,spring-boot,spring-integration,Java,Spring Boot,Spring Integration,我正在使用Spring与Spring Boot的集成。我有一个带有TcpInboundGateway设置的TCP服务器和一个包含业务逻辑的转换器,它在处理完成后返回字符串。当我通过套接字接收消息时,此设置工作正常 @Bean public TcpInboundGateway paWebserviceInGate() { TcpInboundGateway inGateway = new TcpInboundGateway(); inGateway.setConnectionFac

我正在使用Spring与Spring Boot的集成。我有一个带有TcpInboundGateway设置的TCP服务器和一个包含业务逻辑的转换器,它在处理完成后返回字符串。当我通过套接字接收消息时,此设置工作正常

@Bean
public TcpInboundGateway paWebserviceInGate() {
    TcpInboundGateway inGateway = new TcpInboundGateway();
    inGateway.setConnectionFactory(connectionFactory.serverConnectionFactory(port));
    inGateway.setRequestChannelName("paWebserviceInputChannel");
    inGateway.setReplyTimeout(5000);//To configure the timeout - but it does not work 
    return inGateway;
}

@Transformer(inputChannel = "paWebserviceInputChannel")
public String consume(byte[] bytes) {
    String message = new String(bytes);
    return paMessageHandler.processPAIndiators(message);
}
ConnectionFactory.java:

public AbstractServerConnectionFactory serverConnectionFactory(int port) {
    final AbstractServerConnectionFactory connectionFactory = new TcpNetServerConnectionFactory(port);
    connectionFactory.setSerializer(customDeserializer);
    connectionFactory.setDeserializer(customDeserializer);
    connectionFactory.setSoKeepAlive(false);
    // connectionFactory.setSoTimeout(timeout);
    return connectionFactory;
}
现在,我有一个要求,在超时5秒时,我需要向客户端发送一条自定义消息。假设服务需要10秒,我需要在5秒后发送定制消息,告知客户端超时。(请注意,我无法控制客户端;因此无法在客户端添加超时)

我在TcpInboundGateway上使用了setReplyTimeout;但5秒后不会超时

我引用了这篇文章

这篇文章解释了Artem Bilan建议的xml配置。 有人能帮我配置Java吗?在将上述代码配置为包含超时时,我感到困惑。我应该使用IntegrationFlows吗


提前感谢。

框架中没有内置任何东西可以做到这一点;我开了一家商店

回复计时器仅在线程返回网关时启动;它仅适用于异步处理时;您必须在不同的线程上处理您的请求。但这仍然没有帮助,因为网关只是在回复超时后释放线程

在当前状态下,您必须在服务中自己完成

  • 排队等待任务执行者的答复
  • 如果没有收到回复,请返回错误条件

注意一旦你回复网关,你就无法发送真正的回复。

框架中没有内置任何东西可以做到这一点;我开了一家商店

回复计时器仅在线程返回网关时启动;它仅适用于异步处理时;您必须在不同的线程上处理您的请求。但这仍然没有帮助,因为网关只是在回复超时后释放线程

在当前状态下,您必须在服务中自己完成

  • 排队等待任务执行者的答复
  • 如果没有收到回复,请返回错误条件
注意一旦回复网关,就无法发送真正的回复