marcosbarbero / spring-cloud-zuul-ratelimit

Rate limit auto-configure for Spring Cloud Netflix Zuul

Home Page:https://blog.marcosbarbero.com/spring-cloud-netflix-zuul-rate-limit/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to use it with bucket4j hazelcast?

ssseungzz opened this issue · comments

Describe the question
I tried to follow instruction(Bucket4j implementations require the relevant bean with @qualifier("RateLimit")), but it didn't work well and there aren't any examples for implementation so I don't quite understand that. Here is part of my code, can you tell me if I'm wrong or explain it more clearly? It would be very helpful to me. Thanks!

Additional context

@Slf4j
@Configuration
@EnableCaching
@EnableConfigurationProperties(ApiServerConfig.class)
public class CacheRepository {
    
    private final ApiServerConfig apiServerConfig;
    
    public CacheRepository(ApiServerConfig apiServerConfig) {
        this.apiServerConfig = apiServerConfig;
    }
    
    @Bean
    @Primary
    HazelcastInstance hazelCastInstance() {
        ClientConfig config = new ClientConfig();
        ...
        return HazelcastClient.newHazelcastClient(config);
    }
    
    @Bean
    @Qualifier("RateLimit")
    IMap<String, GridBucketState> map() {
        return hazelCastInstance().getMap("rateLimit");
    }
}

Hello @ssseungzz, thanks for getting in touch, we will get back to you asap! If you have issues in the 1.x.x.RELEASE line we recommend you to update to the latest version, unfortunately this line is not supported anymore.

Is there any error message? If so, please share the stack trace here.

I fixed this problem by changing hazelcast & bucket4j hazelcast to right version, but I have another problem.
I set application.yml like this and start spring boot application, then send api request for the first time but received 429 TOO MANY REQUESTS error. policy lists does not mean they limit requests 5 times per 60s / 3 times per 1s?
I use same configuration up there. do I have to set some other configurations?

zuul:
  routes:
    testSimple:
      path: /test/simple
      serviceId: testSimple
    testAdvanced:
      path: /test/advanced
      serviceId: testAdvanced
  ratelimit:
    enabled: true
    behind-proxy: true
    repository: bucket4j_hazelcast
    policy-list:
      testSimple:
        - limit: 5
          refresh-interval: 60
          type:
            - origin
      testAdvanced:
        - limit: 3
          refresh-interval: 1
          type:
            - origin
  strip-prefix: true

Your configurations look good to me, and you are correct in your assumptions on the limit and refresh interval.
How are you performing your request?

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 1 day