2017-08-23 8 views
3

私はSpring Boot 1.5.2.RELEASE + Camel(Spring Boot Starter)+ ActiveMQを使って非常に簡単なルートを試しています。 。しかし、それは別のURLに接続しようとしているURLに私のspring.activemq設定を取得していないように見えるし、それを接続し続け、私の春のブートアプリケーションは決して開始しません。Camel ActiveMQ + Springブートで読み込み中のspring activemqの設定がありません

  1. それはURL場合は永遠に接続しようとしないように、春のActiveMQの構成
  2. 設定maxReconnectAttemptsを許可するように設定を修正:質問は、私は以下行うことができますどのように下に提供しています私の設定に基づいていますActiveMQインスタンスがダウンした場合に可能な可能性があります。

ご協力いただけると幸いです。私はstackoverflow上の関連する質問を検索しましたが、私に直面している問題の解決策を教えてくれませんでした

エラーコンソールに表示されており、これは60-70試行と数え続けます。あなたはラクダが持ち直していることをブローカーのURLを見ることができるように、おそらく春はここ

Failed to connect to [tcp://localhost:61616] after: 10 attempt(s) continuing to retry. 

が私の現在の設定/コードされ、デフォルトで設定されたいくつかのデフォルトのURLです:

のpom.xml - 関連部分

<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.5.2.RELEASE</version> 
</parent> 

<dependencyManagement> 
    <dependencies> 
     <!-- Spring Cloud is part of the project where I am configuring camel routes --> 
     <dependency> 
      <groupId>org.springframework.cloud</groupId> 
      <artifactId>spring-cloud-dependencies</artifactId> 
      <version>Camden.SR5</version> 
      <type>pom</type> 
      <scope>import</scope> 
     </dependency> 

     <dependency> 
      <groupId>org.apache.camel</groupId> 
      <artifactId>camel-spring-boot-dependencies</artifactId> 
      <version>2.19.2</version> 
      <type>pom</type> 
      <scope>import</scope> 
     </dependency> 
    </dependencies> 
</dependencyManagement> 

<dependencies> 

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

    <!-- I have this as the same project works as a web app as well 
    and therefore I do not need the 
    camel.springboot.main-run-controller=true configuration to be set 
    which is as per camel's spring boot documentation--> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
    </dependency> 

    <!-- Camel - start --> 
    <dependency> 
     <groupId>org.apache.camel</groupId> 
     <artifactId>camel-spring-boot-starter</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.apache.activemq</groupId> 
     <artifactId>activemq-camel</artifactId> 
    </dependency> 
    <!-- Camel - end --> 

</dependencies> 

application.yml(Spring Boot ActiveMQProperties

spring: 
    activemq: 
    brokerUrl: tcp://my.company.host:[port] //This port is up and running 
    user: user 
    password: password 

はキャメルルートJAVA

package com.mycamel.route; 

import org.apache.camel.builder.RouteBuilder; 
import org.springframework.stereotype.Component; 

@Component 
public class SampleAmqCamelRouter extends RouteBuilder { 

    @Override 
    public void configure() throws Exception { 
     from("activemq:some.queue").to("log:com.mycamel.route?level=INFO&groupSize=10"); 
    } 

} 

答えて

2

まずで、あなたのpom.xmlにspring-boot-starter-activemq依存関係を追加する必要があります。次に、application.ymlで指定したプロパティに基づいてConnectionFactoryを作成するAutoConfiguration機能を使用できます。

その後、CamelのActiveMQComponentも設定する必要があります。あなたは(自動構成によって作成された)ConnectionFactoryを再利用したい場合、それは次のようで達成可能になります

@Configuration 
public class ActiveMQComponentConfig { 

    @Bean(name = "activemq") 
    public ActiveMQComponent createComponent(ConnectionFactory factory) { 
     ActiveMQComponent activeMQComponent = new ActiveMQComponent(); 
     activeMQComponent.setConnectionFactory(factory); 
     return activeMQComponent; 
    } 
} 

あなたはCamel's ActiveMQ documentationでより多くの情報を見つけることができます。

+0

ありがとうございました! "activemq" Beanを追加することはやりました。私はspring-boot-starter-activemqの依存関係を追加しましたが、それもうまくいきませんでした。両方の組み合わせは実際にトリックをしました。 – Sayantan

関連する問題