2015-06-15 37 views
2

任何人都可以請給出一個關於如何通過使用Throttler處理器實例或使用Apache Camel中的節流元素來動態更改maxRequestsPerPeriod的示例嗎? (參考 - How to change Processor properties during runtime using Camel?阿帕奇駱駝 - 動態改變油門值

我們不能在表頭中使用表達式,因爲如果表頭不存在,那麼Throttler會使用舊值。我們需要的是,在基於某種情況的bean中,我們必須更新節流值,以便在下次更新之前使用它。在我們的例子中,我們不能使用消息頭來達到這個目的。

我們如何瀏覽路由中的運行時處理器並找到Throttler以動態更改它?請幫助一個樣本。

謝謝。

回答

0

您可以使用JMX(例如管理api)更改它。

在MBean具有JMX屬性在運行時改變的值。

在即將到來的駱駝2.16版本中,您可以更容易得到Java代碼的JMX MBean的保持使用

只是,你知道的MBean的ID。您可以在路由中分配ids,因此它使用已知的id,而不是自動生成的。其中btw也使得使用純JMX api更容易找到mbean。

1

感謝Claus ..我們將在即將發佈的Camel 2.16發佈中檢查jmx mbeans。

現在下面的解決方案爲我們提供了駱駝2.15.2

的Java DSL:

from("direct:start") 
    .routeId("throttleroute") 
    .throttle(ExpressionBuilder.beanExpression("throttleBean","getThrottle")) 
    .timePeriodMillis(2000) 
    .to("jms:test.MyQueue") 
    .beanRef("throttleBean", "receiveData"); 

春DSL:

<route id="throttleroute"> 
    <from uri="direct:start" /> 
     <throttle timePeriodMillis="2000"> 
      <method ref="throttleBean" method="getThrottle" /> 
      <to uri="jms:test.MyQueue" /> 
     </throttle> 
    <to uri="bean:throttleBean?method=receiveData" /> 
</route> 

這裏throttleBean。 getThrottle()方法將會有lo gic動態生成並返回所需的節流值。