skip to Main Content

My cassandra docker-compose file:

version: '2'
services:
  redis-node-0:
    image: docker.io/bitnami/redis-cluster:latest
    ports:
      - "6370:6379"
    environment:
      - 'REDIS_PASSWORD=pass'
      - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'

  redis-node-1:
    image: docker.io/bitnami/redis-cluster:latest
    ports:
      - "6371:6379"
    environment:
      - 'REDIS_PASSWORD=pass'
      - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'

  redis-node-2:
    image: docker.io/bitnami/redis-cluster:latest
    ports:
      - "6372:6379"
    environment:
      - 'REDIS_PASSWORD=pass'
      - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'

  redis-node-3:
    image: docker.io/bitnami/redis-cluster:latest
    ports:
      - "6373:6379"
    environment:
      - 'REDIS_PASSWORD=pass'
      - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'

  redis-node-4:
    image: docker.io/bitnami/redis-cluster:latest
    ports:
      - "6374:6379"
    environment:
      - 'REDIS_PASSWORD=pass'
      - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'

  redis-node-5:
    image: docker.io/bitnami/redis-cluster:latest
    ports:
      - "6375:6379"
    environment:
      - 'REDIS_PASSWORD=pass'
      - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'

  redis-cluster-init:
    image: docker.io/bitnami/redis-cluster:latest
    depends_on:
      - redis-node-0
      - redis-node-1
      - redis-node-2
      - redis-node-3
      - redis-node-4
      - redis-node-5
    environment:
      - 'REDISCLI_AUTH=pass'
      - 'REDIS_CLUSTER_REPLICAS=1'
      - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
      - 'REDIS_CLUSTER_CREATOR=yes'

I have following java configuration:

String clusterNodes = "localhost:6370,localhost:6371,localhost:6372,localhost:6373,localhost:6374,localhost:6375";
            List<RedisNode> redisNodes = Arrays.stream(clusterNodes
                    .split(","))
                    .map(s -> {
                        String[] singleNode = s.split(":");
                        return new RedisNode(singleNode[0], Integer.parseInt(singleNode[1]));
                    }).collect(Collectors.toList());

            RedisClusterConfiguration redisClusterConfiguration = new RedisClusterConfiguration();
            redisClusterConfiguration.setPassword("pass");
            redisClusterConfiguration.setClusterNodes(redisNodes);
            JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(redisClusterConfiguration);
            jedisConnectionFactory.afterPropertiesSet();
            beanFactory.registerSingleton("jedisConnectionFactory", jedisConnectionFactory);

