Apache Camel concurrentConsumers vs threads

Ram*_*mki 3 apache-camel

i spent almost two days to understand the concept concurrentConsumers vs threads in Apache Camel. but i really don't understand the concept. could anyone help me to understand the concept. I am using camel 2.12.0.

   from("jms:queue:start?concurrentConsumers=5")
   .threads(3, 3, "replyThread")
   .bean(new SomeBean());

   pom.xml
   ==========================================  
   <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <camel.version>2.12.0</camel.version>
</properties>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.1</version>
        <scope>test</scope>
    </dependency>

    <!-- required by both client and server -->
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-core</artifactId>
        <version>${camel.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-spring</artifactId>
        <version>${camel.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-jms</artifactId>
        <version>${camel.version}</version>
    </dependency>

    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-test</artifactId>
        <version>${camel.version}</version>
    </dependency>

    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-activemq</artifactId>
        <version>1.1.0</version>
    </dependency>

    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-test-spring</artifactId>
        <version>2.12.1</version>
    </dependency>
</dependencies>


   //posting to queue
   for (int i = 0; i < 10; i++) {
      System.out.println(Thread.currentThread() + " sending request..." + i);
      template.asyncCallbackRequestBody("jms:queue:start", (body + " " + i), callback);
   } 

   //my call back
   public class MyCallback extends SynchronizationAdapter {

   @Override
   public void onComplete(Exchange exchange) {
      String body = exchange.getOut().getBody(String.class);
      System.out.println(Thread.currentThread() + " Callback Resposne..." +body);
 }
}

  public static class SomeBean {
    public void someMethod(Exchange body) {
        System.out.println(Thread.currentThread() + " Received: " + body.getIn().getBody());
        body.getOut().setBody(body.getIn().getBody());
    }
}
Run Code Online (Sandbox Code Playgroud)

my understanding(from apache camel documentation) is there will 5 competing consumers on jms:start queue to consume messages. and 3 "replyThreads" to process Async replies from jms:start queue. but actuall output is something different.

     Thread[main,5,main] sending request...0
     Thread[main,5,main] sending request...1
     Thread[Camel (camel-1) thread #9 - replyThread,5,main] Received: Hello Camel 0
     Thread[Camel (camel-1) thread #10 - replyThread,5,main] Received: Hello Camel 1
     Thread[Camel (camel-1) thread #5 - ProducerTemplate,5,main] Callback  Resposne...Hello Camel 0
     Thread[Camel (camel-1) thread #6 - ProducerTemplate,5,main] Callback Resposne...Hello Camel 1
Run Code Online (Sandbox Code Playgroud)

Cla*_*sen 5

JMS组件具有内置的线程池,该线程池可根据消息查询的数量来很好地上下扩展。

所以就用那个

 from("jms:queue:start?concurrentConsumers=5")
   .bean(new SomeBean());
Run Code Online (Sandbox Code Playgroud)

您还可以指定一个最大值,所以有一个范围

 from("jms:queue:start?concurrentConsumers=5&maxConcurrentConsumers=10")
   .bean(new SomeBean());
Run Code Online (Sandbox Code Playgroud)


Wil*_*ang 0

如果你想检查JMS线程池,你需要像这样改变路由

from("jms:queue:start?concurrentConsumers=5")
   .bean(new SomeBean())
   .threads(3, 3, "replyThread")
   .bean(new SomeBean());
Run Code Online (Sandbox Code Playgroud)

SomeBean 可以向您展示骆驼路由中使用了不同的线程池。