0

以下是部署为基本框架的基本 groovy 路由类中的 3 条路由。

from("jms:queue:EndPoint1?concurrentConsumers=100")
                .routePolicyRef("myPolicy")
                .transacted()
                .log("Recieved From Endpoint1")
                /*.to("log:Recieved From Endpoint1?groupSize=100")*/
                .to("CommonEndpoint");

        from("jms:queue:EndPoint2?concurrentConsumers=50")
                .rootPolicyRef("myPolicy")
                /*.to("log:Recieved From Endpoint2?groupSize=100")*/
                .log("Recieved From Endpoint2")
                .to("CommonEndpoint");

        from("CommonEndpoint")
                .delay(50)
                /*.to("log:Delayed?groupSize=100")*/
                .log("Delayed");

下面是我在引用基本框架的包中创建的计时器路由。

from("timer://Timer1?fixedRate=true&period=60000")
                .to("jms:queue:EndPoint1");

from("timer://Timer2?fixedRate=true&period=60000")
                .to("jms:queue:EndPoint2");

它不断地向端点1 和端点2 发送定时器消息,它们都向公共端点发送消息。我的 ThrottlingInflightRoutePolicy 定义如下。

<bean id="myPolicy" class="org.apache.camel.impl.ThrottlingInflightRoutePolicy">
    <property name="scope" value="Context"/>
    <property name="maxInflightExchanges" value="20"/>
    <property name="resumePercentOfMax" value="10"/>
    <property name="loggingLevel" value="WARN"/>
</bean>

在检查日志时,我可以简单地看到计时器的日志跟踪。我不明白如何在检查日志时限制请求。我这里有什么遗漏吗?在我的代码中应该做什么来测试节流......?

4

1 回答 1

1

我不确定如何实现您设置的 ThrottlingInflightPolicy,但您可以实现这样的路线来实现您的目标。

from("jms:queue:EndPoint1?concurrentConsumers=20")
    .throttle(10)
    .to("Other_Logic_Or_Routing");

注意: maxInflightExchanges 可以通过简单地将 concurrentConsumers 降低到 20 来控制 Throttle 组件可以确保您的消息传递速率不超过限制。

有很多方法可以为您的路由配置节流阀,因此请根据文档查找您要配置的内容。我的示例将路由限制为每秒处理 10 条消息。 http://camel.apache.org/throttler.html

于 2015-05-28T10:41:23.540 回答