如何扩展Apache Camel路由?

时间:2013-10-04 04:28:33

标签: apache-camel

我有以下路线:

<camelContext xmlns="http://camel.apache.org/schema/spring">
    <threadPoolProfile id="defaultProfile"
        defaultProfile="true" poolSize="100" maxPoolSize="200" />

    <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>

    </camelContext>

<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"
     />

鉴于example.MyQueue预加载了1000条消息,并且每个hello bean的step *方法需要250ms,当我执行camel:run时,性能仍然很差。它按顺序打印“End:...”,每1秒不平行。这会是什么问题?

在下面这个简单的例子中,我看到了一个奇怪的行为。当没有JMS生产者将消息放入队列时,打印按顺序发生。但是,当有,印刷品并行发生。有什么解释?

<threadPoolProfile id="defaultProfile"
        defaultProfile="true" poolSize="100" maxPoolSize="200" />

<route>
  <from uri="amq:example.MyQueue" />
  <delay>
    <constant>1000</constant>
  </delay>
  <log message="End: ${body}" />
</route>

<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"
     />

3 个答案:

答案 0 :(得分:1)

尝试替换

   <from uri="amq:example.MyQueue?concurrentConsumers=200&amp;maxConcurrentConsumers=500" />

{{1}}

答案 1 :(得分:0)

路由单按顺序运行,并且您通过JMS进行请求/回复(例如,MEP是InOut),因此处理一条消息需要

  • call amq:one = 250 millis(request / reply)
  • call amq:two = 250 millis(request / reply)
  • call amq:three = 250 millis(request / reply)
  • call amq:four = 250 millis(request / reply)

每封邮件总共1秒。

&lt; AMQ路线&lt;来自&gt;可以并行处理消息。但每条消息仍然需要1秒才能处理。

答案 2 :(得分:0)

我猜routeSlip模式是同步的。你需要一些异步组件来处理这个问题。请检查:http://camel.apache.org/async.html

只有一个问题,为什么需要设置ExchangePattern?