【问题标题】:spring integration - multiple gatewayspring 集成 - 多网关
【发布时间】:2017-06-15 15:43:51
【问题描述】:

在我的项目中,我将有两个输入参数相同但响应不同的入站网关。每个网关都在不同的 xml 中声明。问题是当我调用 gateway1 时,它转到 xml2 而不是 xml1。 我们应该如何处理。在同一个接口中有两个网关

public interface MessageGateway {
    @Gateway(requestChannel="requestChannel1")
    @Payload("#args")
    public Response1 invoke(Bean bean) throws Exception;

    @Gateway(requestChannel="requestChannel2")
    @Payload("#args")
    public List<Response2> invoke2(Bean bean) throws Exception;

}

在 xml1 中

<int:gateway id="invoke" default-request-channel="requestChannel1" default-reply-channel="finalResult"
                 service-interface="<class name>" error-channel="errorChannel" default-reply-timeout="6000"/>
    <int:channel id="errorChannel"/>

在 xml2 中

<int:gateway id="invoke1" default-request-channel="requestChannel2" default-reply-channel="finalResult"
                     service-interface="<class name>" error-channel="errorChannel" default-reply-timeout="6000"/>
        <int:channel id="errorChannel"/>

我从另一个系统调用网关。所以我自动装配网关接口并调用方法。

根据 Gary 的评论添加自动装配

@Autowired
private MessageGateway gateway;
//calling
gateway.invoke(bean);

【问题讨论】:

  • 显示两个网关的自动装配。
  • 最好将方法放在不同的接口中以避免混淆。使用此配置,两个网关都有 2 种方法。
  • 自动装配应该失败 - 你有 2 个 bean invokeinvoke1。 Spring 不知道如何为自动布线选择哪一种。您要么只需要一个&lt;gateway/&gt;,要么将方法放在不同的接口上。​​

标签: spring spring-integration gateway


【解决方案1】:

看。同一个接口不需要两个 &lt;gateway&gt; 定义。

如果您担心requestChannel,可以在@Gateway 注释或&lt;gateway&gt;&lt;method&gt; 子元素上使用该属性。

如果有两个&lt;gateway&gt;s,看起来第二个胜出,我们只为这部分配置提供代理。

【讨论】:

  • 感谢 Artem 的解释。但是,如何确保调用正确的网关和相关的 xml。
  • 不确定您的问题。只需创建一个 &lt;gateway&gt; 并为每个 @Gateway 方法指定特定的 request-channels。
【解决方案2】:

一种解决方案是声明一个方法子元素。另请参阅此处的 loadBrokerGateway:http://docs.spring.io/spring-integration/docs/2.0.0.RC1/reference/html/gateway.html

所以 XML1

<int:gateway id="invoke" default-request-channel="requestChannel1" default-reply-channel="finalResult" service-interface="<class name>" error-channel="errorChannel" default-reply-timeout="6000">
    <int:method name="invoke" request-channel="requestChannel1" />
</int:gateway>
<int:channel id="errorChannel"/>

和 XML2

<int:gateway id="invoke1" default-request-channel="requestChannel2" default-reply-channel="finalResult" service-interface="<class name>" error-channel="errorChannel" default-reply-timeout="6000">
    <int:method name="invoke" request-channel="requestChannel2" />
</int:gateway>
<int:channel id="errorChannel"/>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-21
    • 2018-06-15
    • 2014-07-24
    • 2019-03-01
    • 2014-06-08
    • 2013-08-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多