spring-cloud / spring-cloud-connectors

Library to let cloud applications connect to services
Apache License 2.0
185 stars 161 forks source link

Should be able to set the RedisConnection timout with the ServiceConnectorConfig #108

Closed cgfrost closed 9 years ago

cgfrost commented 9 years ago

Sometimes it takes too long to connect to a Redis instance and the default time out gets hit. It should be possible to specify a different time out in the ServiceConnectorConfig object.

https://github.com/spring-cloud/spring-cloud-connectors/blob/master/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/service/keyval/RedisConnectionFactoryCreator.java

scottfrederick commented 9 years ago

@cgfrost We've been getting a few requests lately to add more ability to customize the connections created by SCC.

Some connector types (e.g. relational, mongo, rabbitmq) support a Config class that can be used to set parameters for the created connection. We can add a RedisConnectionFactoryConfig with this (and maybe a few other parameters) and change RedisConnectionFactoryCreator to honor that.

scottfrederick commented 9 years ago

Fixed via https://github.com/spring-cloud/spring-cloud-connectors/commit/30c40dd0d8ed6b884cc516a98ce068f8bc1b0d56

This change allows a map of connection properties to be provided to customize the created RedisConnectionFactory bean.

With XML configuration, you can now do something like this:

<cloud:redis-connection-factory id="redis" service-name="my-redis">
    <cloud:connection-properties>
        <entry key="timeout" value="10"/>
    </cloud:connection-properties>
</cloud:redis-connection-factory>

With Java config, you can now do something like this:

@Configuration
class RedisConfig extends AbstractCloudConfig {
    @Bean
    public RedisConnectionFactory redisConnectionFactory() {
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put("timeout", 10);
        RedisConnectionFactoryConfig serviceConfig = new RedisConnectionFactoryConfig(properties);
        return connectionFactory().redisConnectionFactory("my-redis", serviceConfig);
    }
}