package com.yxcheng.tax.mq.rabbit.manager;


import com.rabbitmq.client.Channel;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Headers;

import java.util.Map;

public class AmqpManager {


    public static void withAck(Channel channel, @Headers Map<String, Object> headers, AckFuntion funtion) throws Exception {
        try {
            funtion.exec();
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            Long deliveryTag = (Long) headers.get(AmqpHeaders.DELIVERY_TAG);
            // 手工ack
            channel.basicAck(deliveryTag,false);
        }
    }
}
