Apache Camel JMS:如何使用Java DSL使用JNDI连接发布或订阅队列?

问题描述 投票:0回答:1

我正在尝试使用骆驼从JBoss EAP 7.0连接到JMS队列。我使用Java DSL而不是Spring。如何获取JNDI条目并创建连接以侦听或调度消息?以下是我通常用于连接到ActiveMQ的代码段!

CamelContext context = new DefaultCamelContext();
context.addComponent("activemq", ActiveMQComponent.activeMQComponent("tcp://localhost:61616"));
context.addRoutes(new RouteBuilder() {
    public void configure() {
        from("direct:writeQueue").to("activemq:queue:FOO");
    }
});
context.start();
Thread.sleep(2000);
ProducerTemplate producer = context.createProducerTemplate();
producer.sendBody("activemq:queue:FOO", "Test Message");

我尝试添加如下代码:

CamelContext context = null;
@Resource(mappedName = "java:/jboss/exported/jms/queue/TestQ")
private ConnectionFactory connectionFactory;
public void testJMS() throws Exception {

    context = new DefaultCamelContext();
    JmsComponent component = new JmsComponent();
    component.setConnectionFactory(connectionFactory);
    context.addComponent("jms", component);
    /*
    Routing Section
    */
}

但是此代码给了我类似[connectionFactory must not be null]的错误>

我正在尝试使用骆驼从JBoss EAP 7.0连接到JMS队列。我使用Java DSL而不是Spring。如何获取JNDI条目并创建连接以侦听或调度消息?以下是...

java apache-camel jms dsl
1个回答
0
投票

这是我在JBoss ... Wildfly中所做的工作:

© www.soinside.com 2019 - 2024. All rights reserved.