1

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

有人可以指出我做错了什么的骆驼文档。感谢您的帮助。

这是简化的代码。

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
4

1 回答 1

2

从堆栈跟踪中可以清楚地看出,未指定 ActiveMQ 连接工厂是一个问题。

配置可以在 Spring XML 中完成。

请查看 jms 页面 - Apache Camel:JMS

于 2013-03-13T08:43:17.523 回答