Announcement Announcement Module
Collapse
No announcement yet.
How message driven channel works? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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).

    Comment


    • #3
      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" />

      Comment


      • #4
        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.

        Comment


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

          Comment


          • #6
            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>

            Comment


            • #7
              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 :\

              Comment


              • #8
                It will reduce over time - we don't want to keep starting/stopping consumers.

                Comment


                • #9
                  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, 12:25 PM.

                  Comment


                  • #10
                    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..

                    Comment


                    • #11
                      Scaling back is enabled by setting max-messages-per-task to some value (the default is -1) which means unlimited.

                      The actual behavior of the task scheduling can be further tweaked by setting idle-task-execution-limit (how many times a consumer can go idle) and idle-consumer-limit (how many idle consumers are allowed). When max-messages-per-task is set, a consumer goes idle when that number of receives have been performed.

                      I suggest you read the javadocs for the DefaultMessageListenerContainer to get a full understanding of these settings. http://static.springsource.org/sprin...Container.html

                      Comment

                      Working...
                      X