Spring 使用负载平衡动态调整出站网关
我想使用输入通道的负载平衡来修改(添加/删除)出站网关列表。我的代码:Spring 使用负载平衡动态调整出站网关,spring,spring-integration,Spring,Spring Integration,我想使用输入通道的负载平衡来修改(添加/删除)出站网关列表。我的代码: <int:channel id="mainRequestChannel" /> <int-http:outbound-gateway request-channel="mainRequestChannel" message-converters="messageConverters" request-factory="httpRequestFa
<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" />
我修改了这个,现在我有了一个dynamicrouder:
<int:channel id="mainRequestChannel" />
<int:router input-channel="mainRequestChannel" expression="@dynamicChannelResolver.resolve()"/>
但是mainRequestChannel只有一个订户,因此默认行为负载平衡器无法工作
谢谢您的帮助。请参阅示例。基本上,您可以将出站网关放在其自己的上下文中,并带有URL等参数。但是,与该示例不同,您需要将上下文设置为主上下文的子上下文(因此它将能够引用finishedResponse
频道)
示例自述文件有一个链接,指向一些论坛讨论,其中解释了该技术
或者,您可以自己连接必要的类-您需要一个带有
mainRequestChannel
的EventDrivenConsumer
和在其构造函数中正确配置的HttpRequestExecutingMessageHandler
。如果您连接自己的组件,不要忘记调用afterPropertiesSet()
在消息处理程序上,您需要start()
消费者才能订阅频道(stop()
才能取消订阅)。谢谢Gary,我明天会读到这篇文章。新年快乐!!:)很好的例子。我照你说的做了,为我的出站网关提取XML,并为引用我的输出通道创建子上下文。然而,另一个问题是,使用这种技术进行负载平衡的最佳实践是什么?如果slave1返回异常,我如何调用另一个出站网关?您真的应该就此开始另一个问题,但默认的负载平衡器是带故障转移的循环-如果当前订阅服务器失败,则调用下一个订阅服务器,直到成功。您可以将负载平衡器设置为none
,以便始终按顺序尝试适配器,而不是负载平衡。在3.0.x中,您可以提供自己的负载平衡器。是的,但通道(您的“toFtpChannel”)是在子上下文中创建的,而不是在主上下文中创建的,因此每个出站网关只有一个订户,负载平衡器无法工作。