【问题标题】:Adapt dynamically outbound-gateway with load-balancing使用负载平衡动态调整出站网关
【发布时间】:2013-12-31 15:23:35
【问题描述】:

我想使用输入通道的负载平衡来修改(添加/删除)出站网关列表。我的代码:

<int:channel id="mainRequestChannel" />

<int-http:outbound-gateway request-channel="mainRequestChannel"     message-converters="messageConverters"
                           request-factory="httpRequestFactory" url="http://localhost:8100/batchfactory-slave/receiveGateway"
                           http-method="POST" expected-response-type="JobLaunchingResponse" order="1" reply-channel="finishedResponse" />
<int-http:outbound-gateway request-channel="mainRequestChannel"     message-converters="messageConverters"
                           request-factory="httpRequestFactory" url="http://localhost:8090/batchfactory-slave/receiveGateway"
                           http-method="POST" expected-response-type="JobLaunchingResponse" order="2" reply-channel="finishedResponse" />

我对此进行了修改,现在我有了一个 dynamicRouter :

<int:channel id="mainRequestChannel" />
<int:router input-channel="mainRequestChannel" expression="@dynamicChannelResolver.resolve()"/>

但 mainRequestChannel 只有 1 个订阅者,因此默认行为的负载均衡器不起作用。

感谢您的帮助。

【问题讨论】:

    标签: spring spring-integration


    【解决方案1】:

    请参阅dynamic-ftp 示例。您基本上会将出站网关与 URL 等参数放在其自己的上下文中。但是,与该示例不同,您需要使上下文成为主上下文的子上下文(因此它将能够引用 finishedResponsechannel )。

    示例 README 包含一些论坛讨论的链接,其中解释了该技术。

    或者,您可以自己连接必要的类 - 您需要一个 EventDrivenConsumermainRequestChannel,并在其构造函数中正确配置 HttpRequestExecutingMessageHandler

    【讨论】:

    • 如果你连接你自己的组件,不要忘记在消息处理程序上调用afterPropertiesSet(),你需要start()消费者使它订阅频道(@987654328 @取消订阅)。
    • 谢谢加里,我明天会读这个。新年快乐 !! :)
    • 很好的例子。我做了你所说的一切,为我的出站网关提取 XML 和一个子上下文来引用我的输出通道。但是,另一个问题是,使用这种技术进行负载平衡的最佳实践是什么?如果 slave1 返回异常,我该如何调用另一个出站网关?
    • 您真的应该为此开始另一个问题,但默认的负载均衡器是带有故障转移的循环 - 如果当前订阅者失败,则调用下一个订阅者,直到一个成功。您可以将负载平衡器设置为none 以始终按顺序尝试适配器而不是负载平衡。在 3.0.x 中,您可以提供自己的负载均衡器。
    • 是的,但是通道(您的“toFtpChannel”)是在子上下文中创建的,而不是在主上下文中创建的,因此每个出站网关只有 1 个订阅者,并且负载均衡器不起作用。
    猜你喜欢
    • 1970-01-01
    • 2010-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多