如何在骆驼环境中节流

how to throttle in camel context

我正在使用 Apache camel 和 jboss fuse,我创建了下面列出的示例路由蓝图,我已经成功处理了所有路由中的异常,现在问题是我找不到任何示例按照我定义的路线节流。在 apache camel 文档中,他们给出了简单的 DSL 节流,在 Whosebug 中我发现了 rabbitMq throttling 这不是我的情况。如何在 apache camel

中限制这样的路由
<?xml version="1.0" encoding="UTF-8"?>
    <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
        xmlns:camel="http://camel.apache.org/schema/blueprint"
        xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd        http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
        <cxf:rsServer address="/testservice" id="testserver" serviceClass="com.company.HelloBean">
        <camelContext id="testContext" trace="false" xmlns="http://camel.apache.org/schema/blueprint">
            <route id="testRoute" >
              <throttle timePeriodMillis="10000">
                <constant>3</constant>
                <from id="_from1" uri="cxfrs:bean:testserver"/>
                    <bean beanType="com.company.HelloBean"
                        id="_bean1" method="hello"/>
              </throttle>
            </route>
        </camelContext>
    </blueprint>

在 jboss 保险丝中部署应用程序时会出现错误。找不到服务

嘿,你所需要的只是你当前在 throttle 标签中定义你的 from 端点这是错误的你需要像这样只在 TO 标签中定义节流标签

  <throttle id="_throttle1" rejectExecution="true" timePeriodMillis="10000">
                <constant>1</constant>
                <bean beanType="com.company.HelloBean"
                    id="_bean1" method="hello"/>
            </throttle>

当请求到达终点时,您将在请求到达您正在使用 bean 的另一个终点时进行限制,因此,您可以执行类似这样的操作

    <?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:camel="http://camel.apache.org/schema/blueprint"
    xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd        http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
    <cxf:rsServer address="/testservice" id="testserver" serviceClass="com.evampsaanga.gethomepage.GetHomePageDataLand">
        <cxf:providers>
            <bean class="com.evampsaanga.restresponses.ExceptionHandler" id="securityException"/>
        </cxf:providers>
    </cxf:rsServer>
<!--     <bean class="com.saanga.servicetest.THR" id="myPolicy"/> -->
    <camelContext id="testContext" trace="false" xmlns="http://camel.apache.org/schema/blueprint">
        <route id="testRoute" >
            <from id="_from1" uri="cxfrs:bean:testserver"/>
            <log id="_log1" message="header : ${headers}"/>
            <setHeader headerName="headerbalance" id="_setHeader1">
                <simple>${headers}</simple>
            </setHeader>
            <setBody id="_setBody1">
                <simple>${body}</simple>
            </setBody>
            <throttle id="_throttle1" rejectExecution="true" timePeriodMillis="10000">
                <constant>1</constant>
                <bean beanType="com.evampsaanga.gethomepage.GetHomePageDataLand"
                    id="_bean1" method="Get"/>
            </throttle>
        </route>
    </camelContext>
</blueprint>