When I run the application – I se folowing error:

    [java] 23:35:30.094 WARN [main] o.e.jetty.webapp.WebAppContext (WebAppContext.java:554): Failed startup of context o.e.j.w.WebAppContext@441016d6{/,[file:///D:/work/onsolve/mir/acadia/ant-build/****/, jar:file:///***/ant-build
/****/WEB-INF/lib/from-ivy-swagger-ui-3.23.0.jar!/META-INF/resources],UNAVAILABLE} org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.mir3.sawtooth.service.redis.RedisConnector#0': Invocation of init method failed
; nested exception is org.springframework.data.redis.RedisConnectionFailureException: Could not get a resource from the pool; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
     [java]     at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:160)
     [java]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:416)
     [java]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1788)
     [java]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595)
     [java]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
     [java]     at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
     [java]     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
     [java]     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
     [java]     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
     [java]     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879)
     [java]     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
     [java]     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
     [java]     at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:401)
     [java]     at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:292)
     [java]     at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103)
     [java]     at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:890)
     [java]     at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:558)
     [java]     at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:853)
     [java]     at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:370)
     [java]     at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1497)
     [java]     at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1459)
     [java]     at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:785)
     [java]     at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:287)
     [java]     at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:545)
     [java]     at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
     [java]     at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:138)
     [java]     at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:117)
     [java]     at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
     [java]     at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
     [java]     at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:138)
     [java]     at org.eclipse.jetty.server.Server.start(Server.java:419)
     [java]     at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:108)
     [java]     at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
     [java]     at org.eclipse.jetty.server.Server.doStart(Server.java:386)
     [java]     at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
     [java]     at com.mir3.cure.framework.WebAppRunner.startServer(WebAppRunner.java:127)
     [java]     at com.mir3.acadia.Main.main(Main.java:63)
     [java] Caused by: org.springframework.data.redis.RedisConnectionFailureException: Could not get a resource from the pool; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
     [java]     at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:67)
     [java]     at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:41)
     [java]     at org.springframework.data.redis.PassThroughExceptionTranslationStrategy.translate(PassThroughExceptionTranslationStrategy.java:44)
     [java]     at org.springframework.data.redis.FallbackExceptionTranslationStrategy.translate(FallbackExceptionTranslationStrategy.java:42)
     [java]     at org.springframework.data.redis.connection.jedis.JedisClusterConnection.convertJedisAccessException(JedisClusterConnection.java:760)
     [java]     at org.springframework.data.redis.connection.jedis.JedisClusterStringCommands.convertJedisAccessException(JedisClusterStringCommands.java:556)
     [java]     at org.springframework.data.redis.connection.jedis.JedisClusterStringCommands.set(JedisClusterStringCommands.java:120)
     [java]     at org.springframework.data.redis.connection.DefaultedRedisConnection.set(DefaultedRedisConnection.java:274)
     [java]     at org.springframework.data.redis.connection.DefaultStringRedisConnection.set(DefaultStringRedisConnection.java:946)
     [java]     at org.springframework.data.redis.core.DefaultValueOperations$3.inRedis(DefaultValueOperations.java:240)
     [java]     at org.springframework.data.redis.core.AbstractOperations$ValueDeserializingRedisCallback.doInRedis(AbstractOperations.java:59)
     [java]     at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:224)
     [java]     at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:184)
     [java]     at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:95)
     [java]     at org.springframework.data.redis.core.DefaultValueOperations.set(DefaultValueOperations.java:236)
     [java]     at com.mir3.sawtooth.service.redis.RedisConnector.init(RedisConnector.java:38)
     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
     [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     [java]     at java.lang.reflect.Method.invoke(Method.java:498)
     [java]     at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:389)
     [java]     at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:333)
     [java]     at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:157)
     [java]     ... 36 common frames omitted
     [java] Caused by: redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
     [java]     at redis.clients.util.Pool.getResource(Pool.java:53)
     [java]     at redis.clients.jedis.JedisPool.getResource(JedisPool.java:226)
     [java]     at redis.clients.jedis.JedisSlotBasedConnectionHandler.getConnectionFromSlot(JedisSlotBasedConnectionHandler.java:66)
     [java]     at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:116)
     [java]     at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141)
     [java]     at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141)
     [java]     at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141)
     [java]     at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:141)
     [java]     at redis.clients.jedis.JedisClusterCommand.runBinary(JedisClusterCommand.java:60)
     [java]     at redis.clients.jedis.BinaryJedisCluster.set(BinaryJedisCluster.java:77)
     [java]     at org.springframework.data.redis.connection.jedis.JedisClusterStringCommands.set(JedisClusterStringCommands.java:118)
     [java]     ... 52 common frames omitted
     [java] Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: connect timed out
     [java]     at redis.clients.jedis.Connection.connect(Connection.java:207)
     [java]     at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93)
     [java]     at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1767)
     [java]     at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:106)
     [java]     at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:868)
     [java]     at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:435)
     [java]     at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363)
     [java]     at redis.clients.util.Pool.getResource(Pool.java:49)
     [java]     ... 62 common frames omitted
     [java] Caused by: java.net.SocketTimeoutException: connect timed out
     [java]     at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
     [java]     at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
     [java]     at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
     [java]     at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
     [java]     at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
     [java]     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
     [java]     at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
     [java]     at java.net.Socket.connect(Socket.java:589)
     [java]     at redis.clients.jedis.Connection.connect(Connection.java:184)
     [java]     ... 69 common frames omitted

How to fix it?

P.S.

I use spring-data-redis 2.1.10.Release

UPDATE

based on Andreas response in comment I tried to modify compose file:

