others-how to solve 'RedisMessageListenerContainer : Connection failure occurred' error when using redis in springboot apps ?

Problem

When we start a springboot application with redis connection, we get this error :

vm 1    | 2021-02-26 09:08:42.910 ERROR 4060 --- [    container-1] o.s.d.r.l.RedisMessageListenerContainer  : Connection failure occurred. Restarting subscription task after 5000 ms
^Cwrapper  | INT trapped.  Shutting down.

The core error is :

RedisMessageListenerContainer  : Connection failure occurred. Restarting subscription task after 5000 ms

Why do this error happen? The springboot app is correctly configured, I promise!!!

Environment

  • Springboot 1.x and 2.x
  • JDK 8

Configuration

Let’s check the configuration properties of the springboot app:

redisHost=12.43.2.1 
redisPort=6379

spring.redis.host=${redisHost}
spring.redis.port=${redisPort}

You can see that , our redis server’s IP address is 12.43.2.1, the port is the default redis port 6379.

Debug

First, we check the network connection from the client to the redis server:

telnet 12.43.2.1 6379

Trying 12.43.2.1...
Connected to 12.43.2.1.
Escape character is '^]'.
quit
+OK
Connection closed by foreign host.

So the redis connection from client to server is ok, the redis server’s network connection is ready to be used. Why our application can not connect to it?

Reason

After check for almost an hour, I found the cause of the problem, there is a space character behind the ip address of the redis server!

Solution

We should remove the space from the ip address:

The original(For display purpose , I use [space] to denote the space character):

redisHost=12.43.2.1[space]
redisPort=6379

After modify:

redisHost=12.43.2.1
redisPort=6379

Run the app again, No error messages ,It works!

-->