欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Spring 配置RabbitMQ 处理异常ErrorHandler

程序员文章站 2022-07-15 12:59:15
...

重写ErrorHandler

package com.uc.task.mq;
import org.apache.log4j.Logger;
import org.springframework.util.ErrorHandler;
/**
 * Created by yanhao on 2017/6/15.
 */
public class TaskErrorHandler implements ErrorHandler {
    private final Logger log = Logger.getLogger(TaskErrorHandler.class);
    public void handleError(Throwable throwable) {
        log.error(throwable.getMessage(), throwable);
    }
}

配置

 <!-- 监听的队列-->
    <rabbit:listener-container connection-factory="connectionFactory" acknowledge="auto" error-handler="errorHandler">
        <rabbit:listener ref="listen" queue-names="yh.rabbitMQ.test"/>
    </rabbit:listener-container>
    <bean id="errorHandler" class="com.uc.task.mq.TaskErrorHandler"/>

转载于:https://my.oschina.net/yan5845hao/blog/974106