package com.ruoyi.rabbitmq.listener;

import com.rabbitmq.client.Channel;
import com.ruoyi.rabbitmq.annotation.RabbitComponent;
import com.ruoyi.rabbitmq.core.BaseRabbiMqHandler;
import com.ruoyi.rabbitmq.utils.BaseMap;
import com.ruoyi.rabbitmq.utils.MqConstant;
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;

/**
 * RabbitMq接受者1
 * （@RabbitListener声明类上，一个类只能监听一个队列）
 */
@Slf4j
@RabbitListener(queues = MqConstant.MQ_RUOYI_MQ)
@RabbitComponent(value = "helloReceiver1")
public class HelloReceiver1 extends BaseRabbiMqHandler<BaseMap> {

    @RabbitHandler
    public void onMessage(BaseMap baseMap, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) {
        super.onMessage(baseMap, deliveryTag, channel, new MqListener<BaseMap>() {
            @Override
            public void handler(BaseMap map, Channel channel) {
                //业务处理
                String orderId = map.get("orderId").toString();
                log.info("MQ Receiver1，orderId : " + orderId);
            }
        });
    }

}
