| package com.matrix.core.rabbitmq; | 
|   | 
| import com.matrix.core.exception.GlobleExceptionResolver; | 
| import com.matrix.core.tools.LogUtil; | 
| import com.rabbitmq.client.DeliverCallback; | 
| import com.rabbitmq.client.Delivery; | 
|   | 
| import java.io.IOException; | 
|   | 
| public class DeliverCallbackAdapter implements DeliverCallback { | 
|   | 
|     private DeliverCallback deliverCallback; | 
|     private String routingKey; | 
|   | 
|   | 
|   | 
|     public DeliverCallbackAdapter(DeliverCallback deliverCallback, String routingKey) { | 
|         this.deliverCallback = deliverCallback; | 
|         this.routingKey = routingKey; | 
|     } | 
|   | 
|     @Override | 
|     public void handle(String consumerTag, Delivery message) throws IOException { | 
|         try { | 
|             if (deliverCallback == null) { | 
|                 LogUtil.info("消费者处理类为null"); | 
|             } else { | 
|                 deliverCallback.handle(consumerTag, message); | 
|             } | 
|   | 
|         } catch (Exception e) { | 
|             LogUtil.error("消费者执行抛出异常", e); | 
|             String messageBody = message == null ? "" : new String(message.getBody()); | 
|             GlobleExceptionResolver.sendNoticeToAdmin(e, "routingKey=" + routingKey+",messageBody=" + messageBody,null ); | 
|         } | 
|     } | 
|   | 
|   | 
| } |