2013-10-04 78 views
1

我有以下途径:如何缩放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条短信,每个你好bean的一步*方法需要250毫秒,当我做骆驼:运行,性能仍然很糟糕。它按顺序打印“End:...”,每个顺序不平行。这里会有什么问题?

在下面很简单的情况下,我看到一个奇怪的行为。当没有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" 
    /> 

回答

0

路由滑移在序列运行,并哟别请求/过JMS(例如,MEP方法是InOut),以便处理一个消息将采取

  • 呼叫AMQ回复:一个= 250毫秒时间(请求/回应)
  • 呼叫AMQ:2 = 250毫秒时间(请求/回复)
  • 呼叫AMQ:3 = 250毫秒时间(请求/回复)
  • 呼叫AMQ:4 = 250毫秒时间(请求/回复)

每条消息总共1秒。

但是,来自>的<中的AMQ路由可以并行处理消息。但是每条消息仍然需要1秒来处理。

+0

更换

<from uri="amq:example.MyQueue" /> 

我知道这一点。问题是如何使它平行? – sancho21

0

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

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

+0

如果没有ExchangePattern,则来自bean调用的结果将不会反映在最后一个日志中。 – sancho21

1

尝试

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