package com.bawei.mall.search.rabbit;

import com.bawei.common.rabbit.constant.QueueConstant;
import com.bawei.common.rabbit.domain.Message;
import com.bawei.common.rabbit.enums.QueueEnum;
import com.bawei.mall.search.service.SearchService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author DongZl
 * @description: rabbit商品消息处理
 * @Date 2022-10-21 下午 02:48
 */
@Component
public class RabbitProductMsg {

    /**
     * 日志
     */
    private final static Logger log = LoggerFactory.getLogger(RabbitProductMsg.class);

    @Autowired
    private SearchService searchService;

    /**
     * 商品新增消息
     * @param message
     */
    @RabbitListener( queues = QueueConstant.PRODUCT_ADD)
    public void productAdd(Message<Long> message){
        log.info("消息队列：[{}]，接受到消息：[{}]", QueueEnum.PRODUCT_ADD.queueStr(),
                message);
        searchService.syncProductInfo(message.getBody());
    }
}
