diff --git a/README.md b/README.md index 0a90429..6573d15 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,8 @@ Pipeline分为两种方式使用,一种是使用队列的方式,一种是网 ### Pipeline +#### 使用网关集成方式 + 1.打开/simples/JT808.Simples.sln项目进行还原编译生成 2.进入JT808.Gateway.SimpleServer项目下的Debug目录运行服务端 @@ -118,6 +120,21 @@ Pipeline分为两种方式使用,一种是使用队列的方式,一种是网 如图所示: ![demo3](https://github.com/SmallChi/JT808Gateway/blob/master/doc/img/demo3.png) +#### 使用队列方式 + +1.打开/simples/JT808.Simples.sln项目进行还原编译生成 + +2.JT808.Gateway.SimpleQueueServer项目下的Debug目录运行服务端 + +3.JT808.Gateway.SimpleQueueService项目下的Debug目录运行消息处理服务 + +4.进入JT808.Gateway.SimpleClient项目下的Debug目录运行客户端 + +> 注意:需要安装kafka和zookeeper + +如图所示: +![demo4](https://github.com/SmallChi/JT808Gateway/blob/master/doc/img/demo4.png) + ### DotNetty 1.打开/simples/JT808.Simples.sln项目进行还原编译生成 diff --git a/doc/img/demo4.png b/doc/img/demo4.png new file mode 100644 index 0000000..f1955a6 Binary files /dev/null and b/doc/img/demo4.png differ diff --git a/simples/JT808.Gateway.SimpleClient/JT808.Gateway.SimpleClient.csproj b/simples/JT808.Gateway.SimpleClient/JT808.Gateway.SimpleClient.csproj index b1f2173..7d2ab2b 100644 --- a/simples/JT808.Gateway.SimpleClient/JT808.Gateway.SimpleClient.csproj +++ b/simples/JT808.Gateway.SimpleClient/JT808.Gateway.SimpleClient.csproj @@ -6,8 +6,8 @@ - - + + diff --git a/simples/JT808.Gateway.SimpleQueueServer/JT808.Gateway.SimpleQueueServer.csproj b/simples/JT808.Gateway.SimpleQueueServer/JT808.Gateway.SimpleQueueServer.csproj new file mode 100644 index 0000000..a274481 --- /dev/null +++ b/simples/JT808.Gateway.SimpleQueueServer/JT808.Gateway.SimpleQueueServer.csproj @@ -0,0 +1,23 @@ + + + + Exe + netcoreapp3.1 + + + + + + + + + + + + + + Always + + + + diff --git a/simples/JT808.Gateway.SimpleQueueServer/Program.cs b/simples/JT808.Gateway.SimpleQueueServer/Program.cs new file mode 100644 index 0000000..d7f7dea --- /dev/null +++ b/simples/JT808.Gateway.SimpleQueueServer/Program.cs @@ -0,0 +1,45 @@ +using JT808.Protocol; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using System; +using System.Threading.Tasks; +using JT808.Gateway.Kafka; + +namespace JT808.Gateway.SimpleQueueServer +{ + class Program + { + static async Task Main(string[] args) + { + var serverHostBuilder = new HostBuilder() + .ConfigureAppConfiguration((hostingContext, config) => + { + config.SetBasePath(AppDomain.CurrentDomain.BaseDirectory); + config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); + }) + .ConfigureLogging((context, logging) => + { + logging.AddConsole(); + logging.SetMinimumLevel(LogLevel.Trace); + }) + .ConfigureServices((hostContext, services) => + { + services.AddSingleton(); + services.AddSingleton(typeof(ILogger<>), typeof(Logger<>)); + services.AddJT808Configure() + .AddQueueGateway(hostContext.Configuration) + .AddServerKafkaMsgProducer(hostContext.Configuration) + .AddServerKafkaMsgReplyConsumer(hostContext.Configuration) + .AddServerKafkaSessionProducer(hostContext.Configuration) + .AddTcp() + .AddUdp() + .AddGrpc() + .Builder(); + }); + + await serverHostBuilder.RunConsoleAsync(); + } + } +} diff --git a/simples/JT808.Gateway.SimpleQueueService/Impl/JT808QueueReplyMessageHandlerImpl.cs b/simples/JT808.Gateway.SimpleQueueService/Impl/JT808QueueReplyMessageHandlerImpl.cs new file mode 100644 index 0000000..e7c200a --- /dev/null +++ b/simples/JT808.Gateway.SimpleQueueService/Impl/JT808QueueReplyMessageHandlerImpl.cs @@ -0,0 +1,37 @@ +using JT808.Gateway.Abstractions; +using JT808.Protocol; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT808.Gateway.SimpleQueueService.Impl +{ + public class JT808QueueReplyMessageHandlerImpl : JT808QueueReplyMessageHandler + { + public JT808QueueReplyMessageHandlerImpl(IJT808Config jT808Config, IJT808MsgReplyProducer jT808MsgReplyProducer) : base(jT808Config, jT808MsgReplyProducer) + { + //添加自定义消息 + HandlerDict.Add(0x9999, Msg0x9999); + } + + /// + /// 重写消息 + /// + /// + /// + public override byte[] Msg0x0001(JT808HeaderPackage request) + { + return base.Msg0x0001(request); + } + + /// + /// 自定义消息 + /// + /// + /// + public byte[] Msg0x9999(JT808HeaderPackage request) + { + return default; + } + } +} diff --git a/simples/JT808.Gateway.SimpleQueueService/Impl/JT808SessionNoticeServiceImpl.cs b/simples/JT808.Gateway.SimpleQueueService/Impl/JT808SessionNoticeServiceImpl.cs new file mode 100644 index 0000000..404ed26 --- /dev/null +++ b/simples/JT808.Gateway.SimpleQueueService/Impl/JT808SessionNoticeServiceImpl.cs @@ -0,0 +1,20 @@ +using JT808.Gateway.SessionNotice; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT808.Gateway.SimpleQueueService.Impl +{ + public class JT808SessionNoticeServiceImpl : JT808SessionNoticeService + { + public JT808SessionNoticeServiceImpl(ILoggerFactory loggerFactory) : base(loggerFactory) + { + } + + public override void Processor((string Notice, string TerminalNo) parameter) + { + base.Processor(parameter); + } + } +} diff --git a/simples/JT808.Gateway.SimpleQueueService/JT808.Gateway.SimpleQueueService.csproj b/simples/JT808.Gateway.SimpleQueueService/JT808.Gateway.SimpleQueueService.csproj new file mode 100644 index 0000000..0b018d1 --- /dev/null +++ b/simples/JT808.Gateway.SimpleQueueService/JT808.Gateway.SimpleQueueService.csproj @@ -0,0 +1,29 @@ + + + + Exe + netcoreapp3.1 + + + + + + + + + + + + + + + + + + + + Always + + + + diff --git a/simples/JT808.Gateway.SimpleQueueService/Program.cs b/simples/JT808.Gateway.SimpleQueueService/Program.cs new file mode 100644 index 0000000..add3c80 --- /dev/null +++ b/simples/JT808.Gateway.SimpleQueueService/Program.cs @@ -0,0 +1,43 @@ +using JT808.Protocol; +using JT808.Gateway.Kafka; +using JT808.Gateway.ReplyMessage; +using JT808.Gateway.SessionNotice; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using System; +using System.Threading.Tasks; +using JT808.Gateway.SimpleQueueService.Impl; + +namespace JT808.Gateway.SimpleQueueService +{ + class Program + { + static async Task Main(string[] args) + { + var hostBuilder = new HostBuilder() + .ConfigureAppConfiguration((hostContext, config) => { + config.SetBasePath(AppDomain.CurrentDomain.BaseDirectory); + config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); + }) + .ConfigureLogging((hostContext, configLogging) => { + configLogging.AddConsole(); + configLogging.SetMinimumLevel(LogLevel.Trace); + }) + .ConfigureServices((hostContext, services) => { + services.AddSingleton(); + services.AddSingleton(typeof(ILogger<>), typeof(Logger<>)); + services.AddJT808Configure() + .AddClientKafka() + .AddMsgConsumer(hostContext.Configuration) + .AddMsgReplyProducer(hostContext.Configuration) + .AddSessionConsumer(hostContext.Configuration) + .AddReplyMessage() + .AddSessionNotice(); + }); + + await hostBuilder.RunConsoleAsync(); + } + } +} diff --git a/simples/JT808.Gateway.SimpleServer/Impl/JT808NormalReplyMessageHandlerImpl.cs b/simples/JT808.Gateway.SimpleServer/Impl/JT808NormalReplyMessageHandlerImpl.cs index 74efb98..1f8b8c9 100644 --- a/simples/JT808.Gateway.SimpleServer/Impl/JT808NormalReplyMessageHandlerImpl.cs +++ b/simples/JT808.Gateway.SimpleServer/Impl/JT808NormalReplyMessageHandlerImpl.cs @@ -46,7 +46,7 @@ namespace JT808.Gateway.SimpleServer.Impl //转发数据(可同步也可以使用队列进行异步) try { - jT808TransmitService.Send(parameter); + jT808TransmitService.SendAsync(parameter); } catch (Exception ex) { diff --git a/simples/JT808.Gateway.SimpleServer/JT808.Gateway.SimpleServer.csproj b/simples/JT808.Gateway.SimpleServer/JT808.Gateway.SimpleServer.csproj index e5b8757..ac7c4b3 100644 --- a/simples/JT808.Gateway.SimpleServer/JT808.Gateway.SimpleServer.csproj +++ b/simples/JT808.Gateway.SimpleServer/JT808.Gateway.SimpleServer.csproj @@ -5,23 +5,17 @@ netcoreapp3.1 - - - - - - - + + + + + + + - - - - - Always - @@ -29,4 +23,5 @@ + diff --git a/simples/JT808.Simples.sln b/simples/JT808.Simples.sln index 1a12087..163bff3 100644 --- a/simples/JT808.Simples.sln +++ b/simples/JT808.Simples.sln @@ -13,6 +13,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT808.Gateway.SimpleServer" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT808.Gateway.SimpleClient", "JT808.Gateway.SimpleClient\JT808.Gateway.SimpleClient.csproj", "{09AFAC3E-4E4D-4B51-962D-BF8489D8BEC6}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JT808.Gateway.SimpleQueueServer", "JT808.Gateway.SimpleQueueServer\JT808.Gateway.SimpleQueueServer.csproj", "{8594AC7F-18B4-439D-B58B-1CEFF0833A1A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JT808.Gateway.SimpleQueueService", "JT808.Gateway.SimpleQueueService\JT808.Gateway.SimpleQueueService.csproj", "{E2D1CFEF-417A-4C44-BC2E-E5A160602485}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -35,6 +39,14 @@ Global {09AFAC3E-4E4D-4B51-962D-BF8489D8BEC6}.Debug|Any CPU.Build.0 = Debug|Any CPU {09AFAC3E-4E4D-4B51-962D-BF8489D8BEC6}.Release|Any CPU.ActiveCfg = Release|Any CPU {09AFAC3E-4E4D-4B51-962D-BF8489D8BEC6}.Release|Any CPU.Build.0 = Release|Any CPU + {8594AC7F-18B4-439D-B58B-1CEFF0833A1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8594AC7F-18B4-439D-B58B-1CEFF0833A1A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8594AC7F-18B4-439D-B58B-1CEFF0833A1A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8594AC7F-18B4-439D-B58B-1CEFF0833A1A}.Release|Any CPU.Build.0 = Release|Any CPU + {E2D1CFEF-417A-4C44-BC2E-E5A160602485}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E2D1CFEF-417A-4C44-BC2E-E5A160602485}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E2D1CFEF-417A-4C44-BC2E-E5A160602485}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E2D1CFEF-417A-4C44-BC2E-E5A160602485}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -44,6 +56,8 @@ Global {CCE6AEFB-1AB0-4BD9-8EA2-8B4CDD097E88} = {2459FB59-8A33-49A4-ADBC-A0B12C5886A6} {98E1CDD0-4D4E-48FE-968E-260F0CD5F4D3} = {2459FB59-8A33-49A4-ADBC-A0B12C5886A6} {09AFAC3E-4E4D-4B51-962D-BF8489D8BEC6} = {2459FB59-8A33-49A4-ADBC-A0B12C5886A6} + {8594AC7F-18B4-439D-B58B-1CEFF0833A1A} = {2459FB59-8A33-49A4-ADBC-A0B12C5886A6} + {E2D1CFEF-417A-4C44-BC2E-E5A160602485} = {2459FB59-8A33-49A4-ADBC-A0B12C5886A6} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {FC0FFCEA-E1EF-4C97-A1C5-F89418B6834B}