如何在骆驼环境中扼杀

时间:2017-06-07 13:48:00

标签: java apache-camel throttling

我正在使用Apache驼峰和jboss保险丝,我已创建了下面列出的示例路线蓝图,我已成功处理所有路线中的异常现在问题是我找不到任何路由限制的例子,因为我有定义。在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保险丝中部署应用程序时会出错。无法找到服务

1 个答案:

答案 0 :(得分:2)

hy,您所需要的只是当前正在使用throttle标签定义您的from endpoint,这是错误的,您需要仅在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>