package com.fdkankan.scene.listener;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;


/**
 * 设置消息监听
 * 监听组：监听topic：监听tag(默认监听topic下所有)
 * 监听消费模式:默认负载均衡：CLUSTERING（每一个消息只发给一个消费者）、广播模式：BROADCASTING（发送给所有消费者）
 *
 */
@Slf4j
@Component
@RocketMQMessageListener(
        consumerGroup = "qwe",
        topic = "qwe",
//        selectorExpression = "${rocketmq.consumer.tags}",
        messageModel = MessageModel.CLUSTERING
)
public class TestMQListener implements RocketMQListener<String> {

    @SneakyThrows
    @Override
    public synchronized void onMessage(String message) {

        System.out.println(Thread.currentThread().getName()+"test1"+message);
        Thread.sleep(10000);
        System.out.println("结束");

    }
}