version: '2'
services:
  redis-node-0:
    image: docker.io/bitnami/redis-cluster:6.0-debian-10
    volumes:
      - redis-cluster_data-0:/bitnami/redis/data
    environment:
      - 'REDIS_PASSWORD=se'
      - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
    network_mode: 'host'

  redis-node-1:
    image: docker.io/bitnami/redis-cluster:6.0-debian-10
    volumes:
      - redis-cluster_data-1:/bitnami/redis/data
    environment:
      - 'REDIS_PASSWORD=se'
      - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
    network_mode: 'host'

  redis-node-2:
    image: docker.io/bitnami/redis-cluster:6.0-debian-10
    volumes:
      - redis-cluster_data-2:/bitnami/redis/data
    environment:
      - 'REDIS_PASSWORD=se'
      - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
    network_mode: 'host'

  redis-node-3:
    image: docker.io/bitnami/redis-cluster:6.0-debian-10
    volumes:
      - redis-cluster_data-3:/bitnami/redis/data
    environment:
      - 'REDIS_PASSWORD=se'
      - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
    network_mode: 'host'

  redis-node-4:
    image: docker.io/bitnami/redis-cluster:6.0-debian-10
    volumes:
      - redis-cluster_data-4:/bitnami/redis/data
    environment:
      - 'REDIS_PASSWORD=se'
      - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
    network_mode: 'host'

  redis-node-5:
    image: docker.io/bitnami/redis-cluster:6.0-debian-10
    volumes:
      - redis-cluster_data-5:/bitnami/redis/data
    environment:
      - 'REDIS_PASSWORD=se'
      - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
    network_mode: 'host'

  redis-cluster-init:
    image: docker.io/bitnami/redis-cluster:6.0-debian-10
    depends_on:
      - redis-node-0
      - redis-node-1
      - redis-node-2
      - redis-node-3
      - redis-node-4
      - redis-node-5
    environment:
      - 'REDISCLI_AUTH=se'
      - 'REDIS_CLUSTER_REPLICAS=1'
      - 'REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5'
      - 'REDIS_CLUSTER_CREATOR=yes'
    network_mode: 'host'

volumes:
  redis-cluster_data-0:
    driver: local
  redis-cluster_data-1:
    driver: local
  redis-cluster_data-2:
    driver: local
  redis-cluster_data-3:
    driver: local
  redis-cluster_data-4:
    driver: local
  redis-cluster_data-5:
    driver: local

But error still the same

2

Answers


  1. Update:

    Since you are running docker on Windows, it’s worth reading this limitation of Windows containers for published ports.

    If you are working with a version prior to Windows 10 18.09, published
    ports on Windows containers have an issue with loopback to the
    localhost. You can only reach container endpoints from the host using
    the container’s IP and port. With Windows 10 18.09, containers work
    with published ports on localhost.

    You can try using container’s ip and port. Use below command to get containers ip –

    docker inspect -f "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" container_name_or_id
    

    Then verify if you are able to ping your container’s ip or not. If pinging works, you’re good to go.

    Original Answer:

    Your docker-compose worked for me without any problem, did a small change to set the password in your java configuration which otherwise throws NOAUTH Authentication required. I have used spring-data-redis-2.3.3 –

    redisClusterConfiguration.setPassword("pass");
    

    Below is how my pom.xml looks like –

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.3.3.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
        <groupId>com.springboot</groupId>
        <artifactId>redis-integration</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>redis-integration</name>
        <description>Spring boot integration with Redis Server Sentinels</description>
    
        <properties>
            <java.version>11</java.version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-redis</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <dependency>
                <groupId>redis.clients</groupId>
                <artifactId>jedis</artifactId>
                <version>3.3.0</version>
            </dependency>
            <dependency>
                <groupId>javax.inject</groupId>
                <artifactId>javax.inject</artifactId>
                <version>1</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
                <exclusions>
                    <exclusion>
                        <groupId>org.junit.vintage</groupId>
                        <artifactId>junit-vintage-engine</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    
    </project>
    

    Please checkout this GitHub project which has your docker-compose and java configuration. Run docker-compose up --build and then mvn spring-boot:run from the root folder.

    Note: I have tried this on Ubuntu 18.04.5 LTS

    Login or Signup to reply.
  2. Changing the property spring.redis.ssl from true to false worked fine for me in local Windows OS(Version 10.0.18363 Build 18363).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search