Apache Camel - 动态改变油门值 [英] Apache Camel - Dynamically changing throttle values

查看:28
本文介绍了Apache Camel - 动态改变油门值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以举例说明如何通过使用 Throttler 处理器实例或使用 Apache Camel 中的油门元素来动态更改 maxRequestsPerPeriod 吗?(参考 - 如何在运行时使用 Camel 更改处理器属性?)

Can anyone please give a sample on how to dynamically change the maxRequestsPerPeriod by using a Throttler processor instance or using a throttle element in Apache Camel ? (Reference - How to change Processor properties during runtime using Camel?)

我们不能将 Expression 与 header 一起使用,因为如果 header 不存在,那么 Throttler 将使用旧值.我们需要的是,在基于某些条件的 bean 中,我们必须更新节流值,以便在下次更新之前使用它.在我们的例子中,我们不能为此目的使用消息头.

We cannot use Expression with header because if the header is absent then the Throttler uses the old value. What we need is, in a bean based on some condition we have to update the throttle value so that it will be used until next update. In our case, we cannot use message header for this purpose.

我们如何导航路由中的运行时处理器并找到 Throttler 以动态更改它?请帮助提供样品.

How can we navigate the runtime processors in the route and find the Throttler to change it dynamically? Please help with a sample.

谢谢.

推荐答案

谢谢 Claus..我们将在即将发布的 Camel 2.16 版本中检查 jmx mbeans.

Thanks Claus..We will check jmx mbeans in upcoming Camel 2.16 release.

现在以下解决方案适用于 Camel 2.15.2:

Now the following solution worked for us with Camel 2.15.2 :

Java DSL:

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

Spring 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() 方法将具有动态生成和返回所需节流值的逻辑.

Here throttleBean.getThrottle() method will be having the logic to generate and return the required throttle value dynamically.

这篇关于Apache Camel - 动态改变油门值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