Program.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. namespace XYY.WindowsService.ReshMQ
  13. {
  14. class Program
  15. {
  16. public static void Main(string[] args)
  17. {
  18. CreateHostBuilder(args).Build().Run();
  19. }
  20. public static IHostBuilder CreateHostBuilder(string[] args)
  21. {
  22. string trackingGRpcUrl = "https://47.244.232.78:7002";
  23. string zipUpdateGrpcUrl = "https://47.244.232.78:7003";
  24. //#if DEBUG
  25. // trackingGRpcUrl = "https://localhost:7002";
  26. // zipUpdateGrpcUrl = "https://localhost:7003";
  27. // //System.Threading.Thread.Sleep(3000);
  28. //#endif
  29. return Host.CreateDefaultBuilder(args)
  30. .UseWindowsService()//使用windows服务
  31. .ConfigureServices((hostContext, services) =>
  32. {
  33. var httpHandler = new HttpClientHandler();
  34. // Return `true` to allow certificates that are untrusted/invalid
  35. httpHandler.ServerCertificateCustomValidationCallback =
  36. HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
  37. var channel = GrpcChannel.ForAddress(trackingGRpcUrl,
  38. new GrpcChannelOptions { HttpHandler = httpHandler });
  39. var TrackingGrpcChanel = new TrackingGrpcChanel
  40. {
  41. Channel = channel
  42. };
  43. var OrderGrpcChannel = new OrderGrpcChannel
  44. {
  45. Channel = GrpcChannel.ForAddress(zipUpdateGrpcUrl,
  46. new GrpcChannelOptions { HttpHandler = httpHandler })
  47. };
  48. services.AddSingleton(x => RabbitHutch.CreateBus(hostContext.Configuration["DBConnectionStrings:RabbitConnection"]));
  49. services.AddSingleton<IMQManager, MQManager>();
  50. services.AddSingleton(x => (TrackingGrpcChanel));
  51. services.AddSingleton(x => (OrderGrpcChannel));
  52. services.AddSingleton<ISeventeenGRPC, SeventeenGRPC>();
  53. services.AddSingleton<IMoreThanOneTicketGrpc, MoreThanOneTicketGrpc>();
  54. var fiddlerLog = new LoggerConfiguration()
  55. .MinimumLevel.Warning()
  56. .MinimumLevel.Override("LogginService", Serilog.Events.LogEventLevel.Warning)
  57. .Enrich.FromLogContext()
  58. .WriteTo.Seq("http://47.244.232.78:5341/")
  59. .WriteTo.Debug()
  60. .CreateLogger();
  61. services.AddLogging(logging =>
  62. {
  63. logging.AddSerilog(fiddlerLog);
  64. });
  65. services.AddHostedService<Work>();
  66. }).ConfigureAppConfiguration((context, config) =>
  67. {
  68. //使用AddAgileConfig配置一个新的IConfigurationSource
  69. config.AddAgileConfig();
  70. });
  71. }
  72. }
  73. }