Пример #1
0
 public void Dispose()
 {
     isdisposeing = true;
     try
     {
         try
         {
             //通知关闭监听通道
             if (redisDb != null)
             {
                 var manager = new XXF.Redis.RedisManager();
                 using (var db = manager.CreateClient(RedisServerIp.Split(':')[0], Convert.ToInt32(RedisServerIp.Split(':')[1]), ""))
                 {
                     db.GetClient().PublishMessage(channelName, "RedisNetCommandListener-Close");
                     db.GetClient().Quit();
                 }
             }
         }
         catch { }
         //关闭当前连接
         CloseRedisClient();
     }
     catch (Exception exp)
     { }
 }
 public void Dispose()
 {
     isdisposeing = true;
     try
     {
         try
         {
             //通知关闭监听通道
             if (redisDb != null)
             {
                 var manager = new XXF.Redis.RedisManager();
                 using (var db = manager.CreateClient(RedisServerIp.Split(':')[0], Convert.ToInt32(RedisServerIp.Split(':')[1]), ""))
                 {
                     db.GetClient().PublishMessage(channelName, "RedisNetCommandListener-Close");
                     db.GetClient().Quit();
                 }
             }
         }
         catch { }
         //关闭当前连接
         CloseRedisClient();
     }
     catch (Exception exp)
     { }
 }
        private void RedisSubscribe(Action <string, string> action, string mqpath, string channelname)
        {
            var manager = new XXF.Redis.RedisManager();

            redisDb = manager.CreateClient(RedisServerIp.Split(':')[0], Convert.ToInt32(RedisServerIp.Split(':')[1]), "");
            using (var subscription = redisDb.GetClient().CreateSubscription())
            {
                subscription.OnSubscribe = channel =>
                {
                    //订阅事件
                };
                subscription.OnUnSubscribe = channel =>
                {
                    //退订事件
                };
                subscription.OnMessage = (channel, msg) =>
                {
                    try
                    {
                        if (msg == "RedisNetCommandListener-Close" || isdisposeing == true)//关闭通道
                        {
                            try { subscription.UnSubscribeFromChannels(channel); }
                            catch { }
                        }
                        else
                        {
                            if (action != null)
                            {
                                action.Invoke(channel, msg);
                            }
                        }
                    }
                    catch (Exception exp)
                    {
                        ErrorLogHelper.WriteLine(-1, mqpath, "RedisSubscribe", string.Format("MQredis订阅通信消息,通道:{1},处理消息{0},订阅名:{2}出错", msg.NullToEmpty(), channelname, Name), exp);
                    }
                };
                subscription.SubscribeToChannels(channelname);
            }
        }
Пример #4
0
        private void RedisSubscribe(Action<string, string> action, string mqpath, string channelname)
        {
            var manager = new XXF.Redis.RedisManager();
            redisDb = manager.CreateClient(RedisServerIp.Split(':')[0], Convert.ToInt32(RedisServerIp.Split(':')[1]), "");
            using (var subscription = redisDb.GetClient().CreateSubscription())
            {
                subscription.OnSubscribe = channel =>
                {

                    //订阅事件
                };
                subscription.OnUnSubscribe = channel =>
                {

                    //退订事件
                };
                subscription.OnMessage = (channel, msg) =>
                {
                    try
                    {
                        if (msg == "RedisNetCommandListener-Close" || isdisposeing==true)//关闭通道
                        {
                            try { subscription.UnSubscribeFromChannels(channel); }
                            catch { }
                        }
                        else
                        {
                            if (action != null)
                                action.Invoke(channel, msg);
                        }
                    }
                    catch (Exception exp)
                    {
                        ErrorLogHelper.WriteLine(-1, mqpath, "RedisSubscribe", string.Format("MQredis订阅通信消息,通道:{1},处理消息{0},订阅名:{2}出错", msg.NullToEmpty(), channelname, Name), exp);
                    }
                };
                subscription.SubscribeToChannels(channelname);
            }
        }