gpt4 book ai didi

methods - 方法返回无效时的 Spring Integration Gateway 回复 channel

转载 作者:行者123 更新时间:2023-12-04 15:09:37 27 4
gpt4 key购买 nike

我有关于 SI 网关功能的问题/澄清:

如果我的网关接口(interface)定义如下:

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) 由于网关服务接口(interface)方法返回 void,网关代理 bean 是否仍然在“default-reply-channel”或用户定义的“reply-channel”上寻找响应?

2)也就是说,我还需要提 reply-channel="nullChannel"吗? (或 default-reply-channel="nullChannel")?

或者

由于方法返回无效,网关会自动理解不收听回复 channel ?

3) 我还能加 reply-timeout归因于此配置,或者由于没有预期的回复而没有意义?

在类似的上下文中,如果我在服务接口(interface)方法中添加另一个方法,如下所示:
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() .

正如您可能猜到的那样,此方法不关心 replyChannelreplyTimeout一点也不。

从逻辑上讲,它假定 void 将忽略这些选项。方法和任何 default-*对于其他方法不会影响 void返回类型。

希望我清楚。

关于methods - 方法返回无效时的 Spring Integration Gateway 回复 channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33199425/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com