【发布时间】:2017-03-02 10:57:19
【问题描述】:
- 我正在使用 apache camel 从队列中接收所有消息。但是我 需要提到线程的睡眠时间才能运行骆驼上下文。
- 现在的问题是它只消耗一些消息,即。内 指定睡眠时间。
- 如果我增加睡眠时间,那么它将路由所有消息,但是 它一直等到睡眠时间结束才终止程序。
- 我需要的是,骆驼应该路由队列中的所有消息 然后它应该立即终止。
有没有什么方法可以在不使用java DSL指定线程睡眠时间的情况下运行骆驼?
示例代码:
import javax.jms.ConnectionFactory;
import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jms.JmsComponent;
import org.apache.camel.impl.DefaultCamelContext;
public class SplitJson {
public static void main(String[] args) {
try {
CamelContext context = new DefaultCamelContext();
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("admin", "admin",
ActiveMQConnection.DEFAULT_BROKER_URL);
context.addComponent("test-jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
context.addRoutes(new RouteBuilder() {
public void configure() {
from("test-jms:queue:testMQDestination")
.choice()
.when().jsonpath("$.[?(@.Status == 'YetToStart')]")
.to("test-jms:queue:YetToStart")
.when().jsonpath("$.[?(@.Status == 'Started')]]")
.to("test-jms:queue:Started")
.when().jsonpath("$.[?(@.Status == 'Completed')]]")
.to("test-jms:queue:Completed")
.otherwise()
.to("test-jms:queue:Others")
.end();
}
});
context.start();
Thread.sleep(10000);
context.stop();
System.out.println("Done");
} catch (Exception e) {
e.printStackTrace();
}
}
}
【问题讨论】:
-
为什么不在代理端使用destinationInterceptors activemq.apache.org/virtual-destinations.html 或activemq.apache.org/broker-camel-component.html ?您可以在使用destinationInterceptors 时编辑配置,而无需在使用此插件时重新启动代理activemq.apache.org/runtime-configuration.html
-
你不需要睡觉。您只需要确保 CamelContext 永远运行。 camel.apache.org/…
-
@SoucianceEqdamRashti 但是在路由队列中的所有消息后需要终止执行
-
只要停止路线内的一切。有一个 EIP。
标签: java apache-camel activemq