/// <summary>
 /// //从队列中出队,获取异常对象
 /// </summary>
 /// <param name="listid"></param>
 /// <returns></returns>
 public static string DequeueItemFromList(string listid)
 {
     using (IRedisClient redis = prcm.GetClient())
     {
         return(redis.DequeueItemFromList(listid));
     }
 }
Exemple #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //新开一个线程去轮询消息队列,如果有异常消息,则取出执行。
            //用CLR维护的线程池里的线程性能更好
            var fileLogPath = @"C:\Users\Victor\Documents\GitHub\CSharpLearning\07_MvcOA\07_MvcOA.LuceneNet\Log\";

            //WaitCallback
            ThreadPool.QueueUserWorkItem(a =>
            {
                //必须死循环,否则执行后线程释放
                while (true)
                {
                    if (redisClient.GetListCount("errorMsg") > 0)
                    {
                        var ex       = redisClient.DequeueItemFromList("errorMsg");
                        var fileName = DateTime.Now.ToString("yyyy-M-d") + ".txt";
                        File.AppendAllText(fileLogPath + fileName, ex.ToString(), Encoding.Default);
                    }
                    else
                    {
                        //线程休息,节约CPU开销
                        Thread.Sleep(3000);
                    }
                }
            }, fileLogPath);
        }
Exemple #3
0
 public string DeQueue(string key)
 {
     using (IRedisClient Redis = RedisManager.GetClient())
     {
         return(Redis.DequeueItemFromList(key));
     }
 }
Exemple #4
0
 public string Dequeue()
 {
     using (IRedisClient redisClent = RedisHelper.clientManager.GetClient())
     {
         return(redisClent.DequeueItemFromList(rp.QueueName));
     }
 }
Exemple #5
0
 /// <summary>
 /// 从消息队列中取出数据
 /// </summary>
 /// <param name="listId">队列Id</param>
 /// <returns></returns>
 public static string Dequeue(string listId)
 {
     listId = Prefix + listId;
     using (IRedisClient client = RedisManager.ClientManager.GetClient())
     {
         return(client.DequeueItemFromList(listId));
     }
 }
Exemple #6
0
 public override T DequeueItemFromList <T>(string listId)
 {
     using (IRedisClient redis = GetRedisClient())
     {
         var lstStr = redis.DequeueItemFromList(listId);
         if (lstStr == null)
         {
             return(default(T));
         }
         return(JsonConvert.DeserializeObject <T>(lstStr));
     }
 }
Exemple #7
0
 public static string DequeueItemFromList(string key)
 {
     try
     {
         using (IRedisClient client = GetClient())
         {
             return client.DequeueItemFromList(key);
         }
     }
     catch (Exception ex)
     {
         return string.Empty;
     }
 }
Exemple #8
0
 /// <summary>
 /// 出队列
 /// </summary>
 public static string GetQueue(string key, RedisEnum redisEnum = RedisEnum.Main)
 {
     try
     {
         using (IRedisClient iRedisClient = redisEnum == RedisEnum.Main ? MainRedisClientManager.GetClient() : CommonRedisClientManager.GetClient())
         {
             iRedisClient.Password = redisEnum == RedisEnum.Main ? MainMasterPwd : CommonMasterPwd;
             return(iRedisClient.DequeueItemFromList(key));
         }
     }
     catch (Exception ex)
     {
         FileHelper.logger.Warn("Redis出队列时异常 || " + ex.Message);
     }
     return(string.Empty);
 }
