1

I have the following camel which polls Redis:

                from("timer://pollredis?fixedRate=true&period=5")
                    // poll redis
                    .setHeader("CamelRedis.Command", constant("LPOP"))
                    .setHeader("CamelRedis.Key", constant("shipments"))
                    // from redis, it is a producer, fetch with .to() !
                    .to(redisUri)
                    //
                    .choice().when(simple("${in.body} == null")).stop().otherwise()
                    //
                    .to("direct:internal").end();


    JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory();
    jedisConnectionFactory.afterPropertiesSet();

    RedisTemplate<?, ?> redisTemplate = new RedisTemplate();
    redisTemplate.setConnectionFactory(jedisConnectionFactory);
    redisTemplate.setDefaultSerializer(new StringRedisSerializer());
    redisTemplate.afterPropertiesSet();

    SimpleRegistry registry = new SimpleRegistry();
    registry.put("redisTemplate", redisTemplate);

And it works great. However, when I change the redisUri from

redisUri = spring-redis://localhost:6379?redisTemplate=#redisTemplate

to

redisUri = spring-redis://[stuff].xavwv8.ng.0001.euw1.cache.amazonaws.com:6379?redisTemplate=#redisTemplate

I get the following error:

11:42:49.754 INFO  Failed delivery for (MessageId: ID-ip-10-12-22-168-43293-1465299763162-0-1 on ExchangeId: ID-ip-10-12-22-168-43293-1465299763162-0-2). On delivery attempt: 0 caught: org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool | org.apache.camel.util.CamelLogger.log(CamelLogger.java:159) [Camel (camel-1) thread #0 - timer://pollredis] 

I have checked that I have access to the elasticache by telneting to it and by using redis-cli.

What is this Could not get a resource from the pool error that I'm getting when connecting to a remote host?

Both my local redis and the elasticache redis is running 2.8.24. Running camel 2.17.1.

Calle at e-man
  • 145
  • 2
  • 9
  • I checked out [this thread](https://stackoverflow.com/questions/30447919/cannot-get-connection-for-redistemplate-for-spring-data-redis) and it may be a version thing. [camel-spring-redis](http://mvnrepository.com/artifact/org.apache.camel/camel-spring-redis/2.17.1) is using spring-data-redis 1.6.4.RELEASE and jedis 2.7.3. Also, if I remove the `?redisTemplate=#redisTemplate` part it works, but then there's no StringRedisSerializer :( – Calle at e-man Jun 08 '16 at 05:54

1 Answers1

2

Here's how I got it working:

    JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory();
    jedisConnectionFactory.setHostName(redisHost);
    jedisConnectionFactory.setPort(Integer.parseInt(redisPort));
    jedisConnectionFactory.afterPropertiesSet();

    RedisTemplate<String, Object> redisTemplate = new RedisTemplate();
    redisTemplate.setConnectionFactory(jedisConnectionFactory);
    redisTemplate.setDefaultSerializer(new StringRedisSerializer());
    redisTemplate.afterPropertiesSet();

    SimpleRegistry registry = new SimpleRegistry();
    registry.put("redisTemplate", redisTemplate);

properties-file:

redisUri = spring-redis://notused?redisTemplate=#redisTemplate
redisHost = [stuff].xavwv8.ng.0001.euw1.cache.amazonaws.com
redisPort = 6379

Camel route same as before.

So apparently when you use a connection factory you can't set the host to use in the URI later.

Calle at e-man
  • 145
  • 2
  • 9