骆驼路线到ActiveMQ目的地

时间:2015-02-01 21:02:54

标签: apache-camel


我正在尝试建立从文件系统到在ActiveMQ上运行的JMS目标的基本路由。我的ActiveMQ服务器使用默认设置在localhost上运行,并且在" activemq / queue / TestQueue "中有一个可用的队列。 所以我编写了以下Java路由:

public static void main(String args[]) throws Exception {
    CamelContext context = new DefaultCamelContext();
    ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
            "vm://localhost");
    context.addComponent("jms",
            JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
    context.addRoutes(new RouteBuilder() {
        public void configure() {
            from("file:D:\\camel\\in").to(
                    "activemq:queue:TestQueue");
        }
    });
    context.start();
    Thread.sleep(10000);
    context.stop();
}

不幸的是,引发了以下异常:

Exception in thread "main" org.apache.camel.FailedToCreateRouteException: Failed to create route route1 at: >>> To[activemq:queue:TestQueue] <<< in route: Route(route1)[[From[file:D:\camel\in]] -> [To[activemq:queue... because of Failed to resolve endpoint: activemq://queue:TestQueue due to: 
No component found with scheme: activemq
        at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:945)
    . . . .
    Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: activemq://queue:TestQueue due to: No component found with scheme: activemq

我尝试了其他一些变体&#34; to&#34;路由,例如&#34; activemq:queue:activemq / queue / TestQueue&#34;没有成功。知道如何让它工作吗?
感谢

3 个答案:

答案 0 :(得分:3)

您可能错过了依赖项:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-jms</artifactId>
    <version>2.18.1</version>
</dependency>
<dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>activemq-camel</artifactId>
    <version>5.6.0</version>
</dependency> 

答案 1 :(得分:2)

在命名JMS组件jms时,需要按如下方式引用队列:

"jms:queue:TestQueue"

而不是

"activemq:queue:TestQueue"

答案 2 :(得分:2)

您必须使用“tcp://0.0.0.0:61616”协议连接到外部ActiveMQ服务器。此外,发布到“vm:”后,您没有任何错误消息,这很奇怪。您是否在项目中包含了所有slfj日志库?