http 出站网关一次只发送一个请求
http outbound gateway is sending only one request at a time
我有一个连接到 URL 的 http 出站网关。下面是代码片段。我在文件夹中放置了大约 100 个文件。 URL 连接 localhost:8080/index.jsp。在 JSP 我添加了 Thread.sleep(60000).
当我 运行 代码时,我看到每 60 秒只对 JSP 进行一次调用。但是我的池管理器每条路线有 25 个连接。
不确定为什么它不起作用。有人遇到过类似的问题吗?
<int:poller default="true" fixed-delay="50"/>
<int:channel id="inputChannel">
<int:queue capacity="5"/>
</int:channel>
<int:channel id="httpInputChannel">
<int:queue capacity="5"/>
</int:channel>
<int-http:outbound-gateway id="simpleHttpGateway"
request-channel="httpInputChannel"
url="${app.webservice.url}"
http-method="GET"
extract-request-payload="false"
expected-response-type="java.lang.String"
charset="UTF-8"
reply-timeout="1234"
request-factory="requestFactory"
reply-channel="wsResponseChannel">
</int-http:outbound-gateway>
<bean id="requestFactory"
class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory">
<constructor-arg ref="httpClient"/>
</bean>
<bean id="httpClient" class="org.apache.http.impl.client.DefaultHttpClient">
<constructor-arg ref="poolManager"/>
</bean>
<bean id="poolManager" class="org.apache.http.impl.conn.PoolingClientConnectionManager">
<property name="defaultMaxPerRoute" value="25"/>
<property name="maxTotal" value="250"/>
</bean>
<int:channel id="wsResponseChannel">
<int:queue capacity="5"/>
</int:channel>
<int:service-activator ref="clientServiceActivator" method="handleServiceResult" input-channel="wsResponseChannel" />
<bean id="clientServiceActivator" class="com.spijb.serviceactivator.ClientServiceActivator"/>
<int-file:inbound-channel-adapter id="producer-file-adapter" channel="inputChannel" directory="file:c://Temp//throttling" prevent-duplicates="true">
<int:poller fixed-rate="100" />
</int-file:inbound-channel-adapter>
<int-file:file-to-string-transformer
id="file-2-string-transformer" input-channel="inputChannel"
output-channel="httpInputChannel" charset="UTF-8" />
您的文件入站通道适配器上有一个轮询器线程。您需要向轮询器添加一个任务执行器,池大小设置您要处理的并发请求数。
您还需要设置max-messages-per-poll
,默认为1。
我更改了配置以添加执行程序,如下所示。
<int-file:inbound-channel-adapter id="producer-file-adapter" channel="inputChannel" directory="file:c://Temp//throttling" prevent-duplicates="true">
<int:poller fixed-rate="100" task-executor="executor" max-messages-per-poll="25"/>
</int-file:inbound-channel-adapter>
<task:executor id="executor" pool-size="25"/>
它仍然只向我的 tomcat 服务器发送一个请求,监听 index.jsp。我的理解是,如果通道队列中存在多条消息(现在在 httpInputChannel 上就是这种情况),http 出站网关将处理多个请求。然而,这并没有发生。我进一步更改了我的默认轮询器,如下所示。
<int:poller default="true" fixed-delay="50" task-executor="executor"/>
经过上述更改后,http 出站网关开始向 URL 发送多个请求。现在我很困惑。我们是否需要为出站网关显式分配执行程序以同时处理多条消息?有人可以指导我查看相同的文档吗?
谢谢。
我有一个连接到 URL 的 http 出站网关。下面是代码片段。我在文件夹中放置了大约 100 个文件。 URL 连接 localhost:8080/index.jsp。在 JSP 我添加了 Thread.sleep(60000).
当我 运行 代码时,我看到每 60 秒只对 JSP 进行一次调用。但是我的池管理器每条路线有 25 个连接。
不确定为什么它不起作用。有人遇到过类似的问题吗?
<int:poller default="true" fixed-delay="50"/>
<int:channel id="inputChannel">
<int:queue capacity="5"/>
</int:channel>
<int:channel id="httpInputChannel">
<int:queue capacity="5"/>
</int:channel>
<int-http:outbound-gateway id="simpleHttpGateway"
request-channel="httpInputChannel"
url="${app.webservice.url}"
http-method="GET"
extract-request-payload="false"
expected-response-type="java.lang.String"
charset="UTF-8"
reply-timeout="1234"
request-factory="requestFactory"
reply-channel="wsResponseChannel">
</int-http:outbound-gateway>
<bean id="requestFactory"
class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory">
<constructor-arg ref="httpClient"/>
</bean>
<bean id="httpClient" class="org.apache.http.impl.client.DefaultHttpClient">
<constructor-arg ref="poolManager"/>
</bean>
<bean id="poolManager" class="org.apache.http.impl.conn.PoolingClientConnectionManager">
<property name="defaultMaxPerRoute" value="25"/>
<property name="maxTotal" value="250"/>
</bean>
<int:channel id="wsResponseChannel">
<int:queue capacity="5"/>
</int:channel>
<int:service-activator ref="clientServiceActivator" method="handleServiceResult" input-channel="wsResponseChannel" />
<bean id="clientServiceActivator" class="com.spijb.serviceactivator.ClientServiceActivator"/>
<int-file:inbound-channel-adapter id="producer-file-adapter" channel="inputChannel" directory="file:c://Temp//throttling" prevent-duplicates="true">
<int:poller fixed-rate="100" />
</int-file:inbound-channel-adapter>
<int-file:file-to-string-transformer
id="file-2-string-transformer" input-channel="inputChannel"
output-channel="httpInputChannel" charset="UTF-8" />
您的文件入站通道适配器上有一个轮询器线程。您需要向轮询器添加一个任务执行器,池大小设置您要处理的并发请求数。
您还需要设置max-messages-per-poll
,默认为1。
我更改了配置以添加执行程序,如下所示。
<int-file:inbound-channel-adapter id="producer-file-adapter" channel="inputChannel" directory="file:c://Temp//throttling" prevent-duplicates="true">
<int:poller fixed-rate="100" task-executor="executor" max-messages-per-poll="25"/>
</int-file:inbound-channel-adapter>
<task:executor id="executor" pool-size="25"/>
它仍然只向我的 tomcat 服务器发送一个请求,监听 index.jsp。我的理解是,如果通道队列中存在多条消息(现在在 httpInputChannel 上就是这种情况),http 出站网关将处理多个请求。然而,这并没有发生。我进一步更改了我的默认轮询器,如下所示。
<int:poller default="true" fixed-delay="50" task-executor="executor"/>
经过上述更改后,http 出站网关开始向 URL 发送多个请求。现在我很困惑。我们是否需要为出站网关显式分配执行程序以同时处理多条消息?有人可以指导我查看相同的文档吗?
谢谢。