2015-11-26 8 views
8

私はいくつかの例で気づきましたが、キャメルでactivemqを設定する一般的な方法は次のようなものです。 Spring Bootが既定でこれらのBeanを既に設定しているかどうかを知りたいと思います。 Activemq jarがクラスパス上にある場合、デフォルトの接続ファクトリが作成されますが、以下のすべてについてはどうでしょうか?キャメルとActivemqのスプリングブートによる設定

<bean id="jmsConnectionFactory" 
     class="org.apache.activemq.ActiveMQConnectionFactory"> 
    <property name="brokerURL" value="tcp://localhost:61616"/> 
    </bean> 

    <bean id="pooledConnectionFactory" 
     class="org.apache.activemq.pool.PooledConnectionFactory" 
     init-method="start" destroy-method="stop"> 
    <property name="maxConnections" value="8"/> 
    <property name="connectionFactory" ref="jmsConnectionFactory"/> 
    </bean> 

    <bean id="jmsConfig" 
     class="org.apache.camel.component.jms.JmsConfiguration"> 
    <property name="connectionFactory" ref="pooledConnectionFactory"/> 
    <property name="concurrentConsumers" value="10"/> 
    </bean> 

    <bean id="jms" 
     class="org.apache.activemq.camel.component.ActiveMQComponent"> 
    <property name="configuration" ref="jmsConfig"/> 
    <property name="transacted" value="true"/> 
    <property name="cacheLevelName" value="CACHE_CONSUMER"/> 
    </bean> 

または

@Bean 
    public ActiveMQConnectionFactory getConnectionFactory() { 
     ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(); 
     connectionFactory.setBrokerURL(brokerURL); 
     return connectionFactory; 
    } 

    @Bean(initMethod = "start", destroyMethod = "stop") 
    public PooledConnectionFactory getPooledConnectionFactory() { 
     PooledConnectionFactory pooledConnectionFactory = new PooledConnectionFactory(); 
     pooledConnectionFactory.setMaxConnections(maxConnections); 
     pooledConnectionFactory.setConnectionFactory(getConnectionFactory()); 
     return pooledConnectionFactory; 
    } 

    @Bean 
    public JmsConfiguration getJmsConfiguration() { 
     JmsConfiguration jmsConfiguration = new JmsConfiguration(); 
     jmsConfiguration.setConnectionFactory(getPooledConnectionFactory()); 
     return jmsConfiguration; 
    } 

    @Bean 
    public JmsConfiguration getJmsHighPriorityConfiguration() { 
     JmsConfiguration jmsConfiguration = new JmsConfiguration(); 
     jmsConfiguration.setConnectionFactory(getPooledConnectionFactory()); 
     jmsConfiguration.setPriority(8); 
     return jmsConfiguration; 
    } 

    @Override 
    protected void setupCamelContext(CamelContext camelContext) throws Exception { 
     ActiveMQComponent activeMQComponent = new ActiveMQComponent(); 
     activeMQComponent.setConfiguration(getJmsConfiguration()); 
     camelContext.addComponent("activemq", activeMQComponent); 

     ActiveMQComponent activeMQHighPriorityComponent = new ActiveMQComponent(); 
     activeMQHighPriorityComponent.setConfiguration(getJmsHighPriorityConfiguration()); 
     camelContext.addComponent("activemq-high-priority", activeMQHighPriorityComponent); 
    } 

答えて

1

一方のActiveMQやキャメルは春ブーツの中に実行されているために使用することができ、いくつかのspring-boot-startersがあります。あなたのポンポンでspring-boot-starter-activemq

ActiveMQの

スタート:

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

設定

がすべてでこのを通じて、設定何見てみる - そのAppendix A. Common application propertiesに文書( 'を検索activemq 'と' jms ')。

代替アプローチ:スプリントのブートに設定可能ですかを決定するために私の視点から、その最高のものを自分のauto-configurationメカニズムを見て持っているではない:

キャメルを設定することができるActiveMQの固有特性を決定互いに

  • ActiveMQProperties

    Apache Camelは独自のSpring Boot integrationを提供しています。基本的に、あなたはまた、camel-spring-boot-starterを追加する必要があります。私は再び、良い例の設定ファイルを発見していない

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

    フィギュレーション、コンフィギュレーションを見てはCamelConfigurationPropertiesクラスを介して公開されています。

    一般的に言えば、この設定で公開されているすべてのプロパティが見つからない場合は、手動でBeanの一部を登録することになります。

  • 関連する問題