MpOrderService.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Collections.Generic;
  3. using Library;
  4. using System.Linq;
  5. using System.Threading;
  6. using RabbitMQ.Client;
  7. using System.Text;
  8. namespace MySystem
  9. {
  10. public class MpOrderService
  11. {
  12. public readonly static MpOrderService Instance = new MpOrderService();
  13. private MpOrderService()
  14. { }
  15. public void Start()
  16. {
  17. Thread th = new Thread(SendMsg);
  18. th.IsBackground = true;
  19. th.Start();
  20. }
  21. public void SendMsg()
  22. {
  23. RabbitMQClient.Instance.SendMsg("QUEUE_LKB_TRADE_DIVISION");
  24. }
  25. public void dosomething(IModel channel, string QueueName)
  26. {
  27. while (true)
  28. {
  29. string content = MpRedisDbconn.Instance.RPop<string>("MpOrderQueue");
  30. if (!string.IsNullOrEmpty(content))
  31. {
  32. try
  33. {
  34. channel.BasicPublish("", QueueName, null, Encoding.Default.GetBytes(content));
  35. }
  36. catch (Exception ex)
  37. {
  38. function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "设置激活奖励异常");
  39. }
  40. }
  41. else
  42. {
  43. Thread.Sleep(500);
  44. }
  45. }
  46. }
  47. }
  48. }