Adapt dynamically outbound-gateway with load-balancing

落爺英雄遲暮 提交于 2019-12-23 04:35:13

问题


I would like to modify (add/remove) the list of outbound-gateway using the loadbalancing of input channel. My code :

<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" />

I modify this and I have now a dynamicRouter :

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

But there is only 1 subscriber for the mainRequestChannel so the load balancer which is the default behaviour doesn't work.

Thanks for your help.


回答1:


See the dynamic-ftp sample. You would essentially put the outbound gateway in its own context with parameters for the URL etc. However, unlike that example, you would need to make the context a child of the main context (so it will be able to reference the finishedResponsechannel).

The sample README has a link to some forum discussions where that technique is explained.

Alternatively, you can wire up the necessary classes yourself - you would need a EventDrivenConsumer with mainRequestChannel and a properly configured HttpRequestExecutingMessageHandler in its constructor.



来源:https://stackoverflow.com/questions/20859415/adapt-dynamically-outbound-gateway-with-load-balancing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!