diff --git a/src/main/java/com/modoospace/config/rabbitmq/RabbitMQConfig.java b/src/main/java/com/modoospace/config/rabbitmq/RabbitMQConfig.java new file mode 100644 index 0000000..d28942a --- /dev/null +++ b/src/main/java/com/modoospace/config/rabbitmq/RabbitMQConfig.java @@ -0,0 +1,33 @@ +package com.modoospace.config.rabbitmq; + +import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory; +import org.springframework.amqp.rabbit.connection.ConnectionFactory; +import org.springframework.amqp.rabbit.listener.FatalExceptionStrategy; +import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.util.ErrorHandler; + +@Configuration +public class RabbitMQConfig { + + @Bean + public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory( + ConnectionFactory connectionFactory, + SimpleRabbitListenerContainerFactoryConfigurer configurer) { + SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); + configurer.configure(factory, connectionFactory); + factory.setErrorHandler(errorHandler()); + return factory; + } + + @Bean + public ErrorHandler errorHandler() { + return new CustomErrorHandler(fatalExceptionStrategy()); + } + + @Bean + FatalExceptionStrategy fatalExceptionStrategy() { + return new CustomFatalExceptionStrategy(); + } +}