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 do you pass REDIS configs for REDIS based ratelimit

mahulivishal opened this issue · comments

I am trying to use the REDIS-based rate limit implementation of this library.
My zuul app is crashing right at the startup with the following error -

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisConnectionFactory' defined in class path resource [org/springframework/boot/autoconfigure/data/redis/LettuceConnectionConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Host must not be empty
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796) ~[spring-beans-5.2.5.RELEASE.jar!/:5.2.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.5.RELEASE.jar!/:5.2.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.5.RELEASE.jar!/:5.2.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.5.RELEASE.jar!/:5.2.5.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.5.RELEASE.jar!/:5.2.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.5.RELEASE.jar!/:5.2.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.5.RELEASE.jar!/:5.2.5.RELEASE]
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.2.5.RELEASE.jar!/:5.2.5.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.addCandidateEntry(DefaultListableBeanFactory.java:1508) ~[spring-beans-5.2.5.RELEASE.jar!/:5.2.5.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1472) ~[spring-beans-5.2.5.RELEASE.jar!/:5.2.5.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveMultipleBeans(DefaultListableBeanFactory.java:1391) ~[spring-beans-5.2.5.RELEASE.jar!/:5.2.5.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1248) ~[spring-beans-5.2.5.RELEASE.jar!/:5.2.5.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1210) ~[spring-beans-5.2.5.RELEASE.jar!/:5.2.5.RELEASE]
	at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:885) ~[spring-beans-5.2.5.RELEASE.jar!/:5.2.5.RELEASE]
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:789) ~[spring-beans-5.2.5.RELEASE.jar!/:5.2.5.RELEASE]
	... 125 common frames omitted
Caused by: java.lang.IllegalArgumentException: Host must not be empty
	at io.lettuce.core.internal.LettuceAssert.notEmpty(LettuceAssert.java:44) ~[lettuce-core-6.1.5.RELEASE.jar!/:6.1.5.RELEASE]
	at io.lettuce.core.RedisURI$Builder.redis(RedisURI.java:1193) ~[lettuce-core-6.1.5.RELEASE.jar!/:6.1.5.RELEASE]
	at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.createRedisURIAndApplySettings(LettuceConnectionFactory.java:1104) ~[spring-data-redis-2.2.6.RELEASE.jar!/:2.2.6.RELEASE]
	at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.createClient(LettuceConnectionFactory.java:1047) ~[spring-data-redis-2.2.6.RELEASE.jar!/:2.2.6.RELEASE]
	at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.afterPropertiesSet(LettuceConnectionFactory.java:277) ~[spring-data-redis-2.2.6.RELEASE.jar!/:2.2.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855) ~[spring-beans-5.2.5.RELEASE.jar!/:5.2.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792) ~[spring-beans-5.2.5.RELEASE.jar!/:5.2.5.RELEASE]
	... 139 common frames omitted

Seems like the issue is with REDIS host.
These are my REDIS configs for the app:
spring.redis.host=a.b.c
spring.redis.port=6379
spring.redis.pass=xyz
spring.redis.timeout=60000

Can you please help?

Hello @mahulivishal, 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.

Hi @mahulivishal, the problem you're having is not related to this library. You are better off at Spring Data Redis.

Hi @marcosbarbero Isn't the library using redis? The error is from the library, it isn't connecting to redis. Could you please tell me this -
zuul.ratelimit.repository=REDIS ensures that we use REDIS as bookkeeper for ratelimiting. But, how do I tell the library where to connect to redis from? What are the configs for me to pass the host, port, pwd of the redis cluster?

This library relies on Spring Boot implementation to connect to Redis, and you need to have it set up before using this library. The problem you are having is related to a misconfiguration on the Spring Data Redis. It seems you are having trouble configuring the host property.

The library picks RedisTemplate and uses it internally, that's what I saw in your code and for RedisTemplate these are the configs that spring provides - (values are dummy)
spring.redis.host=localhost
spring.redis.port=6379
spring.redis.pass=xyz
spring.redis.timeout=60000

Do you see anything wrong here? Or is there a codebase that I can refer to which has already used REDIS based ratelimit?

Can you reproduce this problem in a public repo so I can take a look?

Hey @marcosbarbero, The issue is resolved, you were right, it had to do with my Redis Configuration, Basically, I had to create a RedisTemplate Bean and override the default values in my Boot Class, did it now, it worked. Thanks man :)

You're welcome!