【问题标题】:how to throttle in camel context如何在骆驼上下文中节流
【发布时间】:2017-11-08 22:01:41
【问题描述】:

我正在使用 Apache camel 和 jboss fuse,我创建了下面列出的示例路由蓝图,我已经成功处理了所有路由中的异常,现在问题是我找不到任何路由节流示例定义。在 apache camel 文档中,他们给出了简单的 DSL 节流,在 stackoverflow 中我发现 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 fuse 中部署应用程序时会出错。找不到服务

【问题讨论】:

  • 你没有限制 bean。你限制了路线

标签: java apache-camel throttling


【解决方案1】:

你所需要的只是你当前在节流标记中定义你的从端点这是错误的你只需要在这样的 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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-20
    • 2014-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多