spacewander commented on issue #6197:
URL: https://github.com/apache/apisix/issues/6197#issuecomment-1477167890

   > > Solving it by using a new plugin is unacceptable. We should solve it by 
using the same plugin and in one configuration.
   > 
   > @spacewander I have seen in the above comment that to use 
`resty.limit.traffic` for this in the future. my solution is based on this:
   > 
   > ```
   > local limit_req = require("resty.limit.traffic")
   > 
   > -- set traffic limits in both minutes and days
   > local minute_limit = 100
   > local day_limit = 1000
   > 
   > -- create a traffic limiter
   > local limiter, err = limit_req.new("my_traffic_limiter", minute_limit, 
day_limit, 3600)
   > if not limiter then
   >     ngx.log(ngx.ERR, "failed to create limiter: ", err)
   >     return ngx.exit(500)
   > end
   > 
   > -- call the limiter
   > local delay, err = limiter:incoming(ngx.var.binary_remote_addr, true)
   > if not delay then
   >     if err == "rejected" then
   >         ngx.log(ngx.NOTICE, "traffic rejected")
   >         return ngx.exit(429)
   >     end
   >     ngx.log(ngx.ERR, "failed to limit traffic: ", err)
   >     return ngx.exit(500)
   > end
   > 
   > -- set the delay (in seconds) if necessary
   > if delay >= 0.001 then
   >     ngx.sleep(delay)
   > end
   > ```
   > 
   > created a traffic limiter with a minute limit of 100 and a day limit of 
1000.
   
   
   Limit traffic doesn't have a method called `new`. See 
https://github.com/openresty/lua-resty-limit-traffic/blob/master/lib/resty/limit/traffic.md


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to