Apache camel 将camel-spring引导、amqp和kafka启动器与SpringBoot一起使用时出现FailedToStartRouteException异常,无法找到connectionFactory bean

Apache camel 将camel-spring引导、amqp和kafka启动器与SpringBoot一起使用时出现FailedToStartRouteException异常,无法找到connectionFactory bean,apache-camel,spring-amqp,spring-camel,Apache Camel,Spring Amqp,Spring Camel,我正在使用ApacheCamel创建一个应用程序,以将消息从AMQP传输到Kafka。代码也可以在这里看到- 我想用spring、amqp和kafka初学者将其创建为独立的SpringBoot应用程序。创建了一条类似于 @Component public class QpidToKafkaRoute extends RouteBuilder { public void configure() throws Exception { from("amqp:queue:de

我正在使用ApacheCamel创建一个应用程序,以将消息从AMQP传输到Kafka。代码也可以在这里看到-

我想用spring、amqp和kafka初学者将其创建为独立的SpringBoot应用程序。创建了一条类似于

@Component
public class QpidToKafkaRoute extends RouteBuilder {

  public void configure() throws Exception {
      from("amqp:queue:destinationName")
              .to("kafka:topic");
  }
}
SpringBoot应用程序配置是

@springboot应用程序
公共类jmskafkaapplication{
公共静态void main(字符串[]args){
run(camelspringjmskafapplication.class,args);
}
@豆子
公共JmsConnectionFactory JmsConnectionFactory(@Value(${qpidUser})字符串qpidUser,@Value(${qpidPassword})字符串qpidPassword,@Value(${qpidBrokerUrl}”)字符串qpidBrokerUrl){
JmsConnectionFactory JmsConnectionFactory=新的JmsConnectionFactory(qpidPassword、qpidPassword、qpidBrokerUrl);
返回JMS连接工厂;
}
@豆子
@初级的
公用计算机连接工厂jmsCachingConnectionFactory(JmsConnectionFactory JmsConnectionFactory){
CachingConnectionFactory CachingConnectionFactory=新CachingConnectionFactory(jmsConnectionFactory);
返回cachingConnectionFactory;
}
使用SpringBean注释创建的JMSConnectionFactoryBean应该由AMQPStarter挑选并注入路由中。但这并没有发生。当我启动这个应用程序时,我遇到了以下异常-

org.apache.camel.FailedToStartRouteException: Failed to start route route1 because of Route(route1)[From[amqp:queue:destinationName] -> [To[kafka:.

Caused by: java.lang.IllegalArgumentException: connectionFactory must be specified
若我并没有错,那个么若我在application.properties文件中传递了正确的属性,那个么应该自动创建connectionFactory

我的application.properties文件如下所示:

camel.springboot.main-run-controller = true
camel.component.amqp.enabled = true
camel.component.amqp.connection-factory = jmsCachingConnectionFactory
camel.component.amqp.async-consumer = true
camel.component.amqp.concurrent-consumers = 1
camel.component.amqp.map-jms-message = true
camel.component.amqp.test-connection-on-startup = true
camel.component.kafka.brokers = localhost:9092
qpidBrokerUrl = amqp://localhost:5672?jms.username=guest&jms.password=guest&jms.clientID=clientid2&amqp.vhost=default
qpidUser = guest
qpidPassword = guest
你能不能帮我解释一下为什么在自动配置过程中没有使用connectionFactory对象?当我调试这段代码时,我可以清楚地看到ConnectionFactorybean正在被创建

我甚至可以看到更多的日志行-

CamelContext has only been running for less than a second. If you intend to run Camel for a longer time then you can set the property camel.springboot.main-run-controller=true in application.properties or add spring-boot-starter-web JAR to the classpath.
但是,如果您看到my application.properties文件,则必需的属性出现在第一行

还有一行日志,我可以在应用程序启动开始时看到-

[main] trationDelegate$BeanPostProcessorChecker : Bean 'org.apache.camel.spring.boot.CamelAutoConfiguration' of type [org.apache.camel.spring.boot.CamelAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
这条记录线有什么提示吗


注意-一个有趣的事实是,昨晚完全相同的代码运行良好,只是重新启动了我的桌面,甚至没有一个单词被更改,现在它抛出异常。

这只是指一个接口

camel.component.amqp.connection-factory = javax.jms.ConnectionFactory
相反,它应该引用现有的工厂实例,例如

camel.component.amqp.connection-factory = #myFactory

您可以通过spring boot
@Bean
注释样式设置它。

您可以发布完整的异常吗?您有两个jms连接工厂-即使您在其中一个上指定了primary,注册表中仍有两个。因此您需要配置要使用的jms Camel组件。或者将代码更改为只有一个jms连接工厂connection factory@bean非常感谢您的回答。注释一个连接工厂解决了这个问题。但是,它提出了两个问题-1.它不应该按照camel.component.amqp.connection-factory=jmsCachingConnectionFactory中提到的连接工厂bean名称来查找吗?似乎amqp starter没有使用amqp相关的proapplication.properties中提到的perty值。2.为什么我们需要将amqpmonent注册为bean,这不应该是camel amqp starter使用application.properties中提供的属性创建一个bean的工作吗?检查工作代码。