https://kotlinlang.org logo
#http4k
Title
# http4k
r

RajanS

06/11/2021, 9:46 AM
Hello guys, we are trying out the RateLimit functionality and we can’t get it work as we expected. Here is how we set up the client:
Copy code
private fun client(uri: Uri): HttpHandler =
    SetBaseUriFrom(uri)
        .then(RateLimit())
        .then(OkHttp(okHttpClient(100)))
Note: It’s using the default RateLimitConfig which is documented as
By default, handles maximum of 50 requests per 5 seconds.
Here is how we are testing this out:
Copy code
fun main(){
    val timeTaken = measureTimeMillis {
        makeMultipleRequests(51, client(Uri.of("<http://localhost:3002/some-url>")))
    }
    println(timeTaken)
}
I would expect the time taken to be greater than 5 seconds? Is this is how it’s suppose to work? Running it a few times to get an average it seems to complete in around 2-3 seconds. Thanks in advance
d

dave

06/11/2021, 9:48 AM
hey. it's been a while since I used the rate limiter, but I think the best bet for this is to check out the resilience4j docs as that's the underlying library that we're using
we just delegate down to it so any quirks will be those of the lib: https://github.com/resilience4j/resilience4j
r

RajanS

06/11/2021, 10:08 AM
OK thanks for this, just to be sure the way the client is set up with the filters, does that look correct to you?
d

dave

06/11/2021, 10:11 AM
yep - it's all pretty simple - not much to hide! 🙂
but let us know how you get on 🙂
5 Views