/// <summary> /// 停止消费者 /// </summary> public static void StopConsumer() { //Disposing channel and connection objects is not enough, they must be explicitly closed if (_channel != null) { SafeInvokeUtils.Safe(() => { _channel.Close(); }, ex => { NLogHelper.Error($"关闭RabbitMQ的channel失败:{ex}"); }); _channel = null; } if (_connection != null) { SafeInvokeUtils.Safe(() => { _connection.Close(); }, ex => { NLogHelper.Error($"关闭RabbitMQ的connection失败:{ex}"); }); _connection = null; } lock (SLocker) { _isAlive = false; } }
/// <summary> /// 清理资源函数 /// </summary> public void Dispose() { if (_udpClient == null) { return; } SafeInvokeUtils.Safe(_udpClient.Close); }