PrizeSendService.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Collections.Generic;
  3. using Library;
  4. using LitJson;
  5. using System.Linq;
  6. using System.Threading;
  7. using System.Text;
  8. namespace MySystem
  9. {
  10. public class PrizeSendService
  11. {
  12. public readonly static PrizeSendService Instance = new PrizeSendService();
  13. private PrizeSendService()
  14. { }
  15. public void Start()
  16. {
  17. Thread th = new Thread(dosomething);
  18. th.IsBackground = true;
  19. th.Start();
  20. }
  21. public void dosomething()
  22. {
  23. while (true)
  24. {
  25. string content = RedisDbconn.Instance.RPop<string>("PrizeSendQueue");
  26. if (!string.IsNullOrEmpty(content))
  27. {
  28. try
  29. {
  30. JsonData jsonObj = JsonMapper.ToObject(content);
  31. RabbitMQPrize.Instance.SendMsg(jsonObj["content"].ToString(), "PRIZE_SEND_QUEUE_" + jsonObj["prize_tag"].ToString());
  32. }
  33. catch (Exception ex)
  34. {
  35. Utils.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "推送客小爽机具数据异常");
  36. }
  37. }
  38. else
  39. {
  40. Thread.Sleep(2000);
  41. }
  42. }
  43. }
  44. }
  45. }