8

Springコンテキストで複数のリモートactivemqブローカー(異なるIPアドレス)を構成するにはどうすればよいですか?以下は、1つのリモートブローカーの構成です。私はラクダを使用して、複数のリモートブローカーの異なるキューとの間でメッセージを生成および消費するルートを作成しています。次のルートに基づいて、システムは各キューがどのリモートブローカーに属しているかをどのように知るのですか?

  • リストアイテム

    from( "direct:start")。to( "activemq:queue:outgoingRequests")

  • リストアイテム

    from( "activemq:queue:incomingOrders")。to( "log:Events?showAll = true")。to( "bean:jmsService")

1ブローカーorg.camel.routesのSpringコンテキスト

<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL" value="tcp://10.1.11.97: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="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
    <property name="configuration" ref="jmsConfig"/>
</bean>
4

2 に答える 2

17

異なる名前のコンポーネントを追加するだけです

<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
   <property name="configuration" ref="jmsConfig"/>
</bean>

<bean id="activemq2" class="org.apache.activemq.camel.component.ActiveMQComponent">
   <property name="configuration" ref="myOtherJmsConfig"/>
</bean>

次に、名前を使用します。

<from uri="activemq:queue:MY.QUEUE"/><!-- get from "1st" ActiveMQ -->
<to uri="activemq2:queue:MY.QUEUE"/> <!-- put to same queue name on other ActiveMQ -->

実際には、「EuropeanMarketBroker」など、好きなように呼び出すことができます。

于 2012-11-08T11:36:03.413 に答える
0

私のスプリング構成がxmlにないという違いで、これを達成しようとしています。いくつかの方法でスプリングアノテーションを使用することで同じ結果を達成できることを知っておくと役に立ちます。

これを実現するための鍵は、コンポーネントを目的の名前で登録することです。例えば:

camelContext.addComponent("activemq2", jmsComponentInstance);

これを実現するには2つの方法があります。つまり、相互に識別する修飾子を使用して2つのBeanを作成し、それらのBeanを配線して、コンポーネントとして登録します。または(これが望ましい)、Beanを作成し、コンポーネントを一度に登録することもできます。以下は両方の例です。

1-Beanを作成し、他の場所に登録します

@Configuration
public class ClassA{    
  @Bean @Qualifier("activemq2") public JmsComponent createJmsComponent(){
      return JmsComponent.jmsComponentAutoAcknowledge(..);//Initialise component from externalised configs
  }
}

@Component
public class ClassB{

  @Autowired private CamelContext camelContext;

  @Autowired @Qualifier("activemq2")
  private JmsComponent jmsComponent;

  public void someMethod(){
    camelContext.addComponent("activemq2", jmsComponent);
  }
}

2- Beanを作成し、@ConfigurationBean内の1つの場所に登録します。

@Bean @Autowired public JmsComponent createJmsComponent(CamelContext camelContext){
    JmsComponent component = JmsComponent.jmsComponentAutoAcknowledge(..);//Initialise component from externalised configs
    camelContext.addComponent("activemq2", component);//Add Component to camel context
    return component;//Return component instance
}
于 2017-01-09T15:02:15.060 に答える