Camel JMS未能创建制作人

时间:2013-03-13 08:23:53

标签: jms apache-camel

我对Camel来说相当新,并且一直在尝试使用requestBody但是一直出错。我简化了我的代码并仍然得到了相同的异常。如果我的猜测是正确的,那么关键可能是“无法为端点创建生产者”这一消息,但我不知道如何使用Java DSL来做到这一点。

有人可以指点我看看我做错了什么的Camel文档。谢谢你的帮助。

这是简化的代码。

package nz.co.home.cameljmsrequest;

import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.activemq.ActiveMQComponent;
import org.apache.camel.impl.DefaultCamelContext;

public class App {

    public static void main(String[] args) throws Exception {

        // set up the underlying camel context and add the ActiveMQ component
        CamelContext camelContext = new DefaultCamelContext();
        camelContext.addComponent(
                "jms",
                ActiveMQComponent.activeMQComponent("tcp://192.168.1.150:61616")
                );

        // start the context
        camelContext.start();

        // send the message
        ProducerTemplate producer = camelContext.createProducerTemplate();
        String requestBody = producer.requestBody("jms:queue:test", 
                "Request Message", String.class);
        System.out.println(requestBody);

        // stop the context
        camelContext.stop();

        // just because we can
        System.out.println("sent message");
    }
}

生成的消息如下所示:

Exception in thread "main" org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[Message: Request Message]
    at org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1287)
    at org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:618)
    at org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:454)
    at org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:120)
    at org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:136)
    at org.apache.camel.impl.DefaultProducerTemplate.requestBody(DefaultProducerTemplate.java:284)
    at org.apache.camel.impl.DefaultProducerTemplate.requestBody(DefaultProducerTemplate.java:314)
    at nz.co.home.cameljmsrequest.App.main(App.java:23)
Caused by: org.apache.camel.FailedToCreateProducerException: Failed to create Producer for endpoint: Endpoint[jms://queue:testCamelActiveMq]. Reason: java.lang.IllegalArgumentException: connectionFactory must be specified
    at org.apache.camel.component.jms.JmsProducer.initReplyManager(JmsProducer.java:98)
    at org.apache.camel.component.jms.JmsProducer.processInOut(JmsProducer.java:164)
    at org.apache.camel.component.jms.JmsProducer.process(JmsProducer.java:129)
    at org.apache.camel.processor.UnitOfWorkProcessor.processAsync(UnitOfWorkProcessor.java:150)
    at org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:117)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:99)
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:86)
    at org.apache.camel.processor.UnitOfWorkProducer.process(UnitOfWorkProducer.java:63)
    at org.apache.camel.impl.ProducerCache$2.doInProducer(ProducerCache.java:366)
    at org.apache.camel.impl.ProducerCache$2.doInProducer(ProducerCache.java:337)
    at org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:233)
    at org.apache.camel.impl.ProducerCache.sendExchange(ProducerCache.java:337)
    at org.apache.camel.impl.ProducerCache.send(ProducerCache.java:192)
    at org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:115)
    at org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:119)
    ... 4 more
Caused by: java.lang.IllegalArgumentException: connectionFactory must be specified
    at org.apache.camel.util.ObjectHelper.notNull(ObjectHelper.java:290)
    at org.apache.camel.component.jms.JmsConfiguration.createConnectionFactory(JmsConfiguration.java:1052)
    at org.apache.camel.component.jms.JmsConfiguration.getConnectionFactory(JmsConfiguration.java:415)
    at org.apache.camel.component.jms.JmsEndpoint.getConnectionFactory(JmsEndpoint.java:468)
    at org.apache.camel.component.jms.reply.TemporaryQueueReplyManager.createListenerContainer(TemporaryQueueReplyManager.java:115)
    at org.apache.camel.component.jms.reply.ReplyManagerSupport.doStart(ReplyManagerSupport.java:222)
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:62)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:52)
    at org.apache.camel.component.jms.JmsProducer.createReplyManager(JmsProducer.java:503)
    at org.apache.camel.component.jms.JmsProducer.initReplyManager(JmsProducer.java:94)
    ... 18 more

1 个答案:

答案 0 :(得分:1)

从堆栈跟踪中可以清楚地看出,没有指定ActiveMQ connectionFactory是一个问题。

配置可以在Spring XML中完成。

请查看jms页面 - Apache Camel:JMS