Last active
October 27, 2024 19:19
-
-
Save gbzarelli/23421e3a6db89e91485b24047764b079 to your computer and use it in GitHub Desktop.
RabbitMQ - Graceful shutdown - Configure Shutdown timeout in rabbitmq #helpdev-blog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory; | |
import org.springframework.amqp.rabbit.connection.ConnectionFactory; | |
import org.springframework.beans.factory.annotation.Value; | |
import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
@Configuration | |
public class RabbitmqConnectionConfig { | |
@Value("${spring.rabbitmq.shutdown-timeout:60000}") | |
private Integer shutdownTimeout; | |
@Bean | |
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(final ConnectionFactory connectionFactory, | |
final SimpleRabbitListenerContainerFactoryConfigurer configurer) { | |
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); | |
configurer.configure(factory, connectionFactory); | |
factory.setContainerCustomizer(c -> c.setShutdownTimeout(shutdownTimeout)); | |
return factory; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment