1
votes

I am getting this issue when I deploy redis server and spring server in two different servers and try to connect to spring server through my application.

App Details:
We have mobile application which publish gps coordinates to spring server using stomp. In the spring server we create jedis pubsub connection and publish those gps data to our web application and web users subscribe to those jedis pubsub connections.

Library versions:
stomp:1.7.1
jedis: 2.8.1
spring: 4.3.0

Working scenarios:
*Deploy spring server in my local machine and redis server in remote production server.
*Deploy spring server in remote server and redis server in same remote server where spring server is deployed.

Partially Working scenarios:
*Deploy spring server in remote server and redis server in different remote server where spring server is deployed. In this scenario I monitor redis server using redis cli and I can see the "HGETALL", "PUBLISH" key words with its data. But the same time I got following error in spring server:

Caused by:

java.net.ConnectException: Connection refused (Connection refused)
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at redis.clients.jedis.Connection.connect(Connection.java:158)
    ... 4 more
redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused (Connection refused)
    at redis.clients.jedis.Connection.connect(Connection.java:164)
    at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:80)
    at redis.clients.jedis.Connection.setTimeoutInfinite(Connection.java:68)
    at redis.clients.jedis.Jedis.subscribe(Jedis.java:2626)
    at shipxpress.pubsubservice.controllers.SubscriberThread.run(MainController.java:227)

The spring server can successfully depoyed to the server and exception occurs when jedis try to publish or subscripe to the connection. I can succesfully ping to redis server from the server where we deploy the spring server through the redis-cli and the redis server prtected-mode is no and and bind ip is set to 0.0.0.0

Links: I went through following links but no luck
Redis bind to more than one IP

https://github.com/xetorthio/jedis/issues/1405

Cannot connect to redis using jedis

2
no this is not the same question since my one works fine, when the spring server is in my machine. it doesn't work in case 3 where the spring server and redis server are in two different remote serveres.keshani Rathnayake

2 Answers

0
votes

This issue means that the Spring remote server is not able to communicate with the other remote server(Redis server) on the default Redis port. Maybe you could confirm this by trying to access the Remote Redis server from the other remote Server using netstat from the console.

0
votes

I had the same issue, and the simplest solution was

Find the following line in your redis.conf file and comment it out:

bind 127.0.0.1

By adding a # in front of it:

# bind 127.0.0.1

and change the line protected-mode yes to be protected-mode no

save your redis.conf and restart redis using the config file

redis-server /configFileLocation