Adapt dynamically outbound-gateway with load-balan

2019-06-14 08:04发布

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条回答
我想做一个坏孩纸
2楼-- · 2019-06-14 08:32

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.

查看更多
登录 后发表回答