Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

81 linhas
3.9 KiB

  1. using System;
  2. using System.Threading.Tasks;
  3. using Microsoft.Extensions.DependencyInjection;
  4. using Microsoft.Extensions.Hosting;
  5. using Microsoft.Extensions.Logging;
  6. using JT808.Protocol;
  7. using Microsoft.Extensions.Configuration;
  8. using NLog.Extensions.Logging;
  9. using JT808.Gateway.MsgLogging;
  10. using JT808.Gateway.ReplyMessage;
  11. using JT808.Gateway.Transmit;
  12. using JT808.Gateway.Abstractions;
  13. using JT808.Gateway.SessionNotice;
  14. using JT808.Gateway.Client;
  15. using JT808.Gateway.QueueHosting.Jobs;
  16. using JT808.Gateway.Kafka;
  17. using JT808.Gateway.WebApiClientTool;
  18. using JT808.Gateway.QueueHosting.Impl;
  19. using JT808.Gateway.MsgIdHandler;
  20. namespace JT808.Gateway.QueueHosting
  21. {
  22. class Program
  23. {
  24. static async Task Main(string[] args)
  25. {
  26. var serverHostBuilder = new HostBuilder()
  27. .ConfigureAppConfiguration((hostingContext, config) =>
  28. {
  29. config.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
  30. .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
  31. .AddJsonFile($"appsettings.{ hostingContext.HostingEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true);
  32. })
  33. .ConfigureLogging((context, logging) =>
  34. {
  35. Console.WriteLine($"Environment.OSVersion.Platform:{Environment.OSVersion.Platform.ToString()}");
  36. NLog.LogManager.LoadConfiguration($"Configs/nlog.{Environment.OSVersion.Platform.ToString()}.config");
  37. logging.AddNLog(new NLogProviderOptions { CaptureMessageTemplates = true, CaptureMessageProperties = true });
  38. logging.SetMinimumLevel(LogLevel.Trace);
  39. })
  40. .ConfigureServices((hostContext, services) =>
  41. {
  42. services.AddSingleton<ILoggerFactory, LoggerFactory>();
  43. services.AddSingleton(typeof(ILogger<>), typeof(Logger<>));
  44. services.AddJT808Configure()
  45. //添加客户端工具
  46. .AddClient()
  47. .AddClientReport()
  48. .Builder()
  49. //方式1:客户端webapi调用
  50. .AddWebApiClientTool(hostContext.Configuration)
  51. //添加客户端服务
  52. .AddClientKafka()
  53. .AddMsgConsumer(hostContext.Configuration)
  54. //添加消息上行处理器
  55. .AddMsgIdHandler<JT808UpMessageHandlerImpl>()
  56. //添加消息应答生产者
  57. .AddMsgReplyProducer(hostContext.Configuration)
  58. //添加消息应答服务并实现消息应答处理
  59. .AddReplyMessage<JT808DownMessageHandlerImpl>()
  60. .Builder()
  61. //添加消息应答处理
  62. .AddGateway(hostContext.Configuration)
  63. .AddMessageHandler<JT808CustomMessageHandlerImpl>()
  64. .AddServerKafkaMsgProducer(hostContext.Configuration)
  65. .AddServerKafkaSessionProducer(hostContext.Configuration)
  66. .AddServerKafkaMsgReplyConsumer(hostContext.Configuration)
  67. .AddTcp()
  68. .AddUdp();
  69. //方式2:客户端webapi调用
  70. //services.AddJT808WebApiClientTool(hostContext.Configuration);
  71. //httpclient客户端调用
  72. services.AddHostedService<CallHttpClientJob>();
  73. //客户端测试
  74. services.AddHostedService<UpJob>();
  75. });
  76. await serverHostBuilder.RunConsoleAsync();
  77. }
  78. }
  79. }