【问题标题】:Throttle Camel Requests based on query param根据查询参数限制骆驼请求
【发布时间】:2016-06-20 14:18:15
【问题描述】:

我有如下骆驼路线:-

from("jetty:http://localhost:8888/orchestratorservice").process(processor);

from("direct:setStatusToReadyToShip").to("bean:orderHelper?method=setStatusToReadyToShip")

我经历了throttle 模式。但是有没有一种方法可以根据查询/标头参数获取速率限制/限制(例如,如果在请求中设置了 debug=1,那么我们希望将请求限制为 10 个请求/秒)。

【问题讨论】:

    标签: apache-camel


    【解决方案1】:

    是的,它是可行的,但比您最初假设的要复杂一些。从技术上讲,这是一个重复的问题,所以我只提供以下链接:

    Apache Camel - Dynamically changing throttle values

    基本上,简短的版本是您必须利用骆驼设置的 jmx 调用。在 Camel 2.16+ 中,这要容易得多。但是,Camel 2.15 中也列出了一个不太方便的解决方法。祝你的项目好运!

    【讨论】:

      【解决方案2】:

      我能够使用谓词解决它。下面的代码对我有用:-

      Predicate isDebug = header("debug").isEqualTo("true");
      from("jetty:http://localhost:8888/orchestratorservice")     
      .choice()
          .when(isDebug).throttle(5).timePeriodMillis(1000).rejectExecution(true).process(processor)
      .endChoice()
      .otherwise()
         .process(processor);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-12-01
        • 2014-01-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多