我创建了一个控制 channel 和一个网关服务来向该 channel 发送控制消息。但是,在我调用应该返回 boolean 值的网关服务方法后,在消息提交后没有返回。
代码片段:
public interface SampleControlService {
boolean sendControl(String message);
}
....
@Autowired
private SampleControlService sampleControlService;
.....
boolean done = sampleControlService.sendControl("@testAdapter.stop()"); // message gets sent but it is not returning to caller
System.out.println("Done : " + done); // this line doesn't execute
// integration config
<int:channel id="controlChannel"/>
<int:gateway service-interface="com.test.service.SampleControlService" default-request-channel="controlChannel" />
<int:control-bus input-channel="controlChannel"/>
但是,如果我发送消息 @testAdapter.isRunning() 来检查状态,它会按预期返回。
最佳答案
嗯,void stop()
不会返回结果,而 boolean isRunning()
会返回结果;网关对被调用的方法一无所知;您正在“告诉”框架您正在期待一个永远不会出现的结果。
您可以添加其他网关方法
void sendOneWayControl(String command);
或将 default-reply-timeout="0"
添加到网关,您将得到 null
返回。
关于java - Spring Integration Gateway 服务方法在启动/停止时不返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41341515/