Exemple #9
0
 /// <summary>
 /// 接收消息(生产者消费者模式)
 /// </summary>
 public string Receive(string queueName, int db = 0)
 {
     try
     {
         Context.Db = db;
         if (string.IsNullOrEmpty(queueName))
         {
             return("");
         }
         else
         {
             return(Context.DequeueItemFromList(queueName));
         }
     }
     catch (RedisException ex)
     {
         SaveLog(ex, "Receive", "");
         return("");
     }
 }
        /// <summary>
        /// 接受消息
        /// </summary>
        /// <param name="queueName"></param>
        /// <returns></returns>
        public ResponseResult ReceiveMessage(string queueName)
        {
            ResponseResult result = ResponseResult.Default();

            try
            {
                //NLogHelper.Instance.Info("开始ReceiveMessage=>Redis MQ消息队列......");
                if (string.IsNullOrEmpty(queueName))
                {
                    result = ResponseResult.Faild("queueName不能为空!");
                    return(result);
                }

                using (IRedisClient redisClient = RedisManager.GetClient())
                {
                    var count = redisClient.GetListCount(queueName);
                    if (count > 0)
                    {
                        result.Msg           = redisClient.DequeueItemFromList(queueName);
                        result.RequestStatus = (int)ResultFlags.OK;
                        NLogHelper.Instance.Info(string.Format("ReceiveMessage=>Redis MQ消息队列:{0},消息:{1}......", queueName, result.Msg));
                    }
                    else
                    {
                        result.Msg           = string.Format("当前队列{0}中没有消息队列", queueName);
                        result.RequestStatus = (int)ResultFlags.NotFound;
                    }
                }
            }
            catch (System.Exception ex)
            {
                result.RequestStatus = (int)ResponseResultStatus.Exception;
                result.Msg           = ex.Message;
                NLogHelper.Instance.Info(string.Format("ReceiveMessage=>Redis MQ消息队列Exception异常:{0}", ex.Message));
            }
            finally
            {
                //NLogHelper.Instance.Info("结束ReceiveMessage=>Redis MQ消息队列......");
            }
            return(result);
        }
Exemple #11
0
        static void Main(string[] args)
        {
            #region 客户端添加消息
            redisClient.EnqueueItemOnList("Log", "1111");
            redisClient.EnqueueItemOnList("Log", "222");
            redisClient.EnqueueItemOnList("Log", "333");
            #endregion

            #region  务器端扫码消息
            ThreadPool.QueueUserWorkItem(o =>
            {
                while (true)
                {
                    try
                    {
                        if (redisClient.GetListCount("Log") > 0)
                        {
                            string log = redisClient.DequeueItemFromList("Log");
                            if (!string.IsNullOrEmpty(log))
                            {
                                Console.WriteLine(log);
                            }
                        }
                        else
                        {
                            Thread.Sleep(1000);    //为避免CPU空转,在队列为空时休息1秒
                        }
                    }
                    catch (Exception ex)
                    {
                        redisClient.EnqueueItemOnList("Log", ex.ToString());
                    }
                }
            });
            #endregion

            Console.ReadLine();
        }
Exemple #12
0
        /// <summary>
        /// 接收消息(生产者消费者模式)
        /// </summary>
        public static string Receive(string queueName, int db = 0)
        {
            try
            {
                using (IRedisClient redis = Context(db).GetClient())
                {
                    if (string.IsNullOrEmpty(queueName))
                    {
                        return("");
                    }
                    else
                    {
                        return(redis.DequeueItemFromList(queueName));
                    }
                }
            }
            catch (RedisException ex)
            {
                SaveLog(ex, "Receive", "");

                return("");
            }
        }
Exemple #13
0
 /// <summary>
 /// 从消息队列中取出数据
 /// </summary>
 /// <param name="redisClient"></param>
 /// <param name="listId"></param>
 /// <returns></returns>
 public static string Dequeue(IRedisClient redisClient, string listId)
 {
     listId = Prefix + listId;
     return(redisClient.DequeueItemFromList(listId));
 }
Exemple #14
0
 //出队里
 public static string Popqueue(string listId)
 {
     return(Redisclient.DequeueItemFromList(listId));
 }
Exemple #15
0
 public string DequeueItemFromList(string listId)
 {
     return(_redisCli.DequeueItemFromList(listId));
 }
Exemple #16
0
 /// <summary>
 /// 出队列
 /// </summary>
 /// <param name="key"></param>
 public string Deque(string key)
 {
     return(redisClent.DequeueItemFromList(key));
 }
 /// <summary>
 /// 出队
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public static string Dequeue(string name)
 {
     return(redisClent.DequeueItemFromList(name));
 }
 /// <summary>
 ///   队列中取出一个值
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public string DeQueenOnList(string key)
 {
     return(RedisClient.DequeueItemFromList(key));
 }