使用Service Mix路由队列

时间:2012-03-15 06:56:20

标签: apache-camel activemq apache-servicemix

我正在尝试配置Apache ServiceMix以实现以下网络拓扑:

enter image description here

我在Service Mix,Camel,ActiveMq等方面很新,我试图解决的主要问题是将消息从DC1.ActiveMqBroker的输出队列路由到DC2.ActiveMqBroker的Input队列。

我确信这应该很容易。有人能指出我的好文章或编写粗略的配置片段(在Spring / Blueprint中,无所谓)?

更新

很抱歉长篇文章,但我没有看到其他方式来解释我的问题。

我的示例配置:                                                                                                                                                                                                                                    

<broker xmlns="http://activemq.apache.org/schema/core" brokerName="dc2" dataDirectory="${karaf.data}/activemq/dc2" useShutdownHook="false">
    <destinationPolicy>
        <policyMap>
            <policyEntries>
                <policyEntry queue="input" producerFlowControl="true" memoryLimit="1mb"/>
                <policyEntry queue="output" producerFlowControl="true" memoryLimit="1mb"/>
            </policyEntries>
        </policyMap>
    </destinationPolicy> 
    <managementContext>
        <managementContext createConnector="false"/>
    </managementContext>
    <persistenceAdapter>
        <kahaDB directory="${karaf.data}/activemq/dc2/kahadb"/>
    </persistenceAdapter>
    <transportConnectors>
        <transportConnector name="openwire" uri="tcp://localhost:61619"/>
    </transportConnectors>
</broker>

<bean id="dc1activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
    <property name="brokerURL" value="tcp://localhost:61619" />
</bean>

<bean id="dc2activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
    <property name="brokerURL" value="tcp://localhost:61618" />
</bean>

<camelContext xmlns="http://camel.apache.org/schema/blueprint">
    <route>
        <from uri="dc1activemq:queue:output"/>
        <log message="Took message from dc1 to dc2"/>
        <to uri="dc2activemq:queue:input"/>
    </route>
</camelContext>

我经常遇到以下错误:

08:06:40,739 | INFO  | rint Extender: 3 | Activator                        | ?                                   ? | 68 - or
g.apache.camel.camel-core - 2.6.0 | Found 1 @Converter classes to load
08:06:40,740 | INFO  | rint Extender: 3 | Activator                        | ?                                   ? | 68 - or
g.apache.camel.camel-core - 2.6.0 | Found 1 @Converter classes to load
08:06:40,741 | INFO  | rint Extender: 3 | Activator                        | ?                                   ? | 68 - or
g.apache.camel.camel-core - 2.6.0 | Found 1 @Converter classes to load
08:06:40,741 | INFO  | rint Extender: 3 | Activator                        | ?                                   ? | 68 - or
g.apache.camel.camel-core - 2.6.0 | Found 2 @Converter classes to load
08:06:40,749 | INFO  | rint Extender: 3 | Activator                        | ?                                   ? | 68 - or
g.apache.camel.camel-core - 2.6.0 | Found 13 @Converter classes to load
08:06:40,754 | INFO  | rint Extender: 3 | BlueprintCamelContext            | ?                                   ? | 68 - or
g.apache.camel.camel-core - 2.6.0 | JMX enabled. Using ManagedManagementStrategy.
08:06:40,758 | INFO  | rint Extender: 3 | BlueprintCamelContext            | ?                                   ? | 68 - or
g.apache.camel.camel-core - 2.6.0 | Apache Camel 2.6.0 (CamelContext: 211-camel-165) is starting
08:06:42,364 | INFO  | rint Extender: 3 | BlueprintCamelContext            | ?                                   ? | 68 - or
g.apache.camel.camel-core - 2.6.0 | Route: route55 started and consuming from: Endpoint[dc1activemq://queue:output]
08:06:42,364 | INFO  | rint Extender: 3 | BlueprintCamelContext            | ?                                   ? | 68 - or
g.apache.camel.camel-core - 2.6.0 | Total 1 routes, of which 1 is started.
08:06:42,365 | INFO  | rint Extender: 3 | BlueprintCamelContext            | ?                                   ? | 68 - or
g.apache.camel.camel-core - 2.6.0 | Apache Camel 2.6.0 (CamelContext: 211-camel-165) started in 1.606 seconds
08:06:48,379 | WARN  | tenerContainer-1 | DefaultMessageListenerContainer  | ?                                   ? | 77 - or
g.springframework.jms - 3.0.5.RELEASE | Could not refresh JMS Connection for destination 'output' - retrying in 5000 ms. Cau
se: Could not connect to broker URL: tcp://localhost:61619. Reason: java.net.ConnectException: Connection refused: connect
08:06:54,381 | WARN  | tenerContainer-1 | DefaultMessageListenerContainer  | ?                                   ? | 77 - or
g.springframework.jms - 3.0.5.RELEASE | Could not refresh JMS Connection for destination 'output' - retrying in 5000 ms. Cau
se: Could not connect to broker URL: tcp://localhost:61619. Reason: java.net.ConnectException: Connection refused: connect

1 个答案:

答案 0 :(得分:1)

我假设你已经掌握了Camel如何在ServiceMix中启动并且有一些(至少)概念验证路线......如果没有,start there。还假设您知道2个消息代理的URL,并且它们已经设置好了。

鉴于此,一种解决方案是注册两个ActiveMQComponents:

<bean id="dc1activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
   <property name="brokerURL" value="tcp://DC1BrokerLocation:12345" />
</bean>

<bean id="dc2activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
   <property name="brokerURL" value="tcp://DC2BrokerLocation:12345" />
</bean>

然后在你的骆驼背景中:

<camelContext xmlns="http://camel.apache.org/schema/blueprint">
   <route>
      <from uri="dc1activemq:queue:whateverTheOutQueueIsCalled"/>
      <log message="Took message from dc1 to dc2"/>
      <to uri="dc2activemq:queue:whateverTheInQueueIsCalled"/>
   </route>
   <route>
      <from uri="dc2activemq:queue:whateverTheOutQueueIsCalled"/>
      <log message="Took message from dc2 to dc1"/>
      <to uri="dc1activemq:queue:whateverTheInQueueIsCalled"/>
   </route>
<camelContext>