|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- 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<PackageProcess> _logger;
-
- private readonly MsgQueueManager _msgQueueManager;
-
- public PackageProcess(ILogger<PackageProcess> logger, MsgQueueManager msgQueueManager)
- {
- _logger = logger;
-
- _msgQueueManager = msgQueueManager;
- }
-
- public async Task<bool> ResolveAsync()
- {
- _msgQueueManager.TryDequeue(out var msg);
- if (msg == null) return false;
- var resolver = _msgQueueManager.GetMsgResolver(msg!);
-
- using (_logger.BeginScope(new Dictionary<string, object> { ["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();
- }
- }
- }
|