package com.gz.consumer;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 消费者监听
 * @author LiuchangLan
 * @date 2021/3/9 9:37
 */
//@Component
@Slf4j
@RabbitListener(queues = "${rabbitmq.ocr.queue}")
public class OcrConsumer {

    @RabbitHandler
    public void process(String message, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) throws IOException {
        try {
            System.out.println(message);
            // 确认消费
            channel.basicAck(tag, false);
        } catch (Exception e) {
            e.printStackTrace();
            // 拒绝消费
            channel.basicReject(tag, false);
        }
    }
}
