Methods 方法返回无效时Spring集成网关回复通道
我有一些关于SI网关功能的问题/澄清: 如果我的网关接口定义如下:Methods 方法返回无效时Spring集成网关回复通道,methods,integration,spring-integration,void,gateway,Methods,Integration,Spring Integration,Void,Gateway,我有一些关于SI网关功能的问题/澄清: 如果我的网关接口定义如下: public interface MyGateway{ public void myGatewayMethod(Message<?> inMessage); } <int:gateway id="mySvcGateway" service-interface="com.myCompany.myPkg.MyGateway" error-c
public interface MyGateway{
public void myGatewayMethod(Message<?> inMessage);
}
<int:gateway id="mySvcGateway"
service-interface="com.myCompany.myPkg.MyGateway"
error-channel="globalExceptionHandlerChannel">
<int:method name="myGatewayMethod" request-channel="myGatewayReqChannel" />
</int:gateway>
public interface MyGateway{
public void myGatewayMethod(Message<?> inMessage);
public Object myGatewayMethod2(Message<?> inMessage);
}
<int:gateway id="mySvcGateway"
service-interface="com.myCompany.myPkg.MyGateway"
error-channel="globalExceptionHandlerChannel">
<int:method name="myGatewayMethod" request-channel="myGatewayReqChannel" />
<int:method name="myGatewayMethod2" request-channel="myGatewayReqChannel2" />
</int:gateway>
并在我的网关配置中添加此方法,如下所示:
public interface MyGateway{
public void myGatewayMethod(Message<?> inMessage);
}
<int:gateway id="mySvcGateway"
service-interface="com.myCompany.myPkg.MyGateway"
error-channel="globalExceptionHandlerChannel">
<int:method name="myGatewayMethod" request-channel="myGatewayReqChannel" />
</int:gateway>
public interface MyGateway{
public void myGatewayMethod(Message<?> inMessage);
public Object myGatewayMethod2(Message<?> inMessage);
}
<int:gateway id="mySvcGateway"
service-interface="com.myCompany.myPkg.MyGateway"
error-channel="globalExceptionHandlerChannel">
<int:method name="myGatewayMethod" request-channel="myGatewayReqChannel" />
<int:method name="myGatewayMethod2" request-channel="myGatewayReqChannel2" />
</int:gateway>
4) 在这种情况下,我认为我需要定义回复频道
,对吗
5) 默认回复频道在这种情况下可能不起作用,因为一种方法网关需要响应,而另一种方法则不需要,对吗
6) 如果是,那么对于返回void的方法,我是否需要明确提到reply channel=“nullChannel”
谢谢您的确认。Lalit
谢谢你提出这么多问题,我很惊讶所有这些问题都围绕着网关的void
方法
所有这些问题的快速合理答案是:
由于我们在参考手册中没有对这一问题做任何说明,因此这种配置不必担心,它应该按照用户的预期工作
相信春天的融合
我有点开玩笑,但每个玩笑都有一部分是真的
现在让我们看看<代码> GatewayProxyFactoryBean < /COD>:< /P>的源代码
private Object invokeGatewayMethod(MethodInvocation invocation, boolean runningOnCallerThread) throws Exception {
..........
boolean shouldReply = returnType != void.class;
..................
Object[] args = invocation.getArguments();
if (shouldReply) {
response = shouldReturnMessage ? gateway.sendAndReceiveMessage(args) : gateway.sendAndReceive(args);
}
else {
gateway.send(args);
response = null;
}
}
return (response != null) ? this.convert(response, returnType) : null;
}
其中MessagingGatewaySupport.send()
将代理发送到
this.messagingTemplate.convertAndSend(requestChannel, object, this.historyWritingPostProcessor);
它也是void
,只在末尾调用MessageChannel.send()
您可能猜到,此方法根本不关心replyChannel
和replyTimeout
从逻辑上讲,它假定对于void
方法,这些选项将被忽略,而对于其他方法,任何default-*
都不会影响使用void
返回类型的方法
希望我清楚。有人能帮我澄清以上问题吗?阿泰姆/加里-寻找你的好心人!非常感谢!好的,拉里特。今天我把你的问题放在首位,看一看:-)许多tx艺术;你的澄清非常清楚!但是,如何实现void方法的超时功能,类似于“replyTimeout”为非void方法提供的功能?我不希望我的线程在长时间的处理过程中被不必要地卡住。另外,我希望避免使用任何类型的入站通道适配器。我们在等待回复时,在
async
情况下需要超时。如果您的请求-答复案例是同步的,则不会涉及任何超时。对于卡住的线程,它只是send
或send
的一部分send和receive
并不重要。试着想象一下你没有SI的用例,你会发现没有任何工具可以帮助你停止线程本身。有时候我们可以通过避免不必要的复杂性来简化我们的生活!)谢谢你,阿泰姆!知道一个void
返回值实质上会将“网关”变成类似“适配器”的东西,应该在文档中提到!