using HealthMonitor.Common; using HealthMonitor.Service.Resolver.Interface; using HealthMonitor.Service.Sub; using HealthMonitor.Service.Sub.Interface; using System.Collections.Concurrent; namespace HealthMonitor.WebApi { public class PackageProcess : IDisposable { private readonly ILogger _logger; private readonly MsgQueueManager _msgQueueManager; public PackageProcess(ILogger logger, MsgQueueManager msgQueueManager) { _logger = logger; _msgQueueManager = msgQueueManager; } public async Task ResolveAsync() { _msgQueueManager.TryDequeue(out var msg); if (msg == null) return false; var resolver = _msgQueueManager.GetMsgResolver(msg!); using (_logger.BeginScope(new Dictionary { ["RequestId"] = msg!.MessageId })) using (new CustomizeStopWatch(msg!.Topic, _logger)) { try { if (resolver != null) { await resolver.ExecuteMessageAsync().ConfigureAwait(false); } } catch (Exception ex) { _logger.LogError($"未处理异常 message: {ex.Message}\n {ex.StackTrace}"); } } return true; } public void Dispose() { throw new NotImplementedException(); } } }