Apache camel Apache Camel concurrentConsumers与线程
我花了将近两天的时间来理解ApacheCamel中concurrentConsumers与threads的概念。但我真的不明白这个概念。有人能帮我理解这个概念吗。我正在使用camel 2.12.0Apache camel Apache Camel concurrentConsumers与线程,apache-camel,Apache Camel,我花了将近两天的时间来理解ApacheCamel中concurrentConsumers与threads的概念。但我真的不明白这个概念。有人能帮我理解这个概念吗。我正在使用camel 2.12.0 from("jms:queue:start?concurrentConsumers=5") .threads(3, 3, "replyThread") .bean(new SomeBean()); pom.xml ============================
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());
}
}
如果要检查JMS线程池,则需要像下面这样更改路由
from("jms:queue:start?concurrentConsumers=5")
.bean(new SomeBean())
.threads(3, 3, "replyThread")
.bean(new SomeBean());
SomeBean可以向您展示驼峰路由中使用了不同的线程池。JMS组件具有内置的线程池,它可以根据向上查询的消息数量进行很好的上下扩展 所以就用这个吧
from("jms:queue:start?concurrentConsumers=5")
.bean(new SomeBean());
您还可以指定一个最大值,以便有一个范围
from("jms:queue:start?concurrentConsumers=5&maxConcurrentConsumers=10")
.bean(new SomeBean());
你真的不需要第二个线程池,只要使用JMS中的线程池就可以了。啊,再往下看一点。它说从Camel 2.10.3开始,您不再需要threads()。感谢您的快速回复。当我在@Section“Request-reply over JMS”中读到这篇文档时,我感到困惑。线程(5)需要定义我们是否要处理异步回复。应该提到的是,如果使用者最终应该缩小规模,那么还必须使用“maxMessagesPerTask”参数。
from("jms:queue:start?concurrentConsumers=5&maxConcurrentConsumers=10")
.bean(new SomeBean());