Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

PackageProcess.cs 1.5KB

1 år sedan
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using HealthMonitor.Common;
  2. using HealthMonitor.Service.Resolver.Interface;
  3. using HealthMonitor.Service.Sub;
  4. using HealthMonitor.Service.Sub.Interface;
  5. using System.Collections.Concurrent;
  6. namespace HealthMonitor.WebApi
  7. {
  8. public class PackageProcess : IDisposable
  9. {
  10. private readonly ILogger<PackageProcess> _logger;
  11. private readonly MsgQueueManager _msgQueueManager;
  12. public PackageProcess(ILogger<PackageProcess> logger, MsgQueueManager msgQueueManager)
  13. {
  14. _logger = logger;
  15. _msgQueueManager = msgQueueManager;
  16. }
  17. public async Task<bool> ResolveAsync()
  18. {
  19. _msgQueueManager.TryDequeue(out var msg);
  20. if (msg == null) return false;
  21. var resolver = _msgQueueManager.GetMsgResolver(msg!);
  22. using (_logger.BeginScope(new Dictionary<string, object> { ["RequestId"] = msg!.MessageId }))
  23. using (new CustomizeStopWatch(msg!.Topic, _logger))
  24. {
  25. try
  26. {
  27. if (resolver != null)
  28. {
  29. await resolver.ExecuteMessageAsync().ConfigureAwait(false);
  30. }
  31. }
  32. catch (Exception ex)
  33. {
  34. _logger.LogError($"未处理异常 message: {ex.Message}\n {ex.StackTrace}");
  35. }
  36. }
  37. return true;
  38. }
  39. public void Dispose()
  40. {
  41. throw new NotImplementedException();
  42. }
  43. }
  44. }