Results 1 to 10 of 10

Thread: Can I get polling and set maxMessagesPerTask with JMS

  1. #1
    Join Date
    May 2011
    Location
    Columbus, OH
    Posts
    18

    Default Can I get polling and set maxMessagesPerTask with JMS

    OK, if I use jms:inbound_channel_adapter, I can use polling, but it will read all the messages on the queue at time.

    If I use jms:message_driven_channel_adapter or jms:inbound_gateway, it will read every message as it comes in but I can set the maxMessagesPerTask.

    Is there any way to configure jms inbound so that I can trickle messages in? Can I do something so silly as to say I only want to process one message every 5 seconds?
    --

    J Nelson
    Big Lots, Inc

  2. #2
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,029

    Default

    The inbound channel adapter works exactly as you want - it does not fetch all the messages - that is controlled by max-messages-per-poll on the poller, which defaults to 1.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  3. #3
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,029

    Default

    This will fetch one message every 5 seconds...

    Code:
    <jms:inbound-channel-adapter id="in" channel="jmsinToStdoutChannel" destination="requestQueue">
    	<poller fixed-delay="5000" />
    </jms:inbound-channel-adapter>
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  4. #4
    Join Date
    May 2011
    Location
    Columbus, OH
    Posts
    18

    Default

    Perfect! Thank you!
    --

    J Nelson
    Big Lots, Inc

  5. #5
    Join Date
    May 2011
    Location
    Columbus, OH
    Posts
    18

    Default

    I'm getting something strange with this change that I can't explain.

    Our original configuration to read as fast as possible was this:

    Code:
    <beans:bean id="connectionFactory" class="com.ibm.mq.jms.MQConnectionFactory">
            <beans:property name="queueManager">
                <beans:value>${jms.manager}</beans:value>
            </beans:property>
            <beans:property name="hostName">
                <beans:value>${jms.host.name}</beans:value>
            </beans:property>
            <beans:property name="port">
                <beans:value>${jms.host.port}</beans:value>
            </beans:property>
            <beans:property name="transportType" value="${jms.transport.type}" />
            <beans:property name="channel" value="${jms.channel}"/>
        </beans:bean>
        
        <beans:bean id="jmsConnectionFactoryProxy" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
            <beans:property name="targetConnectionFactory" ref="connectionFactory" />
            <beans:property name="username" value="${jms.userid}" />
            <beans:property name="password" value="${jms.password}" />
        </beans:bean>
    
        <beans:bean id="queueListenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
            <beans:property name="destination" ref="requestQueue" />
            <beans:property name="connectionFactory" ref="jmsConnectionFactoryProxy" />
            <beans:property name="sessionTransacted" value="true" />
            <beans:property name="concurrentConsumers" value="${number.of.concurrent.listener}" />
            <beans:property name="maxConcurrentConsumers" value="${max.concurrent.listener}" />
            <beans:property name="cacheLevelName" value="${cache.level}" />
        </beans:bean>
        
        <beans:bean id="requestQueue" class="com.ibm.mq.jms.MQQueue">
            <beans:constructor-arg value="${q.site}"/>
        </beans:bean>
                
        <jms:message-driven-channel-adapter id="request"
                container="queueListenerContainer"
                channel="inputChannel" auto-startup="true" />
    When I try to use the inbound-channel-adapter to read messages slower, I change the configuration to

    Code:
    <beans:bean id="connectionFactory" class="com.ibm.mq.jms.MQConnectionFactory">
            <beans:property name="queueManager">
                <beans:value>${jms.manager}</beans:value>
            </beans:property>
            <beans:property name="hostName">
                <beans:value>${jms.host.name}</beans:value>
            </beans:property>
            <beans:property name="port">
                <beans:value>${jms.host.port}</beans:value>
            </beans:property>
            <beans:property name="transportType" value="${jms.transport.type}" />
            <beans:property name="channel" value="${jms.channel}"/>
        </beans:bean>
        
        <beans:bean id="jmsConnectionFactoryProxy" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
            <beans:property name="targetConnectionFactory" ref="connectionFactory" />
            <beans:property name="username" value="${jms.userid}" />
            <beans:property name="password" value="${jms.password}" />
        </beans:bean>
    
        <beans:bean id="requestQueue" class="com.ibm.mq.jms.MQQueue">
            <beans:constructor-arg value="${q.site}"/>
        </beans:bean>
                
        <jms:inbound-channel-adapter id="request"
         channel="inputChannel"
         connection-factory="jmsConnectionFactoryProxy"
         destination="requestQueue" auto-startup="true">
            <poller max-messages-per-poll="1" fixed-delay="${fixed.delay}"
             default="true" id="inboundPoller" />
        </jms:inbound-channel-adapter>
    The first configuration with jms:message-driven-channel-adapter works fine in both jboss and tomcat. But the second configuration with jms:inbound-channel-adapter doesn't work in tomcat. I don't get any errors, it just doesn't seem to read from the queue.

    I have backed things out and made sure that this is the only config change between the two.

    Any help?
    Last edited by jnelson; Mar 14th, 2012 at 02:34 PM.
    --

    J Nelson
    Big Lots, Inc

  6. #6
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    Let me see if I can take you the whole different direction here. Why use inbound-channel-adapter (polling approach) when you can use inbound-gateway (even-driven approach) where messages will be read as soon as they come in. If any throttling required downstream (e.g., slow down processing, controlling spikes) it could be easily accomplished by sticking QueueChannel and PollingConsumer downstream

    jms:inbound-gateway -> QueueChannel -> PollingConsumer

  7. #7
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,029

    Default

    Hmmm... can you run with DEBUG logging? You should see something like this (when the queue's empty)...

    Code:
    2012-03-14 15:39:49,302 [jmsexec-1] DEBUG: org.springframework.integration.endpoint.SourcePollingChannelAdapter - Poll resulted in Message: null
    2012-03-14 15:39:49,302 [jmsexec-1] DEBUG: org.springframework.integration.endpoint.SourcePollingChannelAdapter - Received no Message during the poll, returning 'false'
    ...
    
    2012-03-14 15:39:54,302 [jmsexec-1] DEBUG: org.springframework.integration.endpoint.SourcePollingChannelAdapter - Poll resulted in Message: null
    2012-03-14 15:39:54,302 [jmsexec-1] DEBUG: org.springframework.integration.endpoint.SourcePollingChannelAdapter - Received no Message during the poll, returning 'false'
    ...
    Notice I added a task exececutor to make it easier to see the poller's logs...
    Code:
    <poller fixed-delay="5000" task-executor="jmsexec"/>
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  8. #8
    Join Date
    May 2011
    Location
    Columbus, OH
    Posts
    18

    Default

    to Oleg, I'll look into it...

    to Gary, Debug is on and I added teh task-executor, but I don't see poll attempts in tomcat
    --

    J Nelson
    Big Lots, Inc

  9. #9
    Join Date
    May 2011
    Location
    Columbus, OH
    Posts
    18

    Default

    Oleg, I got your suggestion working.

    Thanks again!
    --

    J Nelson
    Big Lots, Inc

  10. #10
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,029

    Default

    Bear in mind you can lose messages that way - messages in the queue channel are in memory, unless you persist them in a database or another message store, or another JMS queue - the polling approach should work - we just need to figure out what's going on in your Tomcat environment. It should make no difference to your SI config what container it's running in.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •