Palak Shah
Palak Shah

Reputation: 71

http outbound gateway is sending only one request at a time

I have a http outbound gateway that is connecting to one URL. Below is the code snippet. I am dropping around 100 files on the folder. The URL connects localhost:8080/index.jsp. In the JSP i have added Thread.sleep(60000).

When I run the code I see that only one call is made to JSP every 60 seconds. However my pool manager to have 25 connections per route.

Not sure why it is not working. Anyone has faced similar problem?

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

Upvotes: 1

Views: 1080

Answers (2)

Palak Shah
Palak Shah

Reputation: 71

I changed the configuration to add executor as below.

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

Still it was only sending one request to my tomcat server listening for index.jsp. My understanding was if there are multiple messages present in the channel queue which is the case now on httpInputChannel, the http outbound gateway would process multiple requests. However this is not happening. I further changed my default poller as below.

<int:poller default="true" fixed-delay="50" task-executor="executor"/>

After above change, the http outbound gateway started sending multiple requests to the URL. Now I am confused. Do we need to explicitly assign executor for outbound gateway to process multiple messages at the same time? Can someone please direct me to the documentation for the same?

Thank you.

Upvotes: 0

Gary Russell
Gary Russell

Reputation: 174779

You have a single poller thread on your file inbound channel adapter. You need to add a task-executor to the poller, with a pool size set the number of concurrent requests you want to handle.

You also need to set max-messages-per-poll, which defaults to 1.

Upvotes: 1

Related Questions