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.

43 lines
1.4 KiB

  1. using EasyNetQ;
  2. using HKLib.RabbitMQ.Config;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace HKLib.RabbitMQ.Subscriber
  8. {
  9. public class ServiceQueryExcute
  10. {
  11. public static ServiceQueryExcute QueryExcute => new Lazy<ServiceQueryExcute>().Value;
  12. public void ExtuteMQ<TImpl,T>(string Key,MQEnum Type) where TImpl : IAccept, new()
  13. {
  14. Task.Run(() =>
  15. {
  16. AcceptEntity accept = new AcceptEntity();
  17. if (Type == MQEnum.Push)
  18. {
  19. accept.SendType = MQEnum.Push;
  20. accept.ExchangeName = "Message.Direct";
  21. accept.QueeName = "Meesage.DirectQuene";
  22. accept.RouteName = Key;
  23. }
  24. else if (Type == MQEnum.Sub)
  25. {
  26. accept.SendType = MQEnum.Sub;
  27. accept.ExchangeName = "Message.Fanout";
  28. accept.QueeName = "Meesage.FanoutQuene";
  29. }
  30. else
  31. {
  32. accept.SendType = MQEnum.Top;
  33. accept.ExchangeName = "Message.Topic";
  34. accept.QueeName = "Meesage.FanoutQuene";
  35. accept.RouteName = Key;
  36. }
  37. MQFactory.Subscriber<TImpl, T>(accept);
  38. });
  39. }
  40. }
  41. }