package com.docus.server.collect.basic.mq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 基于注解的绑定交换器、队列、路由键设置
 * 1. Queue配置：value=队列名称、durable=是否持久化(默认true)、exclusive=排他队列只在当前connection可用(默认false)、autoDelete=如无消息是否自动删除(默认false)
 * 2. Exchange配置：value=交换器名称、type=类型(默认direct)、durable=是否持久化(默认true)、autoDelete=如无消息是否自动删除(默认false)
 * 3. QueueBinding配置：key=路由键(string数组，支持* # 匹配)，*必须匹配一个单词，#匹配0个或N个单词，用.分隔
 * 4. RabbitListener配置： bindings=Queue配置+Exchange配置+QueueBinding配置
 * 注：如果代码创建交换器等且配置绑定关系，注解只需监听队列即可，如：@RabbitListener(queues = "direct.queue")
 * <p>
 * <p>
 * rabbitmq basic consumer 使用时需要开启@RabbitListener注解
 *
 * @author linruifeng
 * @see com.docus.server.collect.basic.mq.impl.BasicRabbitMqCollectServiceImpl#addTBasic(String)
 * @see com.docus.server.collect.user.mq.test.RabbitMQProducer#topicMQ03()
 */
@Component
@Slf4j
public class RabbitMqBasicConsumer {
    @Resource(name = "basicRabbitMqCollectServiceImpl")
    private IBasicMqCollectService basicMqCollectService;

    /**
     * topic n:1 类型 交换器队列 消费
     */
    /*@RabbitListener(
        bindings = {@QueueBinding(value = @Queue(value = "topic.queue.01"),
            exchange = @Exchange(value = "topic.exchange", type = "topic"),
            key = {"*.reg.msg"})})*/
    public void addTBasic(String message) {
        log.info("rabbitmq message:{}", message);
        basicMqCollectService.addTBasic(message);
    }

    /**
     * topic n:1 类型 交换器队列 消费
     */
   /* @RabbitListener(bindings = {
        @QueueBinding(value = @Queue(value = "topic.queue.02"),
            exchange = @Exchange(value = "topic.exchange", type = "topic"),
            key = {"*.*.reg.msg.#"})})*/
    public void updateTBasic(String message) {
        log.info("rabbitmq message:{}", message);
        basicMqCollectService.updateTBasic(message);
    }
}
