0
votes

I have an application running on Cloud Foundry with Spring Boot (1.5.12) and spring-boot-starter-amqp

Based on the previous SO answer to set heartbeat property on rabbitmq autoconfig connectionfactory bean, I tried setting the heart beat property as follows.

cf set-env app spring.rabbitmq.requested-heartbeat 30
cf restage app

However, when viewed through the Rabbit Management Console, the connection still indicates the heart beat is at the default of 60s.

I took a heap dump using the actuator endpoints, and took a look at the connectionFactory that seemed to have been auto-reconfigured by spring-cloud-spring-service-connector. It seems to have the default 60 seconds, and ignores the 30 seconds requested.

Is there another environment property that should be used to configure the heartbeat value ? If not, I suspect we will wire the CachingConnectionFactory and modify it in there.

1

1 Answers

2
votes

If the connection is created by Spring Cloud Connectors (i.e. spring-cloud-spring-service-connector), then you will need to customize the connection with Java configuration.

@Configuration    
class CloudConfig extends AbstractCloudConfig {
    @Bean 
    public RabbitConnectionFactory rabbitFactory() {
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put("requestedHeartbeat", 30);

        RabbitConnectionFactoryConfig rabbitConfig = new 
            RabbitConnectionFactoryConfig(properties);
        return connectionFactory().rabbitConnectionFactory(rabbitConfig);
    }
}

More detail is available in the Connectors docs.