Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: How message driven channel works?

  1. #1
    Join Date
    Apr 2012
    Posts
    27

    Default How message driven channel works?

    I have a message Queue and im getting the messages from there by a message driven channel(jms).
    My question is,how it works?

    It get a message deliver and next get the another one,and so on... Or each time arrives a message it deliver..
    For example:
    1 -> I have 100 messages in my queue,channel is getting one by one,and just get the other one after deliver the message before.
    2-> I have 100 messages in my queue so my channel is getting all 100 in same time and delivering it at same time

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

    Default

    It depends on the concurrency settings; if you use one thread, you will get one at a time; if you use 5 threads, you will get 5 at a time, etc. There are other settings at the broker level that will determine how messages are delivered to consumers (prefetch etc).
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  3. #3
    Join Date
    Apr 2012
    Posts
    27

    Default

    Quote Originally Posted by Gary Russell View Post
    It depends on the concurrency settings; if you use one thread, you will get one at a time; if you use 5 threads, you will get 5 at a time, etc. There are other settings at the broker level that will determine how messages are delivered to consumers (prefetch etc).
    At the moment im using ActiveMQ,so if i have this configuration,it means that i will have 100 threads?
    Or for i have 100 threads i need to create 100 channels pooling from my queue??

    Code:
    <bean id="pooledConnectionFactory" 
      		 class="org.apache.activemq.pool.PooledConnectionFactory">
       		<property name="maxConnections" value="100" />
       		<property name="maximumActive" value="500" />
       		<property name="connectionFactory" ref="jmsConnectionFactory" />
    	</bean>

    a channel example..

    Code:
    <int-jms:message-driven-channel-adapter
    		id="example" destination-name="ExampleQueue" channel="channelExample"
    		connection-factory="jmsConnectionFactory" />

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

    Default

    See the documentation for concurrent-consumers and max-concurrent-consumers for the message-driven-channel-adapter.

    You could, say, set concurrent-consumers to 1 and max-concurrent-consumers to 100 and they will grow as needed. or you can set them both to 100 and you will always have 100.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  5. #5
    Join Date
    Apr 2012
    Posts
    27

    Default

    Never saw that before..
    Im sorry but in documentation u should put more information about that.
    Anyway thanks,i will test it

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

    Default

    The attributes are well documented in the schema - your IDE should present you with a list of available attributes, together with their documentation...

    Code:
    <xsd:attribute name="concurrent-consumers" type="xsd:string">
    	<xsd:annotation>
    		<xsd:documentation>
    			Specify the number of concurrent consumers to create. Default is 1.
    				Specifying a higher value for this setting will increase the standard
    				level of scheduled concurrent consumers at runtime: This is effectively
    				the minimum number of concurrent consumers which will be scheduled
    				at any given time. This is a static setting; for dynamic scaling,
    				consider specifying the "maxConcurrentConsumers" setting instead.
    				Raising the number of concurrent consumers is recommendable in order
    				to scale the consumption of messages coming in from a queue. However,
    				note that any ordering guarantees are lost once multiple consumers are
    				registered
    		</xsd:documentation>
    	</xsd:annotation>
    </xsd:attribute>
    <xsd:attribute name="max-concurrent-consumers" type="xsd:string">
    	<xsd:annotation>
    		<xsd:documentation>
    			 Specify the maximum number of concurrent consumers to create. Default is 1.
    				 If this setting is higher than "concurrentConsumers", the listener container
    				 will dynamically schedule new consumers at runtime, provided that enough
    				 incoming messages are encountered. Once the load goes down again, the number of
    				 consumers will be reduced to the standard level ("concurrentConsumers") again.
    				 Raising the number of concurrent consumers is recommendable in order
    				to scale the consumption of messages coming in from a queue. However,
    				note that any ordering guarantees are lost once multiple consumers are
    				registered.
    		</xsd:documentation>
    	</xsd:annotation>
    </xsd:attribute>
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  7. #7
    Join Date
    Apr 2012
    Posts
    27

    Default

    it works like a charm,but im seeing the consumers always growing and never reduce.

    I did a test that was sending messages in 1 minute,and other minute was stopped,and what i see is that number of consumers estabilished in 25,but when appplicattion stop sending messages the number didnt reduce to 1.
    Why this is not dynamic??


    edit: i saw now in documentation that it should reduce,but i didnt see that :\

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

    Default

    It will reduce over time - we don't want to keep starting/stopping consumers.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  9. #9
    Join Date
    Apr 2012
    Posts
    27

    Default

    I edited my post,anyway here is my code..

    Code:
    while(true){
    	for(int i=0;i<100;i++){
    	    input.send(MessageBuilder.withPayload(someObject).build());	
    	   }
           Thread.sleep(60000);
    }
    So,when is in "for" i see my consumers growing up, but when thread is "sleeping" the number of consumers dont reduce..

    ty again



    ps: In xml i just added this "max-concurrent-consumers="100""


    edit: nevermind.... I cant make it reduce..
    Last edited by Yayaa; Jan 14th, 2013 at 11:25 AM.

  10. #10
    Join Date
    Apr 2012
    Posts
    27

    Default

    I made a second test and consumers never reduce,why? :\

    The code this time is..

    while(true){
    for(int i=0;i<100;i++){
    input.send(MessageBuilder.withPayload(someObject). build());
    }
    for(int i =0;i<10000;i++){
    System.out.println("im in second for");
    }

    So when enter in second cycle for the number of consumers shoulded reduce,but its the same and after back to first cycle for the number up again..

Posting Permissions

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