MaximumConcurrentAccess 的问题

Problems with MaximumConcurrentAccess

我想将我的服务限制为最多同时执行 3 个并发执行,所以我使用节流调解器,将 MaximunConcurrentAcces 设置为 3。 设置这个属性只让我使用该服务三次,之后,总是响应 onReject 中定义的 fault:exception。要重新开始,我必须重新部署服务。

我想我忘记了一些配置,但我不知道。我在 wso2 文档中找不到它:(。我的代理代码是这样的:

<proxy xmlns="http://ws.apache.org/ns/synapse"
   name="PruebaT"
   transports="http"
   statistics="disable"
   trace="disable"
   startOnLoad="true">
<target>
  <inSequence>
     <throttle id="AAA">
        <policy>
           <wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
                       xmlns:throttle="http://www.wso2.org/products/wso2commons/throttle">
              <throttle:ThrottleAssertion>
                 <throttle:MaximumConcurrentAccess>3</throttle:MaximumConcurrentAccess>
              </throttle:ThrottleAssertion>
           </wsp:Policy>
        </policy>
        <onReject>
           <log level="custom">
              <property name="text" value="**Access Denied**"/>
           </log>
           <makefault version="soap11">
              <code xmlns:tns="http://www.w3.org/2003/05/soap-envelope" value="tns:Receiver"/>
              <reason value="**Access Denied**"/>
           </makefault>
           <property name="RESPONSE" value="true"/>
           <header name="To" action="remove"/>
           <send/>
           <drop/>
        </onReject>
        <onAccept>
           <log level="custom">
              <property name="text" value="**Access Accept**"/>
           </log>
           <send>
              <endpoint>
                 <address uri="http://localhost:8090/dummywar/inicio?file=response.xml"/>
              </endpoint>
           </send>
        </onAccept>
     </throttle>
  </inSequence>
</target>
</proxy>

谢谢。

根据 WSO2 文档,当节流调解器用于并发访问限制时,必须在响应流上触发相同的节流调解器 ID,以便从可用限制中扣除已完成的响应。 (即请求和响应流中具有相同 id 属性的节流调解器的两个实例)。

所以,根据 throttle mediator 逻辑,在你的情况下,你已经将 throttle 放在了 inSequence 中,所以 ESB 无法识别哪个请求已完成。你必须把里面的序列。否则,ESB 将认为三个请求未完成,您将收到访问被拒绝的消息。

所以配置应该是这样的

    <?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="PruebaT"
       transports="http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <throttle id="AAA">
            <policy>
               <wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
                           xmlns:throttle="http://www.wso2.org/products/wso2commons/throttle">
                  <throttle:ThrottleAssertion>
                     <throttle:MaximumConcurrentAccess>3</throttle:MaximumConcurrentAccess>
                  </throttle:ThrottleAssertion>
               </wsp:Policy>
            </policy>
            <onReject>
               <log level="custom">
                  <property name="text" value="**Access Denied**"/>
               </log>
               <makefault version="soap11">
                  <code xmlns:tns="http://www.w3.org/2003/05/soap-envelope" value="tns:Receiver"/>
                  <reason value="**Access Denied**"/>
               </makefault>
               <property name="RESPONSE" value="true"/>
               <header name="To" action="remove"/>
               <send/>
               <drop/>
            </onReject>
            <onAccept>
               <log level="custom">
                  <property name="text" value="**Access Accept**"/>
               </log>
               <send>
                  <endpoint>
                     <address uri="http://krishan-Latitude-E5450:8080/ep1"/>
                  </endpoint>
               </send>
            </onAccept>
         </throttle>
      </inSequence>
      <outSequence>
         <throttle id="AAA"/>
         <send/>
      </outSequence>
   </target>
   <description/>
</proxy>