我有一些关于SI网关功能的问题/澄清:
如果我的网关接口定义如下:
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>
我的问题/澄清是:
1)由于网关服务接口方法返回void,网关代理bean是否仍然在"默认回复通道"或用户定义的"回复通道"上查找响应?
2)换句话说,我还需要提到reply-channel="nullChannel"
(或default-reply-channel="nullChannel"
)吗?
或
由于方法返回为void,网关会自动理解不监听应答通道吗?
3)我还可以添加reply-timeout
属性到这个配置或它将没有意义,因为没有回复预期?
在类似的上下文中,如果我像下面这样在服务接口方法中添加另一个方法:
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)在这种情况下,我认为我需要定义reply-channel
,对吗?
5) default-reply-channel
可能不适用于这种情况,因为一个方法网关期望响应而另一个方法网关不期望响应,对吗?
6)如果是,那么对于返回void的方法,我需要显式地提到reply-channel="nullChannel"
吗?
谢谢确认
好!
谢谢这么多的问题,我很惊讶所有的问题都是围绕网关的void
方法。
所有这些问题的快速合理的答案是:
由于我们在参考手册中没有提到任何关于这个问题的内容,所以对于这样的配置没有任何担忧,并且它应该按照
的预期工作。对Spring集成的信心。
我有点开玩笑,但每个笑话都有一部分是真的。
现在让我们看一下GatewayProxyFactoryBean
的源代码:
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
返回类型的方法。
希望我讲清楚了。