private void DealLog(object obj) { QueueOption queueOption = obj as QueueOption; if (queueOption == null) throw new Exception("参数配置有误"); if (string.IsNullOrEmpty(queueOption.QueueName)) throw new Exception("参数配置有误"); if (queueOption.func == null) throw new Exception("参数配置有误"); var queue = new AliyunQueue(queueOption.QueueName); while (true) { //if (queue.IsData) //{ queue.Pop(data => { try { queueOption.func(data); return true; } catch (Exception exception) { //执行外部异常处理方式 //执行休眠100ms-重试-默认5次 //重试一直失败则进行 if (queueOption.ExceptionFunc == null) { Thread.Sleep(100); //for (var i = 0; i < 5; i++) //{ // queueOption.func(data); // return true; //} } else { queueOption.ExceptionFunc(exception); } //返回false继续放入队列 return false; } }); //} //else //{ // Thread.Sleep(1000); //} } }
private static void DealLog() { var queue = new AliyunQueue(); while (true) { lock (queue) { if (queue.IsData) { queue.Pop(data => { try { instance.WriteInfoLog("InfoLog", data); return true; } catch (Exception exception) { return false; } }); } else { Thread.Sleep(1000); } } } }
/// <summary> /// 向消息队列中push数据 /// </summary> /// <param name="messageInfo"></param> public void PushData(MessageInfo messageInfo) { var aliyunQueue = new AliyunQueue("logQueue"); aliyunQueue.Push(messageInfo); }