FinanceQuotationJobSub.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Threading.Tasks;
  3. using XYY.TaskTrack.Standard;
  4. using XYY.TaskTrack.Standard.TaskModel;
  5. namespace XYY.WindowsService.MQ
  6. {
  7. public interface IFinanceQuotationJobSub : IBaseConsumer<FinanceQuotation>
  8. {
  9. }
  10. public class FinanceQuotationJobSub : IFinanceQuotationJobSub
  11. {
  12. public FinanceQuotationJobSub()
  13. {
  14. //我们直接使用api推送内容,减少服务依赖
  15. }
  16. public async Task Consume(FinanceQuotation message)
  17. {
  18. try
  19. {
  20. RestSharp.RestClient client = new RestSharp.RestClient("http://120.24.149.148:9521/api/FinanceQuotation/SendNowCustomerQuotaion");
  21. RestSharp.RestRequest request = new RestSharp.RestRequest(RestSharp.Method.POST);
  22. request.AddJsonBody(message);
  23. var response = client.Execute(request);
  24. if (response.StatusCode == System.Net.HttpStatusCode.OK)
  25. {
  26. Console.WriteLine(message.CustomerName + " " + message.EntryTime + "消息推送成功");
  27. }
  28. else
  29. {
  30. Console.WriteLine(message.CustomerName + " " + message.EntryTime
  31. + "消息推送错误" + (response.Content ?? response.ErrorMessage));
  32. }
  33. }
  34. catch (Exception ex)
  35. {
  36. Console.WriteLine(message.CustomerName + " " + message.EntryTime + "消息推送错误:" + ex.Message);
  37. }
  38. }
  39. }
  40. }