/// <summary> /// MQ回调 /// </summary> /// <param name="state"></param> private static void MQTimerCallBack(object state) { lock (locker) { if (_isRunning) { return; } _isRunning = true; } try { if (!MQConsumer.IsAlive()) { Thread.Sleep(5500); //延迟5s,使其能够自动恢复 if (!MQConsumer.IsAlive()) { if (_isFirstTimeToStartMq) { _isFirstTimeToStartMq = false; NLogHelper.Debug("首次尝试启动MQConsumer"); MQConsumer.InitConsumer(); } else { NLogHelper.Warn("MQ异常,尝试重启 MQConsumer"); MQConsumer.InitConsumer(); } } } else { NLogHelper.Trace("检测MQ连接正常"); } } catch (Exception ex) { NLogHelper.Error("MQ定时器异常:" + ex); } finally { lock (locker) { _isRunning = false; } } }
/// <summary> /// 关闭定时器 /// </summary> public static void Stop() { try { if (_mqTimer != null) { _mqTimer.Dispose(); _mqTimer = null; } } catch { } //关闭MQ MQConsumer.CloseConsumer(); }