WSO2 APIM | Sequence to print throttlling messages

Hi everyone, I will be sharing my another experience with the WSO2 API Manager sample use case for API throttling.

Scenario
So I had a situation encountered where I have to see the throttling messages in my wso2carbon.log file. By default, it has not been enabled and we have to make some changes to see the required output in the wso2carbon log file.
 
API Manager Version 3.2.0

Changes done

WSO2 Sequence to print throttling messages in wso2carbon.log file

  1. Navigate to <APIM_HOME>/repository/deployment/server/synapse-configs/default/sequences directory.
  2. Open the file named _throttle_out_handler_.xml.
  3. Update the contents of file _throttle_out_handler_.xml as per the below custom changes

<sequence name="_throttle_out_handler_" xmlns="http://ws.apache.org/ns/synapse">    
    <property name="X-JWT-Assertion" scope="transport" action="remove"/>
    <class name="org.wso2.carbon.apimgt.gateway.handlers.analytics.APIMgtThrottleUsageHandler"/>
    <sequence key="_cors_request_handler_"/>
</sequence>
<!-- Custom sequence added starts -->
<sequence name="_throttle_out_handler_" xmlns="http://ws.apache.org/ns/synapse">    
    <property name="X-JWT-Assertion" scope="transport" action="remove"/>
    <class name="org.wso2.carbon.apimgt.usage.publisher.APIMgtThrottleUsageHandler"/>
    <sequence key="_cors_request_handler_"/>
    <log level="custom">
    <property name="API_NAME:VERSION" expression="get-property('api.ut.api_version')"/>
    <property name="USER_NAME" expression="get-property('api.ut.userName')"/>
    <property name="APPLICATION_NAME" expression="get-property('api.ut.application.name')"/>
    <property name="THROTTLED_OUT_REASON" expression="get-property('THROTTLED_OUT_REASON')"/>
       <property name="NEXT_ACCESS_UTC_TIME" expression="get-property('NEXT_ACCESS_UTC_TIME')"/>
    </log>
<!-- Custom sequence added ends -->     
</sequence>

 

[2022-02-28 12:10:13,409]  INFO - LogMediator API_NAME:VERSION = PizzaShackAPI:v1.0.0, USER_NAME = admin@carbon.super, APPLICATION_NAME = DefaultApplication, THROTTLED_OUT_REASON = APPLICATION_LIMIT_EXCEEDED, NEXT_ACCESS_UTC_TIME = 2022-Feb-11 12:15:00+0000 UTC 

This log message indicates that the Application Quota has been exhausted i.e. let's say we have provided the quota for Default Application as 10 Req/Min; so if the API subscribed to this application has been called more than 10 times within a minute, the request is throttled out and the API consumer will get HTTP 429 error (too many requests). 

 

Comments

  1. This comment has been removed by a blog administrator.

    ReplyDelete

Post a Comment

Popular posts from this blog

Oracle SOA Suite- Implementing Email Notification

Oracle SOA Suite 12c- PKIX path building failed & unable to find valid certification path to requested target

Migration of Oracle SOA Suite Composite from 11g to 12c