【问题标题】:Apache Camel Routing with Active MQ queue in a spring boot application在 Spring Boot 应用程序中使用 Active MQ 队列的 Apache Camel 路由
【发布时间】:2020-08-30 16:52:42
【问题描述】:

我对 spring-boot、apache camel 和 ActiveMQ broker 还是很陌生。我正在尝试创建一个应用程序,它将消息发送到我在本地使用 Camel 进行路由的队列。

当我运行应用程序时,我收到错误:

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:

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

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

        }

谁能指出我为什么会收到此错误的正确方向?非常感谢任何帮助。

【问题讨论】:

    标签: java spring-boot apache-camel activemq


    【解决方案1】:

    需要在POM.xml文件中添加camel-activemq

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

    【讨论】:

    【解决方案2】:

    您的应用程序不知道组件 activemq。要解决这个问题,您需要在 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-06-14
      • 2017-07-05
      • 1970-01-01
      • 2021-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多