Inigo Fernandez
Inigo Fernandez

Reputation: 43

Problems with MaximumConcurrentAccess

I want to restrict my service to a maximun of 3 concurrent executions at the same time, so I use the throttle mediator, with MaximunConcurrentAcces to 3. Setting this porperty only I let me to use the service three times, after, always responses the fault:exception define in onReject. To start again I have to redeploy the service.

I suppose I forget some configuration, but I donn't know it. I dind't find it in wso2 documentation :(. The code of my proxy is this:

<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>

Thanks.

Upvotes: 1

Views: 313

Answers (1)

krishan
krishan

Reputation: 579

According to the WSO2 Documentation, When throttle mediator is used for the concurrent access limitation, the same Throttle Mediator id must be triggered on the response flow so that completed responses are deducted from the available limit. (i.e. two instances of the throttle mediator with the same id attribute in the request and response flows).

So, according to the throttle mediator logic, in your case you have put throttle inside inSequence, so ESB can't identify which request are completed. You must have to put inside outSequence. Otherwise, ESB will consider three requests are not complete and you will get access denied message.

So configuration should look like

    <?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>

Upvotes: 1

Related Questions