到 ActiveMQ 目的地的骆驼路线

Camel route to ActiveMQ destination


我正在尝试在 ActiveMQ 上设置从文件系统到 JMS 目标 运行 的基本路由。我的 ActiveMQ 服务器在使用默认设置的本地主机上 运行,并且在“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

我尝试了 "to" 路线的其他变体,例如 "activemq:queue:activemq/queue/TestQueue" 但没有成功。知道如何让它工作吗?
谢谢

由于您将 JMS 组件命名为 jms,您需要按如下方式引用队列:

"jms:queue:TestQueue"

而不是

<strike>"activemq:queue:TestQueue"</strike>

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

您可能缺少依赖项:

<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>