如何在Apache Camel中以JMS组件的格式定义ActiveMQ组件

时间:2013-10-04 10:48:26

标签: apache-camel

我正在使用Apache Camel 2.11.1。似乎两个xml定义在Camel中都不相同:

第一个定义:

<bean id="amq" class="org.apache.activemq.camel.component.ActiveMQComponent"
    p:brokerURL="tcp://localhost:61616" p:transacted="true"
    p:cacheLevelName="CACHE_CONSUMER" p:concurrentConsumers="20"
    p:maxConcurrentConsumers="500" p:idleConsumerLimit="10" />

第二个定义:

<bean id="amq" class="org.apache.camel.component.jms.JmsComponent"
    p:configuration-ref="jmsConfig" p:transacted="true" p:cacheLevelName="CACHE_CONSUMER" />

<bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration"
    p:connectionFactory-ref="nakedConnectionFactory"
    p:concurrentConsumers="20" p:maxConcurrentConsumers="500"
    p:idleConsumerLimit="10" />

<bean id="nakedConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"
    p:brokerURL="tcp://localhost:61616" />

由于第一个定义在以下路线上运行良好,但第二个定义不适用。

<route>
    <from uri="amq:example.MyQueue" />
    <setHeader headerName="myRoutingSlipHeader">
        <constant>amq:one#amq:two#amq:three#amq:four</constant>
    </setHeader>
    <log message="Makan" />
    <setExchangePattern pattern="InOut" />
    <routingSlip uriDelimiter="#">
        <header>myRoutingSlipHeader</header>
    </routingSlip>
    <setExchangePattern pattern="InOnly" />
    <log message="End: ${body}" />
</route>

<route>
    <from uri="amq:one" />
    <to uri="bean:helloBean?method=stepOne" />
</route>

<route>
    <from uri="amq:two" />
    <to uri="bean:helloBean?method=stepTwo" />
</route>

<route>
    <from uri="amq:three" />
    <to uri="bean:helloBean?method=stepThree" />
</route>

<route>
    <from uri="amq:four" />
    <to uri="bean:helloBean?method=stepFour" />
</route>

第二个组件定义导致执行期间挂起。

1 个答案:

答案 0 :(得分:0)

似乎对我来说很好。我必须用创建的原型覆盖spring版本。但是我用它并且它工作正常。

请在此处找到我的示例项目: https://github.com/jimternet/camel-activemq

<broker xmlns="http://activemq.apache.org/schema/core" useJmx="true"
    persistent="false">
    <transportConnectors>
        <transportConnector uri="tcp://localhost:61616" />
    </transportConnectors>
</broker>

<camelContext xmlns="http://camel.apache.org/schema/spring">
    <route>
        <from uri="file:src/data?noop=true" />
        <to uri="activemq:personnel.records" />
    </route>
    <route>
        <from uri="activemq:personnel.records" />
        <log message="${body}" />

        <choice>
            <when>
                <xpath>/person/city = 'London'</xpath>
                <to uri="file:target/messages/uk" />
            </when>
            <otherwise>
                <to uri="file:target/messages/others" />
            </otherwise>
        </choice>
    </route>
</camelContext>


<bean id="activemq" class="org.apache.camel.component.jms.JmsComponent"
    p:configuration-ref="jmsConfig" p:transacted="true" p:cacheLevelName="CACHE_CONSUMER" />

<bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration"
    p:connectionFactory-ref="nakedConnectionFactory"
    p:concurrentConsumers="20" p:maxConcurrentConsumers="500"
    p:idleConsumerLimit="10" />

<bean id="nakedConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"
    p:brokerURL="tcp://localhost:61616" />