[英]Getting message through Apache Camel?
我必须将骆驼集成到activemq的消费者方面。 我已经设置了activemq并尝试在消费者语言上配置骆驼(使用Java DSL),但是它对我不起作用。 这是代码:
public class TestConsumer {
static String url = ActiveMQConnection.DEFAULT_BROKER_URL;
static String subject = "Test-AMQ";
public static void main(String[] args) throws Exception {
CamelContext context = new DefaultCamelContext();
BrokerService broker = new BrokerService();
//broker.addConnector(url);
//broker.setBrokerName("localhost");
broker.start();
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?create=false&waitForStart=10000");
context.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
context.addRoutes(new Routes());
context.start();
}
}
class Routes extends RouteBuilder {
@Override
public void configure() throws Exception {
from("jms:"+new TestConsumer().subject).process(new Processor() {
@Override
public void process(Exchange arg0) throws Exception {
System.out.println("Camel Test Message: " + arg0.toString());
}
});
}
}
一个类似于您的示例。
import org.apache.activemq.ActiveMQConnection;
//import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.camel.component.ActiveMQComponent;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
public class TestConsumer {
static String url = ActiveMQConnection.DEFAULT_BROKER_URL;
static String subject = "Test-AMQ";
public static void main(String[] args) throws Exception {
CamelContext context = new DefaultCamelContext();
// BrokerService broker = new BrokerService();
// broker.start();
ActiveMQComponent comp = ActiveMQComponent.activeMQComponent("vm://localhost?broker.persistent=false");
context.addComponent("jms",comp);
context.addRoutes(new Routes());
context.start();
}
}
class Routes extends RouteBuilder {
@Override
public void configure() throws Exception {
from("jms:"+TestConsumer.subject).process(new Processor() {
@Override
public void process(Exchange arg0) throws Exception {
System.out.println("Camel Test Message: " + arg0.toString());
}
});
from("timer://foo?fixedRate=true&period=2000").setBody(simple("Hello, World")).to("jms:"+TestConsumer.subject);
}
}
不确定最终如何进行设置。 实际上,使用VM传输不需要您启动专门的代理,而是使用一个in VM实例。 我只是简单地设置了一个计时器路由,以将一些示例消息发送到该ActiveMQ队列,这将被消耗。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.