简体   繁体   English

Apache 在 spring 引导应用程序中使用活动 MQ 队列的骆驼路由

[英]Apache Camel Routing with Active MQ queue in a spring boot application

I am pretty new to spring-boot, apache camel and ActiveMQ broker.我对 spring-boot、apache 骆驼和ActiveMQ代理很陌生。 I am trying to create an application which will send a message to a queue which I am hosting locally using Camel for routing.我正在尝试创建一个应用程序,它将消息发送到我在本地使用 Camel 进行路由的队列。

When I run the app, I get the error:当我运行应用程序时,我收到错误:

ERROR org.apache.camel.FailedToCreateRouteException: Failed to create route route1 at: >>> To[activemq:queue:myQueue] <<< in route: Route(route1)[[From[direct:firstRoute]] -> [SetBody[constant... because of Failed to resolve endpoint: activemq://queue:myQueue due to: No component found with scheme: activemq

POM:聚甲醛:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-activemq</artifactId>
    </dependency>


   <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-spring-boot-starter</artifactId>
      <version>2.22.0</version>
   </dependency>
   <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-core</artifactId>
      <version>2.22.0</version>
   </dependency>

MsgRouteBuilder:消息路由生成器:

public void configure() throws Exception {
    from("direct:firstRoute")
    .setBody(constant("Hello"))
    .to("activemq:queue:myQueue");
}

application.yaml:应用程序.yaml:

activemq:
    broker-url: tcp://localhost:61616
    user: meAd
    password: meAd

MainApp.java: MainApp.java:

        package me.ad.myCamel;

        import org.apache.camel.CamelContext;
        import org.slf4j.Logger;
        import org.slf4j.LoggerFactory;
        import org.springframework.beans.factory.annotation.Autowired;
        import org.springframework.boot.CommandLineRunner;
        import org.springframework.boot.SpringApplication;
        import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
        import org.springframework.boot.autoconfigure.SpringBootApplication;
        import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
        import org.springframework.cache.annotation.EnableCaching;
        import org.springframework.context.annotation.Bean;
        import org.springframework.context.annotation.EnableAspectJAutoProxy;

        import me.ad.myCamel.router.MessageRouteBuilder;

        @SpringBootApplication
        @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
        @EnableAspectJAutoProxy(proxyTargetClass = true)
        @EnableCaching
        public class MeAdApp implements CommandLineRunner {

          private static final Logger LOG = LoggerFactory.getLogger(MeAdApp.class);

          @Autowired
          private CamelContext camelContext;

          public static void main(String[] args) {
            try {
              SpringApplication.run(MeAdApp.class, args);
            } catch (Exception ex) {
              LOG.error(ex.getMessage(), ex);
            }
          }

          @Override
          public void run(String... args) throws Exception {
            LOG.info("Starting MeAdApp...");
          }

          @Bean
          public MsgRouteBuilder msgRouteBuilder() throws Exception {
            MsgRouteBuilder routeBuilder = new MsgRouteBuilder();
            camelContext.addRoutes(routeBuilder);
            return routeBuilder;
          }

        }

Can anybody please point me to the right direction as to why I am getting this error?谁能指出我为什么会收到此错误的正确方向? Any help is greatly appreciated.任何帮助是极大的赞赏。

You need to add camel-activemq in the POM.xml file需要在POM.xml文件中添加camel-activemq

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-activemq</artifactId>
    <version>3.2.0</version>
</dependency>

Your application doesn't know the component activemq.您的应用程序不知道组件 activemq。 To resolve that, you need to add the dependency of camel-activemq in your pom.xml file:要解决这个问题,您需要在 pom.xml 文件中添加 camel-activemq 的依赖项:

<properties>
        ...
        <activemq.version>3.1.0</activemq.version>
</properties>

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-activemq</artifactId>
    <version>${activemq.version}</version>
</dependency>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM