如何使用以下代码中的“jmsQueueConsumer:queue:consumer.queue”消息:
CamelContext context1 = new DefaultCamelContext();
ConnectionFactory connectionFactory1 = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_BROKER_URL);
ConnectionFactory connectionFactory2 = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_BROKER_URL);
context1.addComponent("jmsQueueProducer", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory1));
context1.addComponent("jmsQueueConsumer", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory2));
context1.addRoutes(new RouteBuilder() {
public void configure() {
from("jmsQueueProducer:queue:producer.queue").to("jmsQueueConsumer:queue:consumer.queue");
}
});
ProducerTemplate template = context1.createProducerTemplate();
context1.start();
for (int i = 0; i < 10; i++) {
template.sendBody("jmsQueueProducer:queue:producer.queue", "Test Message: " + i);
}
答案 0 :(得分:0)
您可以配置另一条路线来处理它。例如:
from("jmsQueueConsumer:queue:consumer.queue")
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
// your processing code here
}
})
.to(any other endpoint)
此外,您可以将处理器单独提取为一个单独的类。