set heartbeat property on rabbitmq autoconfig conn

2019-09-06 15:45发布

问题:

How should I set the heartbeat property on a CachingConnectionFactory bean in rabbitmq spring? This is in a cloud foundry environment. So the application will be using a service binding via manifest file and I don't have the broker host name. In my SimpleMessageListenerContainer bean, I make use of the CachingConnectionFactory bean and I guess it's autowired by Spring.

I could do in there,

@Bean
SimpleMessageListenerContainer container(CachingConnectionFactory connectionFactory,
            MessageListenerAdapter listenerAdapter) {
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
    connectionFactory.setRequestedHeartbeat(60);
    container.setConnectionFactory(connectionFactory);
    ...
}

since I am not creating a bean for CachingconnectionFactory, I don't have a place for assigning that property, this is the only place I see for it.

Is there any other way to assign this property on ConnectionFactory in auto-configured setting? thanks

回答1:

See the Spring Boot Properties Documentation.

spring.rabbitmq.requested-heartbeat= # Requested heartbeat timeout, in seconds; zero for none.