package com.casic.missiles.modular.system.redis;

/**
 * Created by test203 on 2019/4/17.
 */
public class RedisSubscriber {
//    private static final String publish_channel_Name = "DigAlarm";
//    private JedisPool jedisPool;
//    private Jedis jedis;
//    private String subscriber;
//    WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();
//    DeviceGroupManager deviceGroupManager = (DeviceGroupManager) wac.getBean(DeviceGroupManager.class);
//
//    public RedisSubscriber(String subscriber){
//        this.subscriber = subscriber;
//        jedisPool = new JedisPool(Configure.getProperty("redis.host", "127.0.0.1"),
//                Integer.parseInt(Configure.getProperty("redis.port", "6379")));
//        jedis = jedisPool.getResource();
//    }
//
//    public void subscribe(String...channel){
//        if (channel==null || channel.length<=0)
//            return;
//
//        JedisPubSub jedisPubSub = new JedisPubSub() {
//            @Override
//            public void onMessage(String channel, String message) {
//                if (publish_channel_Name.equals(channel)){
//                    System.out.println("------------收到开挖报警设备，编号为：" + message);
//                    if(StringUtils.isNotBlank(message)){
//                        String groupCode=deviceGroupManager.getGroupCode(message);
//                        if(StringUtils.isNotBlank(groupCode)){
//                            String devCodes=deviceGroupManager.getDevCodesByGroup(groupCode);
//                            RedisPublisherUtil.getInstance().publishDigMessage(devCodes);
//                            System.out.println("------------发送订阅消息成功，消息为：" + devCodes);
//                        }
//                    }
//                }
//            }
//
//            @Override
//            public void onSubscribe(String channel, int subscribedChannels) {
//                if (publish_channel_Name.equals(channel)){
//                    System.out.println("订阅了频道:"+channel);
//                }
//            }
//        };
//        jedis.subscribe(jedisPubSub,channel);
//    }
//
//    public static void init(){
//        RedisSubscriber subscriber = new RedisSubscriber("订阅者");
//        subscriber.subscribe(publish_channel_Name);
//    }
////    public static void main(String[] args) {
////        RedisSubscriber subscriber = new RedisSubscriber("订阅者");
////        subscriber.subscribe(publish_channel_Name);
////    }
}
