package com.bohuikeji.delivery.backstage.config;

import com.bohuikeji.frame.module.admin.utils.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
import org.springframework.stereotype.Component;

/**
 * @author Admin
 */
@Slf4j
@Component
public class RedisPushSocketConf {
    /**
     * 订阅发布——socket广播监听
     */
    public static String pushQueueSocketKey = SpringUtil.getProperty("spring.application.name")+":"+SpringUtil.getProperty("spring.profiles.active")+":pubsub:queue:socket";

   /* final RedisMessageListenerContainer container;
    public RedisPushSocketConf(RedisMessageListenerContainer container) {
        this.container = container;
    }*/
    /*RedisPushSocketConf(PropertyUtil util){
        System.err.println(util.getString("server.port"));
    }*/


    //@ConditionalOnMissingBean(RedisMessageListenerContainer.class)
    @Bean
    RedisMessageListenerContainer socketContainer(RedisConnectionFactory connectionFactory, RedisPushSocketReceiver receiver) {
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(connectionFactory);
        //添加Socket订阅发布监听
        container.addMessageListener(new MessageListenerAdapter(receiver),new ChannelTopic(pushQueueSocketKey));
        return container;
    }
}
