Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 使用负载平衡动态调整出站网关_Spring_Spring Integration - Fatal编程技术网

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”)是在子上下文中创建的,而不是在主上下文中创建的,因此每个出站网关只有一个订户,负载平衡器无法工作。