简体   繁体   English

Apache 骆驼上下文启动失败

[英]Apache Camel Context start failure

I am pretty new to Spring Boot, Apache Camel and the ActiveMQ broker.我对 Spring Boot、Apache Camel 和 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 进行路由。

POM:聚甲醛:

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

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

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

MsgRouteBuilder: 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:主应用程序.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);

  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...");
  }  
}

MyController.java:我的控制器.java:

@GetMapping(value = "/routing")
public boolean sendToMyQueue() {
    sendMyInfo.startRouting();
    return true;
}

SendMyInfo.java: SendMyInfo.java:

MsgRouteBuilder routeBuilder = new MsgRouteBuilder();
CamelContext ctx = new DefaultCamelContext();


public void startRouting(){

    try {
        ctx.addRoutes(routeBuilder);
        ctx.start();
        Thread.sleep(5 * 60 * 1000);
        ctx.stop();
    }
    catch (Exception e) {
        e.printStackTrace();
    }

}

So, whenever I call my rest end point: /routing , I get the error:因此,每当我调用我的 rest 端点: /routing时,我都会收到错误消息:

java.lang.NoSuchMethodError: org.apache.camel.RuntimeCamelException.wrapRuntimeException(Ljava/lang/Throwable;)Ljava/lang/RuntimeException;`

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 have the components of the same version.您需要具有相同版本的组件。 If you are using camel-core with 3.2.0, use camel-activemq 3.2.0.如果您使用 3.2.0 的 camel-core,请使用 camel-activemq 3.2.0。 And, since you are using spring-boot, you can make use of the starter dependencies.而且,由于您使用的是 spring-boot,因此您可以使用入门依赖项。 Just add these and you are good to go.只需添加这些,您就可以使用 go。

<dependency>
    <groupId>org.apache.camel.springboot</groupId>
    <artifactId>camel-spring-boot-starter</artifactId>
    <version>3.2.0</version>
</dependency>
<dependency>
    <groupId>org.apache.camel.springboot</groupId>
    <artifactId>camel-activemq-starter</artifactId>
    <version>3.2.0</version>
</dependency>

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

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