You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 satır
3.4KB

  1. using Microsoft.Extensions.Logging;
  2. using Newtonsoft.Json;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using TelpoPush.Models.Dto;
  9. using TelpoPush.Models.Enum;
  10. using TelpoPush.Models.MqTemplates;
  11. using TelpoPush.Models.PushTemplates;
  12. namespace TelpoPush.Service.Mq.Kafka
  13. {
  14. public class MqProcessMessage
  15. {
  16. private readonly ILogger<MqProcessMessage> _logger;
  17. private readonly MessageProducer _messageProducer;
  18. public MqProcessMessage(ILogger<MqProcessMessage> logger, MessageProducer producer)
  19. {
  20. _logger = logger;
  21. _messageProducer = producer;
  22. }
  23. public async Task ProcessWxAlarm(WxModel model, string timeString)
  24. {
  25. List<TopicModel> ls = new List<TopicModel>();
  26. ls.Add(new TopicModel()
  27. {
  28. Topic = "topic.push.wx",
  29. Headers = _messageProducer.CreateHeader(new Dictionary<string, int>
  30. {
  31. {MqHeader.DataType,(int)MqDataType.AlarmInfo },
  32. })
  33. });
  34. await _messageProducer.ProduceAsync(ls, new
  35. {
  36. messageId = string.Format("{0:yyyyMMddHHmmssffff}", DateTime.Now),
  37. topic = string.Join(",", ls.Select(e => e.Topic)), //MqTopic.Wx,
  38. time = timeString,
  39. data = model
  40. });
  41. _logger.LogInformation($"【成功】Third推送(topic.wx):IMEI<{model.imei}>,pushData:{JsonConvert.SerializeObject(model)}");
  42. }
  43. public async Task ProcessProperty(string imei, BaseModel model, HeadersDto headers)
  44. {
  45. List<TopicModel> ls = new List<TopicModel>();
  46. ls.Add(new TopicModel()
  47. {
  48. Topic = "topic.push.property",
  49. Headers = _messageProducer.CreateHeader(new Dictionary<string, int>
  50. {
  51. {MqHeader.DataType,headers.DataType.Value }
  52. })
  53. });
  54. await _messageProducer.ProduceAsync(ls, model);
  55. _logger.LogInformation($"【成功】Third推送(topic.property):IMEI<{imei}>,pushData:{JsonConvert.SerializeObject(model)}");
  56. }
  57. public async Task ProcessDataPushServer(string imei, object model, Dictionary<string, int> headers, string tag)
  58. {
  59. List<TopicModel> ls = new List<TopicModel>();
  60. ls.Add(new TopicModel()
  61. {
  62. Topic = "topic.push",
  63. Headers = _messageProducer.CreateHeader(headers)
  64. });
  65. await _messageProducer.ProduceAsync(ls, model);
  66. _logger.LogInformation($"【{tag}-成功】Third推送(topic.push):IMEI<{imei}>,Header<{JsonConvert.SerializeObject(headers)}>,pushData:{JsonConvert.SerializeObject(model)}");
  67. }
  68. public async Task ProcessThirdhServer(string imei, object model, Dictionary<string, int> headers, string tag)
  69. {
  70. List<TopicModel> ls = new List<TopicModel>();
  71. ls.Add(new TopicModel()
  72. {
  73. Topic = "topic.push.third",
  74. Headers = _messageProducer.CreateHeader(headers)
  75. });
  76. await _messageProducer.ProduceAsync(ls, model);
  77. _logger.LogInformation($"【{tag}-成功】Third推送(topic.push.third):IMEI<{imei}>,Header<{JsonConvert.SerializeObject(headers)}>,pushData:{JsonConvert.SerializeObject(model)}");
  78. }
  79. }
  80. }