2013-10-04 81 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" /> 
相關問題