package com.unis.basic.info.modular.mq.config;


import com.unis.basic.info.modular.mq.constant.TopicConstant;
import com.unis.basic.info.modular.mq.sub.MyMessageListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * @author ybw
 * @version V1.0
 * @className CacheMqConfig
 * @date 2024/5/9
 **/
@Configuration
public class CacheMqConfig {

    @Resource
    private MyMessageListener myMessageListener;
    @Resource
    private RedisMessageListenerContainer redisMessageListenerContainer;

    @PostConstruct
    public void init(){
        //Redis消息监听容器订阅topic
        redisMessageListenerContainer.addMessageListener(myMessageListener, new ChannelTopic(TopicConstant.DEPOT_TOPIC_NAME));
    }
}
