Skip to content

Commit

Permalink
feature: CustomErrorHandler를 RabbitMQ에 적용한다.
Browse files Browse the repository at this point in the history
Related: #70
  • Loading branch information
hoa0217 committed Apr 5, 2024
1 parent 35a3508 commit faad5e8
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/main/java/com/modoospace/config/rabbitmq/RabbitMQConfig.java
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit faad5e8

Please sign in to comment.