Program.cs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using Microsoft.Extensions.Hosting;
  3. using Microsoft.Extensions.DependencyInjection;
  4. using XYY.TaskTrack.Standard;
  5. using EasyNetQ;
  6. using Serilog;
  7. using XYY.WindowsService.ReshMQ.Works;
  8. using Grpc.Net.Client;
  9. using Agile.Config.Client;
  10. using System.Net.Http;
  11. using Grpc.Core;
  12. using StackExchange.Redis;
  13. using System.Net;
  14. namespace XYY.WindowsService.ReshMQ
  15. {
  16. class Program
  17. {
  18. public static void Main(string[] args)
  19. {
  20. CreateHostBuilder(args).Build().Run();
  21. }
  22. public static IHostBuilder CreateHostBuilder(string[] args)
  23. {
  24. string trackingGRpcUrl = "https://47.244.232.78:7002";
  25. string zipUpdateGrpcUrl = "https://47.244.232.78:7003";
  26. //#if DEBUG
  27. // trackingGRpcUrl = "https://localhost:7002";
  28. // zipUpdateGrpcUrl = "https://localhost:7003";
  29. // //System.Threading.Thread.Sleep(3000);
  30. //#endif
  31. return Host.CreateDefaultBuilder(args)
  32. .UseWindowsService()//使用windows服务
  33. .ConfigureServices((hostContext, services) =>
  34. {
  35. var httpHandler = new HttpClientHandler();
  36. // Return `true` to allow certificates that are untrusted/invalid
  37. httpHandler.ServerCertificateCustomValidationCallback =
  38. HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
  39. //手动加层代理设置
  40. HttpClient.DefaultProxy = new WebProxy();
  41. var channel = GrpcChannel.ForAddress(trackingGRpcUrl,
  42. new GrpcChannelOptions { HttpHandler = httpHandler });
  43. var TrackingGrpcChanel = new TrackingGrpcChanel
  44. {
  45. Channel = channel
  46. };
  47. var OrderGrpcChannel = new OrderGrpcChannel
  48. {
  49. Channel = GrpcChannel.ForAddress(zipUpdateGrpcUrl,
  50. new GrpcChannelOptions { HttpHandler = httpHandler })
  51. };
  52. services.AddSingleton(x => RabbitHutch.CreateBus(hostContext.Configuration["DBConnectionStrings:RabbitConnection"]));
  53. services.AddSingleton<IMQManager, MQManager>();
  54. services.AddSingleton(x => (TrackingGrpcChanel));
  55. services.AddSingleton(x => (OrderGrpcChannel));
  56. services.AddSingleton<ISeventeenGRPC, SeventeenGRPC>();
  57. services.AddSingleton<IMoreThanOneTicketGrpc, MoreThanOneTicketGrpc>();
  58. var fiddlerLog = new LoggerConfiguration()
  59. .MinimumLevel.Warning()
  60. .MinimumLevel.Override("LogginService", Serilog.Events.LogEventLevel.Warning)
  61. .Enrich.FromLogContext()
  62. .WriteTo.Seq("http://47.244.232.78:5341/")
  63. .WriteTo.Debug()
  64. .CreateLogger();
  65. services.AddLogging(logging =>
  66. {
  67. logging.AddSerilog(fiddlerLog);
  68. });
  69. services.AddHostedService<Work>();
  70. }).ConfigureAppConfiguration((context, config) =>
  71. {
  72. //使用AddAgileConfig配置一个新的IConfigurationSource
  73. config.AddAgileConfig();
  74. });
  75. }
  76. }
  77. }