0

如何使用以下代码中的“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);
        }
4

1 回答 1

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)

此外,您可以将处理器本身提取为单独的类。

于 2013-09-18T12:01:59.627 回答