diff --git a/README.md b/README.md index fd5839c..ad7be02 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ [玩一玩压力测试](https://github.com/SmallChi/JT808Gateway/blob/master/doc/README.md) -[![MIT Licence](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/SmallChi/JT808Gateway/blob/master/LICENSE)[![Github Build status](https://github.com/SmallChi/JT808Gateway/workflows/.NET%20Core/badge.svg)]() +[![MIT Licence](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/SmallChi/JT808Gateway/blob/master/LICENSE)![.NET Core](https://github.com/SmallChi/JT808Gateway/workflows/.NET%20Core/badge.svg) ## 新网关的优势 @@ -59,14 +59,22 @@ [GRPC消息业务处理协议](https://github.com/SmallChi/JT808Gateway/blob/master/src/JT808.Gateway.Abstractions/Protos/JT808Gateway.proto) -## 基于core 3.1 Pipeline的NuGet安装 +## 基于core 3.1 Pipeline + +Pipeline分为两种方式使用,一种是使用队列的方式,一种是网关集成的方式。 + +| 使用方式 | 特性 |备注| +|:---|:---|:---|:---| +|使用队列|网关不需要重启,相当于透传数据,设备上来的数据直接入队列,通过服务去处理消息。|设备多的可以这样搞,这样关注点在业务上面。| +|使用网关集成|网关需要根据消息业务的变化去处理,也就意味着更改业务,需要重启网关,但是上手简单。|设备少的,开发能力弱的,允许设备丢点数据的。| + +### Pipeline的NuGet安装 | Package Name | Version | Downloads | | --------------------- | -------------------------------------------------- | --------------------------------------------------- | | Install-Package JT808.Gateway.Abstractions| ![JT808.Gateway.Abstractions](https://img.shields.io/nuget/v/JT808.Gateway.Abstractions.svg) | ![JT808.Gateway.Abstractions](https://img.shields.io/nuget/dt/JT808.Gateway.Abstractions.svg) | | Install-Package JT808.Gateway | ![JT808.Gateway](https://img.shields.io/nuget/v/JT808.Gateway.svg) | ![JT808.Gateway](https://img.shields.io/nuget/dt/JT808.Gateway.svg) | | Install-Package JT808.Gateway.Client| ![JT808.Gateway.Client](https://img.shields.io/nuget/v/JT808.Gateway.Client.svg) | ![JT808.Gateway.Client](https://img.shields.io/nuget/dt/JT808.Gateway.Client.svg) | -| Install-Package JT808.Gateway.InMemoryMQ| ![JT808.Gateway.InMemoryMQ](https://img.shields.io/nuget/v/JT808.Gateway.InMemoryMQ.svg) | ![JT808.Gateway.InMemoryMQ](https://img.shields.io/nuget/dt/JT808.Gateway.InMemoryMQ.svg) | | Install-Package JT808.Gateway.Kafka| ![JT808.Gateway.Kafka](https://img.shields.io/nuget/v/JT808.Gateway.Kafka.svg) | ![JT808.Gateway.Kafka](https://img.shields.io/nuget/dt/JT808.Gateway.Kafka.svg) | | Install-Package JT808.Gateway.Transmit | ![JT808.Gateway.Transmit](https://img.shields.io/nuget/v/JT808.Gateway.Transmit.svg) | ![JT808.Gateway.Transmit](https://img.shields.io/nuget/dt/JT808.Gateway.Transmit.svg) | | Install-Package JT808.Gateway.Traffic | ![JT808.Gateway.Traffic](https://img.shields.io/nuget/v/JT808.Gateway.Traffic.svg) | ![JT808.Gateway.Traffic](https://img.shields.io/nuget/dt/JT808.Gateway.Traffic.svg)| @@ -75,7 +83,9 @@ | Install-Package JT808.Gateway.MsgLogging | ![JT808.Gateway.MsgLogging](https://img.shields.io/nuget/v/JT808.Gateway.MsgLogging.svg) | ![JT808.Gateway.MsgLogging](https://img.shields.io/nuget/dt/JT808.Gateway.MsgLogging.svg)| | Install-Package JT808.Gateway.MsgIdHandler | ![JT808.Gateway.MsgIdHandler](https://img.shields.io/nuget/v/JT808.Gateway.MsgIdHandler.svg) | ![JT808.Gateway.MsgIdHandler](https://img.shields.io/nuget/dt/JT808.Gateway.MsgIdHandler.svg)| -## 基于DotNetty的NuGet安装 +## 基于DotNetty + +### DotNetty的NuGet安装 | Package Name | Version | Downloads | | --------------------- | -------------------------------------------------- | --------------------------------------------------- | diff --git a/doc/README.md b/doc/README.md index 11d2e98..211af29 100644 --- a/doc/README.md +++ b/doc/README.md @@ -6,14 +6,14 @@ > 注意1:连接数和并发数要区分开; > 注意2:阿里云的机器默认有连接数限制(5000),可以先创建一台,把该装的软件安装好,tcp参数内核调优后,在备份一个系统镜像在玩; -> 注意3: 使用的是内存队列(InMemoryMQ)进行测试。 +> 注意3: 使用的是网关集成的方式进行测试。 ``` 1 //使用PM2托管 //服务端 cd /data/JT808.Gateway -pm2 start "dotnet JT808.Gateway.TestHosting.dll ASPNETCORE_ENVIRONMENT=Production" --max-restarts=1 -n "JT808.Gateway.808" -o "/data/pm2Logs/JT808.Gateway/out.log" -e "/data/pm2Logs/JT808.Gateway/error.log" +pm2 start "dotnet JT808.Gateway.ServerBenchmark.dll ASPNETCORE_ENVIRONMENT=Production" --max-restarts=1 -n "JT808.Gateway.808" -o "/data/pm2Logs/JT808.Gateway/out.log" -e "/data/pm2Logs/JT808.Gateway/error.log" //客户端 cd /data/JT808Client @@ -51,8 +51,8 @@ pm2 start "dotnet JT808.Gateway.CleintBenchmark.dll ASPNETCORE_ENVIRONMENT=Produ "JT808Configuration": { "TcpPort": 808, "UdpPort": 808, - "MiniNumBufferSize": 80960, - "SoBacklog": 102400 + "MiniNumBufferSize": 102400, + "SoBacklog": 204800 } ``` @@ -89,8 +89,8 @@ pm2 start "dotnet JT808.Gateway.CleintBenchmark.dll ASPNETCORE_ENVIRONMENT=Produ "JT808Configuration": { "TcpPort": 808, "UdpPort": 808, - "MiniNumBufferSize": 80960, - "SoBacklog": 102400 + "MiniNumBufferSize": 102400, + "SoBacklog": 204800 } ``` @@ -127,8 +127,8 @@ pm2 start "dotnet JT808.Gateway.CleintBenchmark.dll ASPNETCORE_ENVIRONMENT=Produ "JT808Configuration": { "TcpPort": 808, "UdpPort": 808, - "MiniNumBufferSize": 80960, - "SoBacklog": 102400 + "MiniNumBufferSize": 102400, + "SoBacklog": 204800 } ``` @@ -144,6 +144,7 @@ pm2 start "dotnet JT808.Gateway.CleintBenchmark.dll ASPNETCORE_ENVIRONMENT=Produ |:-------:|:-------:|:-------:| | centos7 | 8c16g | JT808服务端 | | centos7 | 8c16g | JT808客户端 | +| centos7 | 8c16g | JT808客户端 | > 计算网络增强型 sn1ne ecs.sn1ne.2xlarge 8 vCPU 16 GiB Intel Xeon E5-2682v4 / Intel Xeon(Skylake) Platinum 8163 2.5 GHz 2 Gbps 100 万 PPS @@ -158,12 +159,10 @@ pm2 start "dotnet JT808.Gateway.CleintBenchmark.dll ASPNETCORE_ENVIRONMENT=Produ "Interval": 1000, "DeviceTemplate": 100000 //需要多台机器同时访问,那么可以根据这个避开重复终端号 100000-200000-300000 } - 修改wwwroot下index.html的webapi接口地址 - 127.0.0.1:15004/index.html ``` ``` 2 - "urls": "http://*:15005;", + "urls": "http://*:15004;", "ClientBenchmarkOptions": { "IP": "", "Port": 808, @@ -171,8 +170,6 @@ pm2 start "dotnet JT808.Gateway.CleintBenchmark.dll ASPNETCORE_ENVIRONMENT=Produ "Interval": 1000, "DeviceTemplate": 200000 //需要多台机器同时访问,那么可以根据这个避开重复终端号 100000-200000-300000 } - 修改wwwroot下index.html的webapi接口地址 - 127.0.0.1:15005/index.html ``` > 一个进程的线程是有限的,所以分两个进程进行测试 @@ -183,7 +180,7 @@ pm2 start "dotnet JT808.Gateway.CleintBenchmark.dll ASPNETCORE_ENVIRONMENT=Produ "JT808Configuration": { "TcpPort": 808, "UdpPort": 808, - "MiniNumBufferSize": 80960, + "MiniNumBufferSize": 102400, "SoBacklog": 102400 } ``` @@ -192,7 +189,7 @@ pm2 start "dotnet JT808.Gateway.CleintBenchmark.dll ASPNETCORE_ENVIRONMENT=Produ ![server_network_40k](https://github.com/SmallChi/JT808Gateway/blob/master/doc/pipeline/server_network_40k.png) -> 由于资源被占满了,所以客户端的界面访问不到,但是不影响总体。 +![client_40k](https://github.com/SmallChi/JT808Gateway/blob/master/doc/pipeline/client_40k.png) ### 60K diff --git a/doc/pipeline/client_10k.png b/doc/pipeline/client_10k.png index 12ce724..4e634c6 100644 Binary files a/doc/pipeline/client_10k.png and b/doc/pipeline/client_10k.png differ diff --git a/doc/pipeline/client_20k.png b/doc/pipeline/client_20k.png index cb71146..18027b8 100644 Binary files a/doc/pipeline/client_20k.png and b/doc/pipeline/client_20k.png differ diff --git a/doc/pipeline/client_30k.png b/doc/pipeline/client_30k.png index 1fa72eb..8092ac6 100644 Binary files a/doc/pipeline/client_30k.png and b/doc/pipeline/client_30k.png differ diff --git a/doc/pipeline/client_40k.png b/doc/pipeline/client_40k.png new file mode 100644 index 0000000..be9b23c Binary files /dev/null and b/doc/pipeline/client_40k.png differ diff --git a/doc/pipeline/client_60k.png b/doc/pipeline/client_60k.png index 42e7006..8aae1b6 100644 Binary files a/doc/pipeline/client_60k.png and b/doc/pipeline/client_60k.png differ diff --git a/doc/pipeline/server_network_10k.png b/doc/pipeline/server_network_10k.png index bbb7a4b..a9bc1a7 100644 Binary files a/doc/pipeline/server_network_10k.png and b/doc/pipeline/server_network_10k.png differ diff --git a/doc/pipeline/server_network_20k.png b/doc/pipeline/server_network_20k.png index 4a4fd1b..22c4275 100644 Binary files a/doc/pipeline/server_network_20k.png and b/doc/pipeline/server_network_20k.png differ diff --git a/doc/pipeline/server_network_30k.png b/doc/pipeline/server_network_30k.png index 35d2d8e..6173919 100644 Binary files a/doc/pipeline/server_network_30k.png and b/doc/pipeline/server_network_30k.png differ diff --git a/doc/pipeline/server_network_40k.png b/doc/pipeline/server_network_40k.png index 316930a..b720434 100644 Binary files a/doc/pipeline/server_network_40k.png and b/doc/pipeline/server_network_40k.png differ diff --git a/doc/pipeline/server_network_60k.png b/doc/pipeline/server_network_60k.png index 0749740..70ba453 100644 Binary files a/doc/pipeline/server_network_60k.png and b/doc/pipeline/server_network_60k.png differ diff --git a/doc/pipeline/server_proccess_10k.png b/doc/pipeline/server_proccess_10k.png index 25f3fa8..f31c186 100644 Binary files a/doc/pipeline/server_proccess_10k.png and b/doc/pipeline/server_proccess_10k.png differ diff --git a/doc/pipeline/server_proccess_20k.png b/doc/pipeline/server_proccess_20k.png index 3c8ee22..a9cfc35 100644 Binary files a/doc/pipeline/server_proccess_20k.png and b/doc/pipeline/server_proccess_20k.png differ diff --git a/doc/pipeline/server_proccess_30k.png b/doc/pipeline/server_proccess_30k.png index fe27955..f39c986 100644 Binary files a/doc/pipeline/server_proccess_30k.png and b/doc/pipeline/server_proccess_30k.png differ diff --git a/doc/pipeline/server_proccess_40k.png b/doc/pipeline/server_proccess_40k.png index 8474d7e..4bf9e15 100644 Binary files a/doc/pipeline/server_proccess_40k.png and b/doc/pipeline/server_proccess_40k.png differ diff --git a/doc/pipeline/server_proccess_60k.png b/doc/pipeline/server_proccess_60k.png index 39bdaf3..a83bada 100644 Binary files a/doc/pipeline/server_proccess_60k.png and b/doc/pipeline/server_proccess_60k.png differ diff --git a/src/JT808.Gateway.Abstractions/Enums/JT808UseType.cs b/src/JT808.Gateway.Abstractions/Enums/JT808UseType.cs new file mode 100644 index 0000000..ffef406 --- /dev/null +++ b/src/JT808.Gateway.Abstractions/Enums/JT808UseType.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT808.Gateway.Enums +{ + public enum JT808UseType : byte + { + /// + /// 使用正常方式 + /// + Normal = 1, + /// + /// 使用队列方式 + /// + Queue = 2 + } +} diff --git a/src/JT808.Gateway.Abstractions/Extensions/JT808SessionExtensions.cs b/src/JT808.Gateway.Abstractions/Extensions/JT808SessionExtensions.cs new file mode 100644 index 0000000..65eecf0 --- /dev/null +++ b/src/JT808.Gateway.Abstractions/Extensions/JT808SessionExtensions.cs @@ -0,0 +1,23 @@ +using JT808.Gateway.Abstractions.Enums; +using System; +using System.Collections.Generic; +using System.Net.Sockets; +using System.Text; + +namespace JT808.Gateway.Abstractions +{ + public static class JT808SessionExtensions + { + public static async void SendAsync(this IJT808Session session,byte[] data) + { + if (session.TransportProtocolType == JT808TransportProtocolType.tcp) + { + await session.Client.SendAsync(data, SocketFlags.None); + } + else + { + await session.Client.SendToAsync(data, SocketFlags.None, session.RemoteEndPoint); + } + } + } +} diff --git a/src/JT808.Gateway.Abstractions/IJT808MsgConsumerFactory.cs b/src/JT808.Gateway.Abstractions/IJT808MsgConsumerFactory.cs deleted file mode 100644 index 6acea41..0000000 --- a/src/JT808.Gateway.Abstractions/IJT808MsgConsumerFactory.cs +++ /dev/null @@ -1,12 +0,0 @@ -using JT808.Gateway.Abstractions.Enums; -using System; -using System.Collections.Generic; -using System.Text; - -namespace JT808.Gateway.Abstractions -{ - public interface IJT808MsgConsumerFactory - { - IJT808MsgConsumer Create(JT808ConsumerType consumerType); - } -} diff --git a/src/JT808.Gateway.Abstractions/IJT808MsgReplyConsumerFactory.cs b/src/JT808.Gateway.Abstractions/IJT808MsgReplyConsumerFactory.cs deleted file mode 100644 index 23b63ad..0000000 --- a/src/JT808.Gateway.Abstractions/IJT808MsgReplyConsumerFactory.cs +++ /dev/null @@ -1,13 +0,0 @@ -using JT808.Gateway.Abstractions.Enums; -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading; - -namespace JT808.Gateway.Abstractions -{ - public interface IJT808MsgReplyConsumerFactory - { - IJT808MsgReplyConsumer Create(JT808ConsumerType consumerType); - } -} diff --git a/src/JT808.Gateway.Abstractions/IJT808NormalGatewayBuilder.cs b/src/JT808.Gateway.Abstractions/IJT808NormalGatewayBuilder.cs new file mode 100644 index 0000000..3608e8b --- /dev/null +++ b/src/JT808.Gateway.Abstractions/IJT808NormalGatewayBuilder.cs @@ -0,0 +1,13 @@ +using JT808.Protocol; +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT808.Gateway.Abstractions +{ + public interface IJT808NormalGatewayBuilder: IJT808GatewayBuilder + { + + } +} diff --git a/src/JT808.Gateway.Abstractions/IJT808QueueGatewayBuilder.cs b/src/JT808.Gateway.Abstractions/IJT808QueueGatewayBuilder.cs new file mode 100644 index 0000000..1fb8a93 --- /dev/null +++ b/src/JT808.Gateway.Abstractions/IJT808QueueGatewayBuilder.cs @@ -0,0 +1,13 @@ +using JT808.Protocol; +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT808.Gateway.Abstractions +{ + public interface IJT808QueueGatewayBuilder: IJT808GatewayBuilder + { + + } +} diff --git a/src/JT808.Gateway/Interfaces/IJT808Session.cs b/src/JT808.Gateway.Abstractions/IJT808Session.cs similarity index 94% rename from src/JT808.Gateway/Interfaces/IJT808Session.cs rename to src/JT808.Gateway.Abstractions/IJT808Session.cs index 14e1b0d..d4024f9 100644 --- a/src/JT808.Gateway/Interfaces/IJT808Session.cs +++ b/src/JT808.Gateway.Abstractions/IJT808Session.cs @@ -6,7 +6,7 @@ using System.Net.Sockets; using System.Text; using System.Threading; -namespace JT808.Gateway.Interfaces +namespace JT808.Gateway.Abstractions { public interface IJT808Session { diff --git a/src/JT808.Gateway.Abstractions/JT808.Gateway.Abstractions.csproj b/src/JT808.Gateway.Abstractions/JT808.Gateway.Abstractions.csproj index dfbef5f..8e7f17d 100644 --- a/src/JT808.Gateway.Abstractions/JT808.Gateway.Abstractions.csproj +++ b/src/JT808.Gateway.Abstractions/JT808.Gateway.Abstractions.csproj @@ -29,7 +29,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/src/JT808.Gateway.Abstractions/JT808NormalReplyMessageHandler.cs b/src/JT808.Gateway.Abstractions/JT808NormalReplyMessageHandler.cs new file mode 100644 index 0000000..ff39cdb --- /dev/null +++ b/src/JT808.Gateway.Abstractions/JT808NormalReplyMessageHandler.cs @@ -0,0 +1,179 @@ +using JT808.Protocol; +using JT808.Protocol.Enums; +using JT808.Protocol.Extensions; +using JT808.Protocol.MessageBody; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT808.Gateway.Abstractions +{ + public class JT808NormalReplyMessageHandler + { + protected Dictionary HandlerDict { get; } + + protected delegate byte[] MsgIdMethodDelegate(JT808HeaderPackage package, IJT808Session session); + protected JT808Serializer JT808Serializer { get; } + public JT808NormalReplyMessageHandler( + IJT808Config jT808Config) + { + this.JT808Serializer = jT808Config.GetSerializer(); + HandlerDict = new Dictionary { + {JT808MsgId.终端通用应答.ToUInt16Value(), Msg0x0001}, + {JT808MsgId.终端鉴权.ToUInt16Value(), Msg0x0102}, + {JT808MsgId.终端心跳.ToUInt16Value(), Msg0x0002}, + {JT808MsgId.终端注销.ToUInt16Value(), Msg0x0003}, + {JT808MsgId.终端注册.ToUInt16Value(), Msg0x0100}, + {JT808MsgId.位置信息汇报.ToUInt16Value(),Msg0x0200 }, + {JT808MsgId.定位数据批量上传.ToUInt16Value(),Msg0x0704 }, + {JT808MsgId.数据上行透传.ToUInt16Value(),Msg0x0900 } + }; + } + + /// + /// + /// + /// 请求数据 + /// 当前会话 + /// 应答消息数据 + public virtual byte[] Processor(JT808HeaderPackage request, IJT808Session session) + { + if (HandlerDict.TryGetValue(request.Header.MsgId, out var func)) + { + return func(request, session); + } + else + { + //处理不了的消息统一回复通用应答 + return CommonReply(request, session); + } + } + + /// + /// 平台通用应答 + /// + /// + /// + public virtual byte[] CommonReply(JT808HeaderPackage request, IJT808Session session) + { + if (request.Version == JT808Version.JTT2019) + { + byte[] data = JT808Serializer.Serialize(JT808MsgId.平台通用应答.Create_平台通用应答_2019(request.Header.TerminalPhoneNo, new JT808_0x8001() + { + AckMsgId = request.Header.MsgId, + JT808PlatformResult = JT808PlatformResult.成功, + MsgNum = request.Header.MsgNum + })); + session.SendAsync(data); + return data; + } + else + { + byte[] data = JT808Serializer.Serialize(JT808MsgId.平台通用应答.Create(request.Header.TerminalPhoneNo, new JT808_0x8001() + { + AckMsgId = request.Header.MsgId, + JT808PlatformResult = JT808PlatformResult.成功, + MsgNum = request.Header.MsgNum + })); + session.SendAsync(data); + return data; + } + } + + /// + /// 终端通用应答 + /// 平台无需回复 + /// 实现自己的业务 + /// + /// + /// + public virtual byte[] Msg0x0001(JT808HeaderPackage request, IJT808Session session) + { + return default; + } + /// + /// 终端心跳 + /// + /// + /// + public virtual byte[] Msg0x0002(JT808HeaderPackage request, IJT808Session session) + { + return CommonReply(request, session); + } + /// + /// 终端注销 + /// + /// + /// + public virtual byte[] Msg0x0003(JT808HeaderPackage request, IJT808Session session) + { + return CommonReply(request, session); + } + /// + /// 终端注册 + /// + /// + /// + public virtual byte[] Msg0x0100(JT808HeaderPackage request, IJT808Session session) + { + if (request.Version == JT808Version.JTT2019) + { + byte[] data = JT808Serializer.Serialize(JT808MsgId.终端注册应答.Create_终端注册应答_2019(request.Header.TerminalPhoneNo, new JT808_0x8100() + { + Code = "J" + request.Header.TerminalPhoneNo, + JT808TerminalRegisterResult = JT808TerminalRegisterResult.成功, + AckMsgNum = request.Header.MsgNum + })); + session.SendAsync(data); + return data; + } + else + { + byte[] data = JT808Serializer.Serialize(JT808MsgId.终端注册应答.Create(request.Header.TerminalPhoneNo, new JT808_0x8100() + { + Code = "J" + request.Header.TerminalPhoneNo, + JT808TerminalRegisterResult = JT808TerminalRegisterResult.成功, + AckMsgNum = request.Header.MsgNum + })); + session.SendAsync(data); + return data; + } + } + /// + /// 终端鉴权 + /// + /// + /// + public virtual byte[] Msg0x0102(JT808HeaderPackage request, IJT808Session session) + { + return CommonReply(request, session); + } + /// + /// 位置信息汇报 + /// + /// + /// + public virtual byte[] Msg0x0200(JT808HeaderPackage request, IJT808Session session) + { + return CommonReply(request, session); + } + /// + /// 定位数据批量上传 + /// + /// + /// + public virtual byte[] Msg0x0704(JT808HeaderPackage request, IJT808Session session) + { + return CommonReply(request, session); + } + /// + /// 数据上行透传 + /// + /// + /// + public virtual byte[] Msg0x0900(JT808HeaderPackage request, IJT808Session session) + { + return CommonReply(request, session); + } + } +} diff --git a/src/JT808.Gateway.Abstractions/JT808ReplyMessageHandler.cs b/src/JT808.Gateway.Abstractions/JT808QueueReplyMessageHandler.cs similarity index 52% rename from src/JT808.Gateway.Abstractions/JT808ReplyMessageHandler.cs rename to src/JT808.Gateway.Abstractions/JT808QueueReplyMessageHandler.cs index 2e96fda..5350773 100644 --- a/src/JT808.Gateway.Abstractions/JT808ReplyMessageHandler.cs +++ b/src/JT808.Gateway.Abstractions/JT808QueueReplyMessageHandler.cs @@ -8,14 +8,14 @@ using System.Text; namespace JT808.Gateway.Abstractions { - public class JT808ReplyMessageHandler + public class JT808QueueReplyMessageHandler { protected Dictionary HandlerDict { get; } protected delegate byte[] MsgIdMethodDelegate(JT808HeaderPackage package); protected JT808Serializer JT808Serializer { get; } protected IJT808MsgReplyProducer JT808MsgReplyProducer { get; } - public JT808ReplyMessageHandler( + public JT808QueueReplyMessageHandler( IJT808Config jT808Config, IJT808MsgReplyProducer jT808MsgReplyProducer) { @@ -35,40 +35,23 @@ namespace JT808.Gateway.Abstractions public virtual void Processor((string TerminalNo, byte[] Data) parameter) { - try + var request = JT808Serializer.HeaderDeserialize(parameter.Data); + if (HandlerDict.TryGetValue(request.Header.MsgId, out var func)) { - var request = JT808Serializer.HeaderDeserialize(parameter.Data); - if (HandlerDict.TryGetValue(request.Header.MsgId, out var func)) + var buffer = func(request); + if (buffer != null) { - var buffer = func(request); - if (buffer != null) - { - JT808MsgReplyProducer.ProduceAsync(parameter.TerminalNo, buffer); - } + JT808MsgReplyProducer.ProduceAsync(parameter.TerminalNo, buffer); } } - catch - { - } } /// - /// 终端通用应答 - /// 平台无需回复 - /// 实现自己的业务 - /// - /// - /// - public virtual byte[] Msg0x0001(JT808HeaderPackage request) - { - return null; - } - /// - /// 终端心跳 + /// 平台通用应答 /// /// - /// - public virtual byte[] Msg0x0002(JT808HeaderPackage request) + /// + public virtual byte[] CommonReply(JT808HeaderPackage request) { if (request.Version == JT808Version.JTT2019) { @@ -89,6 +72,27 @@ namespace JT808.Gateway.Abstractions })); } } + + /// + /// 终端通用应答 + /// 平台无需回复 + /// 实现自己的业务 + /// + /// + /// + public virtual byte[] Msg0x0001(JT808HeaderPackage request) + { + return null; + } + /// + /// 终端心跳 + /// + /// + /// + public virtual byte[] Msg0x0002(JT808HeaderPackage request) + { + return CommonReply(request); + } /// /// 终端注销 /// @@ -96,24 +100,7 @@ namespace JT808.Gateway.Abstractions /// public virtual byte[] Msg0x0003(JT808HeaderPackage request) { - if (request.Version == JT808Version.JTT2019) - { - return JT808Serializer.Serialize(JT808MsgId.平台通用应答.Create_平台通用应答_2019(request.Header.TerminalPhoneNo, new JT808_0x8001() - { - AckMsgId = request.Header.MsgId, - JT808PlatformResult = JT808PlatformResult.成功, - MsgNum = request.Header.MsgNum - })); - } - else - { - return JT808Serializer.Serialize(JT808MsgId.平台通用应答.Create(request.Header.TerminalPhoneNo, new JT808_0x8001() - { - AckMsgId = request.Header.MsgId, - JT808PlatformResult = JT808PlatformResult.成功, - MsgNum = request.Header.MsgNum - })); - } + return CommonReply(request); } /// /// 终端注册 @@ -148,24 +135,7 @@ namespace JT808.Gateway.Abstractions /// public virtual byte[] Msg0x0102(JT808HeaderPackage request) { - if (request.Version == JT808Version.JTT2019) - { - return JT808Serializer.Serialize(JT808MsgId.平台通用应答.Create_平台通用应答_2019(request.Header.TerminalPhoneNo, new JT808_0x8001() - { - AckMsgId = request.Header.MsgId, - JT808PlatformResult = JT808PlatformResult.成功, - MsgNum = request.Header.MsgNum - })); - } - else - { - return JT808Serializer.Serialize(JT808MsgId.平台通用应答.Create(request.Header.TerminalPhoneNo, new JT808_0x8001() - { - AckMsgId = request.Header.MsgId, - JT808PlatformResult = JT808PlatformResult.成功, - MsgNum = request.Header.MsgNum - })); - } + return CommonReply(request); } /// /// 位置信息汇报 @@ -174,24 +144,7 @@ namespace JT808.Gateway.Abstractions /// public virtual byte[] Msg0x0200(JT808HeaderPackage request) { - if (request.Version == JT808Version.JTT2019) - { - return JT808Serializer.Serialize(JT808MsgId.平台通用应答.Create_平台通用应答_2019(request.Header.TerminalPhoneNo, new JT808_0x8001() - { - AckMsgId = request.Header.MsgId, - JT808PlatformResult = JT808PlatformResult.成功, - MsgNum = request.Header.MsgNum - })); - } - else - { - return JT808Serializer.Serialize(JT808MsgId.平台通用应答.Create(request.Header.TerminalPhoneNo, new JT808_0x8001() - { - AckMsgId = request.Header.MsgId, - JT808PlatformResult = JT808PlatformResult.成功, - MsgNum = request.Header.MsgNum - })); - } + return CommonReply(request); } /// /// 定位数据批量上传 @@ -200,24 +153,7 @@ namespace JT808.Gateway.Abstractions /// public virtual byte[] Msg0x0704(JT808HeaderPackage request) { - if (request.Version == JT808Version.JTT2019) - { - return JT808Serializer.Serialize(JT808MsgId.平台通用应答.Create_平台通用应答_2019(request.Header.TerminalPhoneNo, new JT808_0x8001() - { - AckMsgId = request.Header.MsgId, - JT808PlatformResult = JT808PlatformResult.成功, - MsgNum = request.Header.MsgNum - })); - } - else - { - return JT808Serializer.Serialize(JT808MsgId.平台通用应答.Create(request.Header.TerminalPhoneNo, new JT808_0x8001() - { - AckMsgId = request.Header.MsgId, - JT808PlatformResult = JT808PlatformResult.成功, - MsgNum = request.Header.MsgNum - })); - } + return CommonReply(request); } /// /// 数据上行透传 @@ -226,24 +162,7 @@ namespace JT808.Gateway.Abstractions /// public virtual byte[] Msg0x0900(JT808HeaderPackage request) { - if (request.Version == JT808Version.JTT2019) - { - return JT808Serializer.Serialize(JT808MsgId.平台通用应答.Create_平台通用应答_2019(request.Header.TerminalPhoneNo, new JT808_0x8001() - { - AckMsgId = request.Header.MsgId, - JT808PlatformResult = JT808PlatformResult.成功, - MsgNum = request.Header.MsgNum - })); - } - else - { - return JT808Serializer.Serialize(JT808MsgId.平台通用应答.Create(request.Header.TerminalPhoneNo, new JT808_0x8001() - { - AckMsgId = request.Header.MsgId, - JT808PlatformResult = JT808PlatformResult.成功, - MsgNum = request.Header.MsgNum - })); - } + return CommonReply(request); } } } diff --git a/src/JT808.Gateway.CleintBenchmark/Configs/ClientBenchmarkOptions.cs b/src/JT808.Gateway.Benchmark/JT808.Gateway.CleintBenchmark/Configs/ClientBenchmarkOptions.cs similarity index 100% rename from src/JT808.Gateway.CleintBenchmark/Configs/ClientBenchmarkOptions.cs rename to src/JT808.Gateway.Benchmark/JT808.Gateway.CleintBenchmark/Configs/ClientBenchmarkOptions.cs diff --git a/src/JT808.Gateway.CleintBenchmark/Configs/NLog.xsd b/src/JT808.Gateway.Benchmark/JT808.Gateway.CleintBenchmark/Configs/NLog.xsd similarity index 100% rename from src/JT808.Gateway.CleintBenchmark/Configs/NLog.xsd rename to src/JT808.Gateway.Benchmark/JT808.Gateway.CleintBenchmark/Configs/NLog.xsd diff --git a/src/JT808.Gateway.CleintBenchmark/Configs/nlog.unix.config b/src/JT808.Gateway.Benchmark/JT808.Gateway.CleintBenchmark/Configs/nlog.unix.config similarity index 100% rename from src/JT808.Gateway.CleintBenchmark/Configs/nlog.unix.config rename to src/JT808.Gateway.Benchmark/JT808.Gateway.CleintBenchmark/Configs/nlog.unix.config diff --git a/src/JT808.Gateway.CleintBenchmark/Configs/nlog.win.config b/src/JT808.Gateway.Benchmark/JT808.Gateway.CleintBenchmark/Configs/nlog.win.config similarity index 100% rename from src/JT808.Gateway.CleintBenchmark/Configs/nlog.win.config rename to src/JT808.Gateway.Benchmark/JT808.Gateway.CleintBenchmark/Configs/nlog.win.config diff --git a/src/JT808.Gateway.CleintBenchmark/Controllers/ReportController.cs b/src/JT808.Gateway.Benchmark/JT808.Gateway.CleintBenchmark/Controllers/ReportController.cs similarity index 100% rename from src/JT808.Gateway.CleintBenchmark/Controllers/ReportController.cs rename to src/JT808.Gateway.Benchmark/JT808.Gateway.CleintBenchmark/Controllers/ReportController.cs diff --git a/src/JT808.Gateway.CleintBenchmark/JT808.Gateway.CleintBenchmark.csproj b/src/JT808.Gateway.Benchmark/JT808.Gateway.CleintBenchmark/JT808.Gateway.CleintBenchmark.csproj similarity index 95% rename from src/JT808.Gateway.CleintBenchmark/JT808.Gateway.CleintBenchmark.csproj rename to src/JT808.Gateway.Benchmark/JT808.Gateway.CleintBenchmark/JT808.Gateway.CleintBenchmark.csproj index 3045711..cf24270 100644 --- a/src/JT808.Gateway.CleintBenchmark/JT808.Gateway.CleintBenchmark.csproj +++ b/src/JT808.Gateway.Benchmark/JT808.Gateway.CleintBenchmark/JT808.Gateway.CleintBenchmark.csproj @@ -20,7 +20,7 @@ - + diff --git a/src/JT808.Gateway.CleintBenchmark/Program.cs b/src/JT808.Gateway.Benchmark/JT808.Gateway.CleintBenchmark/Program.cs similarity index 100% rename from src/JT808.Gateway.CleintBenchmark/Program.cs rename to src/JT808.Gateway.Benchmark/JT808.Gateway.CleintBenchmark/Program.cs diff --git a/src/JT808.Gateway.CleintBenchmark/Services/CleintBenchmarkHostedService.cs b/src/JT808.Gateway.Benchmark/JT808.Gateway.CleintBenchmark/Services/CleintBenchmarkHostedService.cs similarity index 100% rename from src/JT808.Gateway.CleintBenchmark/Services/CleintBenchmarkHostedService.cs rename to src/JT808.Gateway.Benchmark/JT808.Gateway.CleintBenchmark/Services/CleintBenchmarkHostedService.cs diff --git a/src/JT808.Gateway.CleintBenchmark/wwwroot/echarts.min.js b/src/JT808.Gateway.Benchmark/JT808.Gateway.CleintBenchmark/wwwroot/echarts.min.js similarity index 100% rename from src/JT808.Gateway.CleintBenchmark/wwwroot/echarts.min.js rename to src/JT808.Gateway.Benchmark/JT808.Gateway.CleintBenchmark/wwwroot/echarts.min.js diff --git a/src/JT808.Gateway.CleintBenchmark/wwwroot/index.html b/src/JT808.Gateway.Benchmark/JT808.Gateway.CleintBenchmark/wwwroot/index.html similarity index 100% rename from src/JT808.Gateway.CleintBenchmark/wwwroot/index.html rename to src/JT808.Gateway.Benchmark/JT808.Gateway.CleintBenchmark/wwwroot/index.html diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/Configs/NLog.xsd b/src/JT808.Gateway.Benchmark/JT808.Gateway.ServerBenchmark/Configs/NLog.xsd similarity index 100% rename from src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/Configs/NLog.xsd rename to src/JT808.Gateway.Benchmark/JT808.Gateway.ServerBenchmark/Configs/NLog.xsd diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/Configs/nlog.Unix.config b/src/JT808.Gateway.Benchmark/JT808.Gateway.ServerBenchmark/Configs/nlog.Unix.config similarity index 100% rename from src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/Configs/nlog.Unix.config rename to src/JT808.Gateway.Benchmark/JT808.Gateway.ServerBenchmark/Configs/nlog.Unix.config diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/Configs/nlog.Win32NT.config b/src/JT808.Gateway.Benchmark/JT808.Gateway.ServerBenchmark/Configs/nlog.Win32NT.config similarity index 100% rename from src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/Configs/nlog.Win32NT.config rename to src/JT808.Gateway.Benchmark/JT808.Gateway.ServerBenchmark/Configs/nlog.Win32NT.config diff --git a/src/JT808.Gateway.Benchmark/JT808.Gateway.ServerBenchmark/JT808.Gateway.ServerBenchmark.csproj b/src/JT808.Gateway.Benchmark/JT808.Gateway.ServerBenchmark/JT808.Gateway.ServerBenchmark.csproj new file mode 100644 index 0000000..69c4512 --- /dev/null +++ b/src/JT808.Gateway.Benchmark/JT808.Gateway.ServerBenchmark/JT808.Gateway.ServerBenchmark.csproj @@ -0,0 +1,35 @@ + + + + Exe + netcoreapp3.1 + + + + + + + + + + + + + + + + + Always + + + Always + + + Always + + + Always + + + + diff --git a/src/JT808.Gateway.Benchmark/JT808.Gateway.ServerBenchmark/Program.cs b/src/JT808.Gateway.Benchmark/JT808.Gateway.ServerBenchmark/Program.cs new file mode 100644 index 0000000..fb0a1d2 --- /dev/null +++ b/src/JT808.Gateway.Benchmark/JT808.Gateway.ServerBenchmark/Program.cs @@ -0,0 +1,43 @@ +using System; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using JT808.Protocol; +using Microsoft.Extensions.Configuration; +using NLog.Extensions.Logging; + +namespace JT808.Gateway.ServerBenchmark +{ + class Program + { + static async Task Main(string[] args) + { + var serverHostBuilder = new HostBuilder() + .ConfigureAppConfiguration((hostingContext, config) => + { + config.SetBasePath(AppDomain.CurrentDomain.BaseDirectory) + .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) + .AddJsonFile($"appsettings.{ hostingContext.HostingEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true); + }) + .ConfigureLogging((context, logging) => + { + Console.WriteLine($"Environment.OSVersion.Platform:{Environment.OSVersion.Platform.ToString()}"); + NLog.LogManager.LoadConfiguration($"Configs/nlog.{Environment.OSVersion.Platform.ToString()}.config"); + logging.AddNLog(new NLogProviderOptions { CaptureMessageTemplates = true, CaptureMessageProperties = true }); + logging.SetMinimumLevel(LogLevel.Trace); + }) + .ConfigureServices((hostContext, services) => + { + services.AddSingleton(); + services.AddSingleton(typeof(ILogger<>), typeof(Logger<>)); + services.AddJT808Configure() + .AddNormalGateway(hostContext.Configuration) + .AddTcp() + .AddUdp(); + }); + + await serverHostBuilder.RunConsoleAsync(); + } + } +} diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/startup.txt b/src/JT808.Gateway.Benchmark/JT808.Gateway.ServerBenchmark/startup.txt similarity index 55% rename from src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/startup.txt rename to src/JT808.Gateway.Benchmark/JT808.Gateway.ServerBenchmark/startup.txt index 5cc05f2..4d1b8c1 100644 --- a/src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/startup.txt +++ b/src/JT808.Gateway.Benchmark/JT808.Gateway.ServerBenchmark/startup.txt @@ -1,4 +1,4 @@ pm2 start "dotnet JT808.Gateway.CleintBenchmark.dll ASPNETCORE_ENVIRONMENT=Production" --max-restarts=1 -n "JT808.Gateway.CleintBenchmark" -o "/data/pm2Logs/JT808.Gateway.CleintBenchmark/out.log" -e "/data/pm2Logs/JT808.Gateway.CleintBenchmark/error.log" -pm2 start "dotnet JT808.Gateway.TestHosting.dll ASPNETCORE_ENVIRONMENT=Production" --max-restarts=1 -n "JT808.Gateway.808" -o "/data/pm2Logs/JT808.Gateway/out.log" -e "/data/pm2Logs/JT808.Gateway/error.log" \ No newline at end of file +pm2 start "dotnet JT808.Gateway.ServerBenchmark.dll ASPNETCORE_ENVIRONMENT=Production" --max-restarts=1 -n "JT808.Gateway.808" -o "/data/pm2Logs/JT808.Gateway/out.log" -e "/data/pm2Logs/JT808.Gateway/error.log" \ No newline at end of file diff --git a/src/JT808.Gateway.InMemoryMQ/Consumers/JT808MsgIdHandlerConsumer.cs b/src/JT808.Gateway.InMemoryMQ/Consumers/JT808MsgIdHandlerConsumer.cs deleted file mode 100644 index 791d61c..0000000 --- a/src/JT808.Gateway.InMemoryMQ/Consumers/JT808MsgIdHandlerConsumer.cs +++ /dev/null @@ -1,60 +0,0 @@ -using JT808.Gateway.Abstractions; -using JT808.Gateway.InMemoryMQ.Services; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace JT808.Gateway.InMemoryMQ -{ - public class JT808MsgIdHandlerConsumer : IJT808MsgConsumer - { - private readonly JT808MsgIdHandlerService JT808MsgService; - public CancellationTokenSource Cts => new CancellationTokenSource(); - private readonly ILogger logger; - public string TopicName => JT808GatewayConstants.MsgTopic; - public JT808MsgIdHandlerConsumer( - JT808MsgIdHandlerService jT808MsgService, - ILoggerFactory loggerFactory) - { - JT808MsgService = jT808MsgService; - logger = loggerFactory.CreateLogger("JT808MsgIdHandlerConsumer"); - } - - public void OnMessage(Action<(string TerminalNo, byte[] Data)> callback) - { - Task.Run(async() => - { - while (!Cts.IsCancellationRequested) - { - try - { - var item = await JT808MsgService.ReadAsync(Cts.Token); - callback(item); - } - catch(Exception ex) - { - logger.LogError(ex, ""); - } - } - }, Cts.Token); - } - - public void Subscribe() - { - - } - - public void Unsubscribe() - { - Cts.Cancel(); - } - - public void Dispose() - { - Cts.Dispose(); - } - } -} diff --git a/src/JT808.Gateway.InMemoryMQ/Consumers/JT808MsgLoggingConsumer.cs b/src/JT808.Gateway.InMemoryMQ/Consumers/JT808MsgLoggingConsumer.cs deleted file mode 100644 index f2949bc..0000000 --- a/src/JT808.Gateway.InMemoryMQ/Consumers/JT808MsgLoggingConsumer.cs +++ /dev/null @@ -1,60 +0,0 @@ -using JT808.Gateway.Abstractions; -using JT808.Gateway.InMemoryMQ.Services; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace JT808.Gateway.InMemoryMQ -{ - public class JT808MsgLoggingConsumer : IJT808MsgConsumer - { - private readonly JT808MsgLoggingService JT808MsgService; - public CancellationTokenSource Cts => new CancellationTokenSource(); - private readonly ILogger logger; - public string TopicName => JT808GatewayConstants.MsgTopic; - public JT808MsgLoggingConsumer( - JT808MsgLoggingService jT808MsgService, - ILoggerFactory loggerFactory) - { - JT808MsgService = jT808MsgService; - logger = loggerFactory.CreateLogger("JT808MsgLoggingConsumer"); - } - - public void OnMessage(Action<(string TerminalNo, byte[] Data)> callback) - { - Task.Run(async() => - { - while (!Cts.IsCancellationRequested) - { - try - { - var item = await JT808MsgService.ReadAsync(Cts.Token); - callback(item); - } - catch(Exception ex) - { - logger.LogError(ex, ""); - } - } - }, Cts.Token); - } - - public void Subscribe() - { - - } - - public void Unsubscribe() - { - Cts.Cancel(); - } - - public void Dispose() - { - Cts.Dispose(); - } - } -} diff --git a/src/JT808.Gateway.InMemoryMQ/Consumers/JT808MsgReplyMessageConsumer.cs b/src/JT808.Gateway.InMemoryMQ/Consumers/JT808MsgReplyMessageConsumer.cs deleted file mode 100644 index 009404c..0000000 --- a/src/JT808.Gateway.InMemoryMQ/Consumers/JT808MsgReplyMessageConsumer.cs +++ /dev/null @@ -1,60 +0,0 @@ -using JT808.Gateway.Abstractions; -using JT808.Gateway.InMemoryMQ.Services; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace JT808.Gateway.InMemoryMQ -{ - public class JT808MsgReplyMessageConsumer : IJT808MsgConsumer - { - private readonly JT808MsgReplyMessageService JT808MsgService; - public CancellationTokenSource Cts => new CancellationTokenSource(); - private readonly ILogger logger; - public string TopicName => JT808GatewayConstants.MsgTopic; - public JT808MsgReplyMessageConsumer( - JT808MsgReplyMessageService jT808MsgService, - ILoggerFactory loggerFactory) - { - JT808MsgService = jT808MsgService; - logger = loggerFactory.CreateLogger("JT808MsgReplyMessageConsumer"); - } - - public void OnMessage(Action<(string TerminalNo, byte[] Data)> callback) - { - Task.Run(async() => - { - while (!Cts.IsCancellationRequested) - { - try - { - var item = await JT808MsgService.ReadAsync(Cts.Token); - callback(item); - } - catch(Exception ex) - { - logger.LogError(ex, ""); - } - } - }, Cts.Token); - } - - public void Subscribe() - { - - } - - public void Unsubscribe() - { - Cts.Cancel(); - } - - public void Dispose() - { - Cts.Dispose(); - } - } -} diff --git a/src/JT808.Gateway.InMemoryMQ/Consumers/JT808MsgReplyMessageLoggingConsumer.cs b/src/JT808.Gateway.InMemoryMQ/Consumers/JT808MsgReplyMessageLoggingConsumer.cs deleted file mode 100644 index 2c5dc5b..0000000 --- a/src/JT808.Gateway.InMemoryMQ/Consumers/JT808MsgReplyMessageLoggingConsumer.cs +++ /dev/null @@ -1,60 +0,0 @@ -using JT808.Gateway.Abstractions; -using JT808.Gateway.InMemoryMQ.Services; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace JT808.Gateway.InMemoryMQ -{ - public class JT808MsgReplyMessageLoggingConsumer : IJT808MsgReplyConsumer - { - private readonly JT808MsgReplyMessageLoggingService JT808MsgService; - public CancellationTokenSource Cts => new CancellationTokenSource(); - private readonly ILogger logger; - public string TopicName => JT808GatewayConstants.MsgTopic; - public JT808MsgReplyMessageLoggingConsumer( - JT808MsgReplyMessageLoggingService jT808MsgService, - ILoggerFactory loggerFactory) - { - JT808MsgService = jT808MsgService; - logger = loggerFactory.CreateLogger("JT808MsgReplyMessageLoggingConsumer"); - } - - public void OnMessage(Action<(string TerminalNo, byte[] Data)> callback) - { - Task.Run(async() => - { - while (!Cts.IsCancellationRequested) - { - try - { - var item = await JT808MsgService.ReadAsync(Cts.Token); - callback(item); - } - catch(Exception ex) - { - logger.LogError(ex, ""); - } - } - }, Cts.Token); - } - - public void Subscribe() - { - - } - - public void Unsubscribe() - { - Cts.Cancel(); - } - - public void Dispose() - { - Cts.Dispose(); - } - } -} diff --git a/src/JT808.Gateway.InMemoryMQ/Consumers/JT808MsgTrafficConsumer.cs b/src/JT808.Gateway.InMemoryMQ/Consumers/JT808MsgTrafficConsumer.cs deleted file mode 100644 index ed7c8a5..0000000 --- a/src/JT808.Gateway.InMemoryMQ/Consumers/JT808MsgTrafficConsumer.cs +++ /dev/null @@ -1,60 +0,0 @@ -using JT808.Gateway.Abstractions; -using JT808.Gateway.InMemoryMQ.Services; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace JT808.Gateway.InMemoryMQ -{ - public class JT808MsgTrafficConsumer : IJT808MsgConsumer - { - private readonly JT808MsgTrafficService JT808MsgService; - public CancellationTokenSource Cts => new CancellationTokenSource(); - private readonly ILogger logger; - public string TopicName => JT808GatewayConstants.MsgTopic; - public JT808MsgTrafficConsumer( - JT808MsgTrafficService jT808MsgService, - ILoggerFactory loggerFactory) - { - JT808MsgService = jT808MsgService; - logger = loggerFactory.CreateLogger("JT808MsgTrafficConsumer"); - } - - public void OnMessage(Action<(string TerminalNo, byte[] Data)> callback) - { - Task.Run(async() => - { - while (!Cts.IsCancellationRequested) - { - try - { - var item = await JT808MsgService.ReadAsync(Cts.Token); - callback(item); - } - catch(Exception ex) - { - logger.LogError(ex, ""); - } - } - }, Cts.Token); - } - - public void Subscribe() - { - - } - - public void Unsubscribe() - { - Cts.Cancel(); - } - - public void Dispose() - { - Cts.Dispose(); - } - } -} diff --git a/src/JT808.Gateway.InMemoryMQ/Consumers/JT808MsgTransmitConsumer.cs b/src/JT808.Gateway.InMemoryMQ/Consumers/JT808MsgTransmitConsumer.cs deleted file mode 100644 index 0bce3ab..0000000 --- a/src/JT808.Gateway.InMemoryMQ/Consumers/JT808MsgTransmitConsumer.cs +++ /dev/null @@ -1,60 +0,0 @@ -using JT808.Gateway.Abstractions; -using JT808.Gateway.InMemoryMQ.Services; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace JT808.Gateway.InMemoryMQ -{ - public class JT808MsgTransmitConsumer : IJT808MsgConsumer - { - private readonly JT808MsgTransmitService JT808MsgService; - public CancellationTokenSource Cts => new CancellationTokenSource(); - private readonly ILogger logger; - public string TopicName => JT808GatewayConstants.MsgTopic; - public JT808MsgTransmitConsumer( - JT808MsgTransmitService jT808MsgService, - ILoggerFactory loggerFactory) - { - JT808MsgService = jT808MsgService; - logger = loggerFactory.CreateLogger("JT808MsgTransmitConsumer"); - } - - public void OnMessage(Action<(string TerminalNo, byte[] Data)> callback) - { - Task.Run(async() => - { - while (!Cts.IsCancellationRequested) - { - try - { - var item = await JT808MsgService.ReadAsync(Cts.Token); - callback(item); - } - catch(Exception ex) - { - logger.LogError(ex, ""); - } - } - }, Cts.Token); - } - - public void Subscribe() - { - - } - - public void Unsubscribe() - { - Cts.Cancel(); - } - - public void Dispose() - { - Cts.Dispose(); - } - } -} diff --git a/src/JT808.Gateway.InMemoryMQ/JT808.Gateway.InMemoryMQ.csproj b/src/JT808.Gateway.InMemoryMQ/JT808.Gateway.InMemoryMQ.csproj deleted file mode 100644 index b9bbf12..0000000 --- a/src/JT808.Gateway.InMemoryMQ/JT808.Gateway.InMemoryMQ.csproj +++ /dev/null @@ -1,34 +0,0 @@ - - - - - netstandard2.1 - 8.0 - Copyright 2019. - SmallChi(Koike) - https://github.com/SmallChi/JT808Gateway - https://github.com/SmallChi/JT808Gateway - https://github.com/SmallChi/JT808Gateway/blob/master/LICENSE - https://github.com/SmallChi/JT808Gateway/blob/master/LICENSE - false - false - LICENSE - true - JT808.Gateway.InMemoryMQ - JT808.Gateway.InMemoryMQ - 基于InMemory的JT808消息发布与订阅 - 基于InMemory的JT808消息发布与订阅 - $(JT808GatewayPackageVersion) - - - - - - - - - - - - - diff --git a/src/JT808.Gateway.InMemoryMQ/JT808MsgConsumer.cs b/src/JT808.Gateway.InMemoryMQ/JT808MsgConsumer.cs deleted file mode 100644 index 516b65d..0000000 --- a/src/JT808.Gateway.InMemoryMQ/JT808MsgConsumer.cs +++ /dev/null @@ -1,72 +0,0 @@ -using JT808.Gateway.Abstractions; -using JT808.Gateway.Abstractions.Enums; -using JT808.Gateway.InMemoryMQ.Services; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace JT808.Gateway.InMemoryMQ -{ - public class JT808MsgConsumer : IJT808MsgConsumer - { - private readonly JT808MsgService JT808MsgService; - private readonly Func func; - public CancellationTokenSource Cts => new CancellationTokenSource(); - private readonly ILogger logger; - public string TopicName => JT808GatewayConstants.MsgTopic; - public JT808MsgConsumer( - Func func, - JT808MsgService jT808MsgService, - ILoggerFactory loggerFactory) - { - JT808MsgService = jT808MsgService; - this.func = func; - logger = loggerFactory.CreateLogger("JT808MsgConsumer"); - } - - public void OnMessage(Action<(string TerminalNo, byte[] Data)> callback) - { - Task.Run(async() => - { - while (!Cts.IsCancellationRequested) - { - try - { - var item = await JT808MsgService.ReadAsync(Cts.Token); - foreach(var type in JT808ServerInMemoryMQExtensions.ConsumerTypes) - { - var method = func(type); - if (method != null) - { - await method.WriteAsync(item.TerminalNo, item.Data); - } - } - //callback(item); - } - catch(Exception ex) - { - logger.LogError(ex, ""); - } - } - }, Cts.Token); - } - - public void Subscribe() - { - - } - - public void Unsubscribe() - { - Cts.Cancel(); - } - - public void Dispose() - { - Cts.Dispose(); - } - } -} diff --git a/src/JT808.Gateway.InMemoryMQ/JT808MsgConsumerFactory.cs b/src/JT808.Gateway.InMemoryMQ/JT808MsgConsumerFactory.cs deleted file mode 100644 index 49af6c1..0000000 --- a/src/JT808.Gateway.InMemoryMQ/JT808MsgConsumerFactory.cs +++ /dev/null @@ -1,23 +0,0 @@ -using JT808.Gateway.Abstractions; -using JT808.Gateway.Abstractions.Enums; -using System; -using System.Collections.Generic; -using System.Text; - -namespace JT808.Gateway.InMemoryMQ -{ - public class JT808MsgConsumerFactory : IJT808MsgConsumerFactory - { - private readonly Func factory; - - public JT808MsgConsumerFactory(Func accesor) - { - factory = accesor; - } - - public IJT808MsgConsumer Create(JT808ConsumerType consumerType) - { - return factory(consumerType); - } - } -} diff --git a/src/JT808.Gateway.InMemoryMQ/JT808MsgConsumerInMemoryHostedService.cs b/src/JT808.Gateway.InMemoryMQ/JT808MsgConsumerInMemoryHostedService.cs deleted file mode 100644 index 82a5091..0000000 --- a/src/JT808.Gateway.InMemoryMQ/JT808MsgConsumerInMemoryHostedService.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Threading.Tasks; -using Microsoft.Extensions.Hosting; -using System.Threading; -using JT808.Gateway.Abstractions; -using JT808.Gateway.Abstractions.Enums; - -namespace JT808.Gateway.InMemoryMQ -{ - public class JT808MsgConsumerInMemoryHostedService : IHostedService - { - private readonly IJT808MsgConsumer jT808MsgConsumer; - - public JT808MsgConsumerInMemoryHostedService( - IJT808MsgConsumer jT808MsgConsumer) - { - this.jT808MsgConsumer = jT808MsgConsumer; - } - - public Task StartAsync(CancellationToken cancellationToken) - { - jT808MsgConsumer.Subscribe(); - jT808MsgConsumer.OnMessage(null); - return Task.CompletedTask; - } - - public Task StopAsync(CancellationToken cancellationToken) - { - jT808MsgConsumer.Unsubscribe(); - return Task.CompletedTask; - } - } -} diff --git a/src/JT808.Gateway.InMemoryMQ/JT808MsgProducer.cs b/src/JT808.Gateway.InMemoryMQ/JT808MsgProducer.cs deleted file mode 100644 index 60efd58..0000000 --- a/src/JT808.Gateway.InMemoryMQ/JT808MsgProducer.cs +++ /dev/null @@ -1,27 +0,0 @@ -using JT808.Gateway.Abstractions; -using JT808.Gateway.InMemoryMQ.Services; -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; - -namespace JT808.Gateway.InMemoryMQ -{ - public class JT808MsgProducer : IJT808MsgProducer - { - private readonly JT808MsgService JT808MsgService; - public string TopicName => JT808GatewayConstants.MsgTopic; - public JT808MsgProducer(JT808MsgService jT808MsgService) - { - JT808MsgService = jT808MsgService; - } - public async ValueTask ProduceAsync(string terminalNo, byte[] data) - { - await JT808MsgService.WriteAsync(terminalNo, data); - } - public void Dispose() - { - - } - } -} diff --git a/src/JT808.Gateway.InMemoryMQ/JT808MsgReplyConsumer.cs b/src/JT808.Gateway.InMemoryMQ/JT808MsgReplyConsumer.cs deleted file mode 100644 index 7eb172e..0000000 --- a/src/JT808.Gateway.InMemoryMQ/JT808MsgReplyConsumer.cs +++ /dev/null @@ -1,63 +0,0 @@ -using JT808.Gateway.Abstractions; -using JT808.Gateway.InMemoryMQ.Services; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace JT808.Gateway.InMemoryMQ -{ - public class JT808MsgReplyConsumer : IJT808MsgReplyConsumer - { - private readonly JT808ReplyMsgService JT808ReplyMsgService; - public CancellationTokenSource Cts => new CancellationTokenSource(); - - private readonly ILogger logger; - - public string TopicName => JT808GatewayConstants.MsgReplyTopic; - - public JT808MsgReplyConsumer( - JT808ReplyMsgService jT808ReplyMsgService, - ILoggerFactory loggerFactory) - { - logger = loggerFactory.CreateLogger("JT808MsgReplyConsumer"); - JT808ReplyMsgService = jT808ReplyMsgService; - } - - public void OnMessage(Action<(string TerminalNo, byte[] Data)> callback) - { - Task.Run(async() => - { - while (!Cts.IsCancellationRequested) - { - try - { - var item= await JT808ReplyMsgService.ReadAsync(Cts.Token); - callback(item); - } - catch (Exception ex) - { - logger.LogError(ex, ""); - } - } - }, Cts.Token); - } - - public void Subscribe() - { - - } - - public void Unsubscribe() - { - Cts.Cancel(); - } - - public void Dispose() - { - Cts.Dispose(); - } - } -} diff --git a/src/JT808.Gateway.InMemoryMQ/JT808MsgReplyConsumerFactory.cs b/src/JT808.Gateway.InMemoryMQ/JT808MsgReplyConsumerFactory.cs deleted file mode 100644 index ab256de..0000000 --- a/src/JT808.Gateway.InMemoryMQ/JT808MsgReplyConsumerFactory.cs +++ /dev/null @@ -1,23 +0,0 @@ -using JT808.Gateway.Abstractions; -using JT808.Gateway.Abstractions.Enums; -using System; -using System.Collections.Generic; -using System.Text; - -namespace JT808.Gateway.InMemoryMQ -{ - public class JT808MsgReplyConsumerFactory : IJT808MsgReplyConsumerFactory - { - private readonly Func factory; - - public JT808MsgReplyConsumerFactory(Func accesor) - { - factory = accesor; - } - - public IJT808MsgReplyConsumer Create(JT808ConsumerType consumerType) - { - return factory(consumerType); - } - } -} diff --git a/src/JT808.Gateway.InMemoryMQ/JT808MsgReplyProducer.cs b/src/JT808.Gateway.InMemoryMQ/JT808MsgReplyProducer.cs deleted file mode 100644 index 76ce9b4..0000000 --- a/src/JT808.Gateway.InMemoryMQ/JT808MsgReplyProducer.cs +++ /dev/null @@ -1,43 +0,0 @@ -using JT808.Gateway.Abstractions; -using JT808.Gateway.Abstractions.Enums; -using JT808.Gateway.InMemoryMQ.Services; -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; - -namespace JT808.Gateway.InMemoryMQ -{ - public class JT808MsgReplyProducer : IJT808MsgReplyProducer - { - public string TopicName => JT808GatewayConstants.MsgReplyTopic; - - //JT808ServerInMemoryMQExtensions - private readonly JT808ReplyMsgService JT808ReplyMsgService; - - private readonly Func func; - public JT808MsgReplyProducer( - Func func, - JT808ReplyMsgService jT808ReplyMsgService) - { - this.func = func; - JT808ReplyMsgService = jT808ReplyMsgService; - } - public async ValueTask ProduceAsync(string terminalNo, byte[] data) - { - await JT808ReplyMsgService.WriteAsync(terminalNo, data); - if (JT808ServerInMemoryMQExtensions.ReplyMessageLoggingConsumer.HasValue) - { - var method = func(JT808ConsumerType.ReplyMessageLoggingConsumer); - if (method != null) - { - await method.WriteAsync(terminalNo, data); - } - } - } - public void Dispose() - { - - } - } -} diff --git a/src/JT808.Gateway.InMemoryMQ/JT808ServerInMemoryMQExtensions.cs b/src/JT808.Gateway.InMemoryMQ/JT808ServerInMemoryMQExtensions.cs deleted file mode 100644 index ac3a0ff..0000000 --- a/src/JT808.Gateway.InMemoryMQ/JT808ServerInMemoryMQExtensions.cs +++ /dev/null @@ -1,363 +0,0 @@ -using JT808.Gateway.Abstractions; -using JT808.Gateway.Abstractions.Enums; -using JT808.Gateway.InMemoryMQ.Services; -using Microsoft.Extensions.DependencyInjection; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.CompilerServices; - -[assembly: InternalsVisibleTo("JT808.Gateway.InMemoryMQ.Test")] -namespace JT808.Gateway.InMemoryMQ -{ - public static class JT808ServerInMemoryMQExtensions - { - internal static List ConsumerTypes { get; private set; } - - static JT808ServerInMemoryMQExtensions() - { - ConsumerTypes = new List(); - } - - internal static JT808ConsumerType? ReplyMessageLoggingConsumer { get; private set; } - - /// - /// - /// - /// - /// - public static IJT808GatewayBuilder AddServerInMemoryMQ(this IJT808GatewayBuilder jT808GatewayBuilder, JT808ConsumerType consumerType) - { - if ((consumerType & JT808ConsumerType.All) == JT808ConsumerType.All) - { - ConsumerTypes.Add(JT808ConsumerType.MsgIdHandlerConsumer); - ConsumerTypes.Add(JT808ConsumerType.MsgLoggingConsumer); - ConsumerTypes.Add(JT808ConsumerType.ReplyMessageConsumer); - ConsumerTypes.Add(JT808ConsumerType.TrafficConsumer); - ConsumerTypes.Add(JT808ConsumerType.TransmitConsumer); - ConsumerTypes.Add(JT808ConsumerType.ReplyMessageLoggingConsumer); - } - else - { - if ((consumerType & JT808ConsumerType.MsgLoggingConsumer) == JT808ConsumerType.MsgLoggingConsumer) - { - ConsumerTypes.Add(JT808ConsumerType.MsgLoggingConsumer); - } - if ((consumerType & JT808ConsumerType.MsgIdHandlerConsumer) == JT808ConsumerType.MsgIdHandlerConsumer) - { - ConsumerTypes.Add(JT808ConsumerType.MsgIdHandlerConsumer); - } - if ((consumerType & JT808ConsumerType.ReplyMessageConsumer) == JT808ConsumerType.ReplyMessageConsumer) - { - ConsumerTypes.Add(JT808ConsumerType.ReplyMessageConsumer); - } - if ((consumerType & JT808ConsumerType.TrafficConsumer) == JT808ConsumerType.TrafficConsumer) - { - ConsumerTypes.Add(JT808ConsumerType.TrafficConsumer); - } - if ((consumerType & JT808ConsumerType.TransmitConsumer) == JT808ConsumerType.TransmitConsumer) - { - ConsumerTypes.Add(JT808ConsumerType.TransmitConsumer); - } - if ((consumerType & JT808ConsumerType.ReplyMessageLoggingConsumer) == JT808ConsumerType.ReplyMessageLoggingConsumer) - { - // - ReplyMessageLoggingConsumer = JT808ConsumerType.ReplyMessageLoggingConsumer; - } - } - jT808GatewayBuilder.AddServerInMemoryConsumers(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddHostedService(); - return jT808GatewayBuilder; - } - - /// - /// - /// - /// - /// - public static IJT808GatewayBuilder AddServerInMemoryMQ(this IJT808GatewayBuilder jT808GatewayBuilder,params JT808ConsumerType[] consumerTypes) - { - if (consumerTypes == null) - { - throw new ArgumentNullException("消费类型不为空!"); - } - ConsumerTypes = consumerTypes.ToList(); - jT808GatewayBuilder.AddServerInMemoryConsumers(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddHostedService(); - return jT808GatewayBuilder; - } - - /// - /// - /// - /// - /// - internal static IServiceCollection AddServerInMemoryMQ(this IServiceCollection serviceDescriptors, JT808ConsumerType consumerType) - { - if ((consumerType & JT808ConsumerType.All) == JT808ConsumerType.All) - { - ConsumerTypes.Add(JT808ConsumerType.MsgIdHandlerConsumer); - ConsumerTypes.Add(JT808ConsumerType.MsgLoggingConsumer); - ConsumerTypes.Add(JT808ConsumerType.ReplyMessageConsumer); - ConsumerTypes.Add(JT808ConsumerType.TrafficConsumer); - ConsumerTypes.Add(JT808ConsumerType.TransmitConsumer); - } - else - { - if ((consumerType & JT808ConsumerType.MsgLoggingConsumer) == JT808ConsumerType.MsgLoggingConsumer) - { - ConsumerTypes.Add(JT808ConsumerType.MsgLoggingConsumer); - } - if ((consumerType & JT808ConsumerType.MsgIdHandlerConsumer) == JT808ConsumerType.MsgIdHandlerConsumer) - { - ConsumerTypes.Add(JT808ConsumerType.MsgIdHandlerConsumer); - } - if ((consumerType & JT808ConsumerType.ReplyMessageConsumer) == JT808ConsumerType.ReplyMessageConsumer) - { - ConsumerTypes.Add(JT808ConsumerType.ReplyMessageConsumer); - } - if ((consumerType & JT808ConsumerType.TrafficConsumer) == JT808ConsumerType.TrafficConsumer) - { - ConsumerTypes.Add(JT808ConsumerType.TrafficConsumer); - } - if ((consumerType & JT808ConsumerType.TransmitConsumer) == JT808ConsumerType.TransmitConsumer) - { - ConsumerTypes.Add(JT808ConsumerType.TransmitConsumer); - } - if ((consumerType & JT808ConsumerType.ReplyMessageLoggingConsumer) == JT808ConsumerType.ReplyMessageLoggingConsumer) - { - ReplyMessageLoggingConsumer = JT808ConsumerType.ReplyMessageLoggingConsumer; - } - } - serviceDescriptors.AddServerInMemoryConsumers(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddHostedService(); - return serviceDescriptors; - } - - /// - /// - /// - /// - /// - internal static IServiceCollection AddServerInMemoryMQ(this IServiceCollection serviceDescriptors, params JT808ConsumerType[] consumerTypes) - { - if (consumerTypes == null) - { - throw new ArgumentNullException("消费类型不为空!"); - } - ConsumerTypes = consumerTypes.ToList(); - serviceDescriptors.AddServerInMemoryConsumers(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddHostedService(); - return serviceDescriptors; - } - - - /// - /// - /// - /// - /// - private static IJT808GatewayBuilder AddServerInMemoryConsumers(this IJT808GatewayBuilder jT808GatewayBuilder) - { - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton((factory) => - { - Func accesor = type => - { - switch (type) - { - case JT808ConsumerType.MsgIdHandlerConsumer: - return factory.GetRequiredService(); - case JT808ConsumerType.MsgLoggingConsumer: - return factory.GetRequiredService(); - case JT808ConsumerType.TrafficConsumer: - return factory.GetRequiredService(); - case JT808ConsumerType.TransmitConsumer: - return factory.GetRequiredService(); - case JT808ConsumerType.ReplyMessageConsumer: - return factory.GetRequiredService(); - default: - return default; - } - }; - return accesor; - }); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton((factory) => - { - Func accesor = type => - { - switch (type) - { - case JT808ConsumerType.ReplyMessageLoggingConsumer: - return factory.GetRequiredService(); - default: - return default; - } - }; - return accesor; - }); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton((factory) => - { - Func accesor = type => - { - switch (type) - { - case JT808ConsumerType.MsgIdHandlerConsumer: - return factory.GetRequiredService(); - case JT808ConsumerType.MsgLoggingConsumer: - return factory.GetRequiredService(); - case JT808ConsumerType.TrafficConsumer: - return factory.GetRequiredService(); - case JT808ConsumerType.TransmitConsumer: - return factory.GetRequiredService(); - case JT808ConsumerType.ReplyMessageConsumer: - return factory.GetRequiredService(); - case JT808ConsumerType.ReplyMessageLoggingConsumer: - return factory.GetRequiredService(); - default: - return default; - } - }; - return accesor; - }); - return jT808GatewayBuilder; - } - - /// - /// - /// - /// - /// - private static IServiceCollection AddServerInMemoryConsumers(this IServiceCollection serviceDescriptors) - { - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton((factory) => - { - Func accesor = type => - { - switch (type) - { - case JT808ConsumerType.MsgIdHandlerConsumer: - return factory.GetRequiredService(); - case JT808ConsumerType.MsgLoggingConsumer: - return factory.GetRequiredService(); - case JT808ConsumerType.TrafficConsumer: - return factory.GetRequiredService(); - case JT808ConsumerType.TransmitConsumer: - return factory.GetRequiredService(); - case JT808ConsumerType.ReplyMessageConsumer: - return factory.GetRequiredService(); - default: - return default; - } - }; - return accesor; - }); - serviceDescriptors.AddSingleton((factory) => - { - Func accesor = type => - { - switch (type) - { - case JT808ConsumerType.ReplyMessageLoggingConsumer: - return factory.GetRequiredService(); - default: - return default; - } - }; - return accesor; - }); - serviceDescriptors.AddSingleton((factory) => - { - Func accesor = type => - { - switch (type) - { - case JT808ConsumerType.MsgIdHandlerConsumer: - return factory.GetRequiredService(); - case JT808ConsumerType.MsgLoggingConsumer: - return factory.GetRequiredService(); - case JT808ConsumerType.TrafficConsumer: - return factory.GetRequiredService(); - case JT808ConsumerType.TransmitConsumer: - return factory.GetRequiredService(); - case JT808ConsumerType.ReplyMessageConsumer: - return factory.GetRequiredService(); - case JT808ConsumerType.ReplyMessageLoggingConsumer: - return factory.GetRequiredService(); - default: - return default; - } - }; - return accesor; - }); - return serviceDescriptors; - } - } -} \ No newline at end of file diff --git a/src/JT808.Gateway.InMemoryMQ/Services/JT808MsgIdHandlerService.cs b/src/JT808.Gateway.InMemoryMQ/Services/JT808MsgIdHandlerService.cs deleted file mode 100644 index 028ba53..0000000 --- a/src/JT808.Gateway.InMemoryMQ/Services/JT808MsgIdHandlerService.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading; -using System.Threading.Channels; -using System.Threading.Tasks; - -namespace JT808.Gateway.InMemoryMQ.Services -{ - public class JT808MsgIdHandlerService: JT808MsgServiceBase - { - - } -} diff --git a/src/JT808.Gateway.InMemoryMQ/Services/JT808MsgLoggingService.cs b/src/JT808.Gateway.InMemoryMQ/Services/JT808MsgLoggingService.cs deleted file mode 100644 index 4fc0fc9..0000000 --- a/src/JT808.Gateway.InMemoryMQ/Services/JT808MsgLoggingService.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading; -using System.Threading.Channels; -using System.Threading.Tasks; - -namespace JT808.Gateway.InMemoryMQ.Services -{ - public class JT808MsgLoggingService: JT808MsgServiceBase - { - - } -} diff --git a/src/JT808.Gateway.InMemoryMQ/Services/JT808MsgReplyMessageLoggingService.cs b/src/JT808.Gateway.InMemoryMQ/Services/JT808MsgReplyMessageLoggingService.cs deleted file mode 100644 index 58c4001..0000000 --- a/src/JT808.Gateway.InMemoryMQ/Services/JT808MsgReplyMessageLoggingService.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading; -using System.Threading.Channels; -using System.Threading.Tasks; - -namespace JT808.Gateway.InMemoryMQ.Services -{ - public class JT808MsgReplyMessageLoggingService : JT808MsgServiceBase - { - - } -} diff --git a/src/JT808.Gateway.InMemoryMQ/Services/JT808MsgReplyMessageService.cs b/src/JT808.Gateway.InMemoryMQ/Services/JT808MsgReplyMessageService.cs deleted file mode 100644 index e2831f3..0000000 --- a/src/JT808.Gateway.InMemoryMQ/Services/JT808MsgReplyMessageService.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading; -using System.Threading.Channels; -using System.Threading.Tasks; - -namespace JT808.Gateway.InMemoryMQ.Services -{ - public class JT808MsgReplyMessageService: JT808MsgServiceBase - { - - } -} diff --git a/src/JT808.Gateway.InMemoryMQ/Services/JT808MsgService.cs b/src/JT808.Gateway.InMemoryMQ/Services/JT808MsgService.cs deleted file mode 100644 index 83ec2d1..0000000 --- a/src/JT808.Gateway.InMemoryMQ/Services/JT808MsgService.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading; -using System.Threading.Channels; -using System.Threading.Tasks; - -namespace JT808.Gateway.InMemoryMQ.Services -{ - public class JT808MsgService: JT808MsgServiceBase - { - - } -} diff --git a/src/JT808.Gateway.InMemoryMQ/Services/JT808MsgServiceBase.cs b/src/JT808.Gateway.InMemoryMQ/Services/JT808MsgServiceBase.cs deleted file mode 100644 index 8e3b067..0000000 --- a/src/JT808.Gateway.InMemoryMQ/Services/JT808MsgServiceBase.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading; -using System.Threading.Channels; -using System.Threading.Tasks; - -namespace JT808.Gateway.InMemoryMQ.Services -{ - public class JT808MsgServiceBase - { - private readonly Channel<(string TerminalNo, byte[] Data)> _channel; - - public JT808MsgServiceBase() - { - _channel = Channel.CreateUnbounded<(string TerminalNo, byte[] Data)>(); - } - - public async ValueTask WriteAsync(string terminalNo, byte[] data) - { - await _channel.Writer.WriteAsync((terminalNo, data)); - } - - public async ValueTask<(string TerminalNo, byte[] Data)> ReadAsync(CancellationToken cancellationToken) - { - return await _channel.Reader.ReadAsync(cancellationToken); - } - } -} diff --git a/src/JT808.Gateway.InMemoryMQ/Services/JT808MsgTrafficService.cs b/src/JT808.Gateway.InMemoryMQ/Services/JT808MsgTrafficService.cs deleted file mode 100644 index da8da45..0000000 --- a/src/JT808.Gateway.InMemoryMQ/Services/JT808MsgTrafficService.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading; -using System.Threading.Channels; -using System.Threading.Tasks; - -namespace JT808.Gateway.InMemoryMQ.Services -{ - public class JT808MsgTrafficService: JT808MsgServiceBase - { - - } -} diff --git a/src/JT808.Gateway.InMemoryMQ/Services/JT808MsgTransmitService.cs b/src/JT808.Gateway.InMemoryMQ/Services/JT808MsgTransmitService.cs deleted file mode 100644 index fc52024..0000000 --- a/src/JT808.Gateway.InMemoryMQ/Services/JT808MsgTransmitService.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading; -using System.Threading.Channels; -using System.Threading.Tasks; - -namespace JT808.Gateway.InMemoryMQ.Services -{ - public class JT808MsgTransmitService: JT808MsgServiceBase - { - - } -} diff --git a/src/JT808.Gateway.InMemoryMQ/Services/JT808ReplyMsgService.cs b/src/JT808.Gateway.InMemoryMQ/Services/JT808ReplyMsgService.cs deleted file mode 100644 index a24200f..0000000 --- a/src/JT808.Gateway.InMemoryMQ/Services/JT808ReplyMsgService.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading; -using System.Threading.Channels; -using System.Threading.Tasks; - -namespace JT808.Gateway.InMemoryMQ.Services -{ - public class JT808ReplyMsgService: JT808MsgServiceBase - { - - } -} diff --git a/src/JT808.Gateway.Kafka/JT808ServerKafkaExtensions.cs b/src/JT808.Gateway.Kafka/JT808ServerKafkaExtensions.cs index 3d9d9b0..d58ba2a 100644 --- a/src/JT808.Gateway.Kafka/JT808ServerKafkaExtensions.cs +++ b/src/JT808.Gateway.Kafka/JT808ServerKafkaExtensions.cs @@ -14,7 +14,7 @@ namespace JT808.Gateway.Kafka /// /// GetSection("JT808MsgProducerConfig") /// - public static IJT808GatewayBuilder AddServerKafkaMsgProducer(this IJT808GatewayBuilder jT808GatewayBuilder, IConfiguration configuration) + public static IJT808QueueGatewayBuilder AddServerKafkaMsgProducer(this IJT808QueueGatewayBuilder jT808GatewayBuilder, IConfiguration configuration) { jT808GatewayBuilder.JT808Builder.Services.Configure(configuration.GetSection("JT808MsgProducerConfig")); jT808GatewayBuilder.JT808Builder.Services.Replace(new ServiceDescriptor(typeof(IJT808MsgProducer), typeof(JT808MsgProducer), ServiceLifetime.Singleton)); @@ -26,7 +26,7 @@ namespace JT808.Gateway.Kafka /// /// GetSection("JT808MsgReplyConsumerConfig") /// - public static IJT808GatewayBuilder AddServerKafkaMsgReplyConsumer(this IJT808GatewayBuilder jT808GatewayBuilder, IConfiguration configuration) + public static IJT808QueueGatewayBuilder AddServerKafkaMsgReplyConsumer(this IJT808QueueGatewayBuilder jT808GatewayBuilder, IConfiguration configuration) { jT808GatewayBuilder.JT808Builder.Services.Configure(configuration.GetSection("JT808MsgReplyConsumerConfig")); jT808GatewayBuilder.JT808Builder.Services.Replace(new ServiceDescriptor(typeof(IJT808MsgReplyConsumer), typeof(JT808MsgReplyConsumer), ServiceLifetime.Singleton)); @@ -38,7 +38,7 @@ namespace JT808.Gateway.Kafka /// /// GetSection("JT808SessionProducerConfig") /// - public static IJT808GatewayBuilder AddServerKafkaSessionProducer(this IJT808GatewayBuilder jT808GatewayBuilder, IConfiguration configuration) + public static IJT808QueueGatewayBuilder AddServerKafkaSessionProducer(this IJT808QueueGatewayBuilder jT808GatewayBuilder, IConfiguration configuration) { jT808GatewayBuilder.JT808Builder.Services.Configure(configuration.GetSection("JT808SessionProducerConfig")); jT808GatewayBuilder.JT808Builder.Services.Replace(new ServiceDescriptor(typeof(IJT808SessionProducer), typeof(JT808SessionProducer), ServiceLifetime.Singleton)); diff --git a/src/JT808.Gateway.Services/JT808.Gateway.MsgIdHandler/JT808MsgIdHandlerExtensions.cs b/src/JT808.Gateway.Services/JT808.Gateway.MsgIdHandler/JT808MsgIdHandlerExtensions.cs index 5cefd83..4a711e8 100644 --- a/src/JT808.Gateway.Services/JT808.Gateway.MsgIdHandler/JT808MsgIdHandlerExtensions.cs +++ b/src/JT808.Gateway.Services/JT808.Gateway.MsgIdHandler/JT808MsgIdHandlerExtensions.cs @@ -15,13 +15,5 @@ namespace JT808.Gateway.MsgIdHandler jT808ClientBuilder.JT808Builder.Services.AddHostedService(); return jT808ClientBuilder; } - - public static IJT808GatewayBuilder AddInMemoryMsgIdHandler(this IJT808GatewayBuilder jT808GatewayBuilder) - where TJT808MsgIdHandler : IJT808MsgIdHandler - { - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(typeof(IJT808MsgIdHandler), typeof(TJT808MsgIdHandler)); - jT808GatewayBuilder.JT808Builder.Services.AddHostedService(); - return jT808GatewayBuilder; - } } } diff --git a/src/JT808.Gateway.Services/JT808.Gateway.MsgIdHandler/JT808MsgIdHandlerInMemoryHostedService.cs b/src/JT808.Gateway.Services/JT808.Gateway.MsgIdHandler/JT808MsgIdHandlerInMemoryHostedService.cs deleted file mode 100644 index 09d0661..0000000 --- a/src/JT808.Gateway.Services/JT808.Gateway.MsgIdHandler/JT808MsgIdHandlerInMemoryHostedService.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Threading.Tasks; -using Microsoft.Extensions.Hosting; -using System.Threading; -using JT808.Gateway.Abstractions; -using JT808.Gateway.Abstractions.Enums; - -namespace JT808.Gateway.MsgIdHandler -{ - public class JT808MsgIdHandlerInMemoryHostedService : IHostedService - { - private readonly IJT808MsgConsumer jT808MsgConsumer; - - private readonly IJT808MsgIdHandler jT808MsgIdHandler; - public JT808MsgIdHandlerInMemoryHostedService( - IJT808MsgIdHandler jT808MsgIdHandler, - IJT808MsgConsumerFactory jT808MsgConsumerFactory) - { - this.jT808MsgIdHandler = jT808MsgIdHandler; - this.jT808MsgConsumer = jT808MsgConsumerFactory.Create(JT808ConsumerType.MsgIdHandlerConsumer); - } - - public Task StartAsync(CancellationToken cancellationToken) - { - jT808MsgConsumer.Subscribe(); - jT808MsgConsumer.OnMessage(jT808MsgIdHandler.Processor); - return Task.CompletedTask; - } - - public Task StopAsync(CancellationToken cancellationToken) - { - jT808MsgConsumer.Unsubscribe(); - return Task.CompletedTask; - } - } -} diff --git a/src/JT808.Gateway.Services/JT808.Gateway.MsgLogging/JT808MsgDownLoggingInMemoryHostedService.cs b/src/JT808.Gateway.Services/JT808.Gateway.MsgLogging/JT808MsgDownLoggingInMemoryHostedService.cs deleted file mode 100644 index 8b53812..0000000 --- a/src/JT808.Gateway.Services/JT808.Gateway.MsgLogging/JT808MsgDownLoggingInMemoryHostedService.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Threading.Tasks; -using Microsoft.Extensions.Hosting; -using System.Threading; -using JT808.Gateway.Abstractions; -using JT808.Gateway.Abstractions.Enums; - -namespace JT808.Gateway.MsgLogging -{ - public class JT808MsgDownLoggingInMemoryHostedService : IHostedService - { - private readonly IJT808MsgReplyConsumer jT808MsgReplyConsumer; - private readonly IJT808MsgLogging jT808MsgLogging; - public JT808MsgDownLoggingInMemoryHostedService( - IJT808MsgLogging jT808MsgLogging, - IJT808MsgReplyConsumerFactory jT808MsgReplyConsumerFactory) - { - this.jT808MsgReplyConsumer = jT808MsgReplyConsumerFactory.Create(JT808ConsumerType.ReplyMessageLoggingConsumer); - this.jT808MsgLogging = jT808MsgLogging; - } - - public Task StartAsync(CancellationToken cancellationToken) - { - jT808MsgReplyConsumer.Subscribe(); - jT808MsgReplyConsumer.OnMessage(item=> - { - jT808MsgLogging.Processor(item, JT808MsgLoggingType.down); - }); - return Task.CompletedTask; - } - - public Task StopAsync(CancellationToken cancellationToken) - { - jT808MsgReplyConsumer.Unsubscribe(); - return Task.CompletedTask; - } - } -} diff --git a/src/JT808.Gateway.Services/JT808.Gateway.MsgLogging/JT808MsgLoggingExtensions.cs b/src/JT808.Gateway.Services/JT808.Gateway.MsgLogging/JT808MsgLoggingExtensions.cs index 2890b4b..19e38fd 100644 --- a/src/JT808.Gateway.Services/JT808.Gateway.MsgLogging/JT808MsgLoggingExtensions.cs +++ b/src/JT808.Gateway.Services/JT808.Gateway.MsgLogging/JT808MsgLoggingExtensions.cs @@ -17,13 +17,11 @@ namespace JT808.Gateway.MsgLogging return jT808ClientBuilder; } - public static IJT808GatewayBuilder AddInMemoryMsgLogging(this IJT808GatewayBuilder jT808GatewayBuilder) + public static IJT808NormalGatewayBuilder AddMsgLogging(this IJT808NormalGatewayBuilder jT808NormalGatewayBuilder) where TJT808MsgLogging : IJT808MsgLogging { - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(typeof(IJT808MsgLogging), typeof(TJT808MsgLogging)); - jT808GatewayBuilder.JT808Builder.Services.AddHostedService(); - jT808GatewayBuilder.JT808Builder.Services.AddHostedService(); - return jT808GatewayBuilder; + jT808NormalGatewayBuilder.JT808Builder.Services.AddSingleton(typeof(IJT808MsgLogging), typeof(TJT808MsgLogging)); + return jT808NormalGatewayBuilder; } } } diff --git a/src/JT808.Gateway.Services/JT808.Gateway.MsgLogging/JT808MsgUpLoggingInMemoryHostedService.cs b/src/JT808.Gateway.Services/JT808.Gateway.MsgLogging/JT808MsgUpLoggingInMemoryHostedService.cs deleted file mode 100644 index 7784def..0000000 --- a/src/JT808.Gateway.Services/JT808.Gateway.MsgLogging/JT808MsgUpLoggingInMemoryHostedService.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Threading.Tasks; -using Microsoft.Extensions.Hosting; -using System.Threading; -using JT808.Gateway.Abstractions; -using JT808.Gateway.Abstractions.Enums; - -namespace JT808.Gateway.MsgLogging -{ - public class JT808MsgUpLoggingInMemoryHostedService : IHostedService - { - private readonly IJT808MsgConsumer jT808MsgConsumer; - private readonly IJT808MsgLogging jT808MsgLogging; - public JT808MsgUpLoggingInMemoryHostedService( - IJT808MsgLogging jT808MsgLogging, - IJT808MsgConsumerFactory jT808MsgConsumerFactory) - { - this.jT808MsgConsumer = jT808MsgConsumerFactory.Create(JT808ConsumerType.MsgLoggingConsumer); - this.jT808MsgLogging = jT808MsgLogging; - } - - public Task StartAsync(CancellationToken cancellationToken) - { - jT808MsgConsumer.Subscribe(); - jT808MsgConsumer.OnMessage(item=> - { - jT808MsgLogging.Processor(item, JT808MsgLoggingType.up); - }); - return Task.CompletedTask; - } - - public Task StopAsync(CancellationToken cancellationToken) - { - jT808MsgConsumer.Unsubscribe(); - return Task.CompletedTask; - } - } -} diff --git a/src/JT808.Gateway.Services/JT808.Gateway.ReplyMessage/JT808ReplyMessageExtensions.cs b/src/JT808.Gateway.Services/JT808.Gateway.ReplyMessage/JT808ReplyMessageExtensions.cs index 7a9e786..28084fb 100644 --- a/src/JT808.Gateway.Services/JT808.Gateway.ReplyMessage/JT808ReplyMessageExtensions.cs +++ b/src/JT808.Gateway.Services/JT808.Gateway.ReplyMessage/JT808ReplyMessageExtensions.cs @@ -14,9 +14,9 @@ namespace JT808.Gateway.ReplyMessage /// /// /// - public static IJT808ClientBuilder AddInPlugReplyMessage(this IJT808ClientBuilder jT808ClientBuilder) + public static IJT808ClientBuilder AddReplyMessage(this IJT808ClientBuilder jT808ClientBuilder) { - jT808ClientBuilder.JT808Builder.Services.AddSingleton(); + jT808ClientBuilder.JT808Builder.Services.AddSingleton(); jT808ClientBuilder.JT808Builder.Services.AddHostedService(); return jT808ClientBuilder; } @@ -26,36 +26,12 @@ namespace JT808.Gateway.ReplyMessage /// 自定义消息回复服务 /// /// - public static IJT808ClientBuilder AddInPlugReplyMessage(this IJT808ClientBuilder jT808ClientBuilder) - where TReplyMessageHandler : JT808ReplyMessageHandler + public static IJT808ClientBuilder AddReplyMessage(this IJT808ClientBuilder jT808ClientBuilder) + where TReplyMessageHandler : JT808QueueReplyMessageHandler { - jT808ClientBuilder.JT808Builder.Services.AddSingleton(); + jT808ClientBuilder.JT808Builder.Services.AddSingleton(); jT808ClientBuilder.JT808Builder.Services.AddHostedService(); return jT808ClientBuilder; } - /// - /// 消息应答服务(消费者单实例) - /// - /// 自定义消息回复服务 - /// - /// - public static IJT808GatewayBuilder AddInMemoryReplyMessage(this IJT808GatewayBuilder jT808GatewayBuilder) - where TReplyMessageHandler : JT808ReplyMessageHandler - { - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddHostedService(); - return jT808GatewayBuilder; - } - /// - /// 消息应答服务(消费者单实例) - /// - /// - /// - public static IJT808GatewayBuilder AddInMemoryReplyMessage(this IJT808GatewayBuilder jT808GatewayBuilder) - { - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddHostedService(); - return jT808GatewayBuilder; - } } } diff --git a/src/JT808.Gateway.Services/JT808.Gateway.ReplyMessage/JT808ReplyMessageHostedService.cs b/src/JT808.Gateway.Services/JT808.Gateway.ReplyMessage/JT808ReplyMessageHostedService.cs index 41937ae..dfcdef3 100644 --- a/src/JT808.Gateway.Services/JT808.Gateway.ReplyMessage/JT808ReplyMessageHostedService.cs +++ b/src/JT808.Gateway.Services/JT808.Gateway.ReplyMessage/JT808ReplyMessageHostedService.cs @@ -8,10 +8,10 @@ namespace JT808.Gateway.ReplyMessage public class JT808ReplyMessageHostedService : IHostedService { private readonly IJT808MsgConsumer jT808MsgConsumer; - private readonly JT808ReplyMessageHandler jT808ReplyMessageHandler; + private readonly JT808QueueReplyMessageHandler jT808ReplyMessageHandler; public JT808ReplyMessageHostedService( - JT808ReplyMessageHandler jT808ReplyMessageHandler, + JT808QueueReplyMessageHandler jT808ReplyMessageHandler, IJT808MsgConsumer jT808MsgConsumer) { this.jT808MsgConsumer = jT808MsgConsumer; diff --git a/src/JT808.Gateway.Services/JT808.Gateway.ReplyMessage/JT808ReplyMessageInMemoryHostedService.cs b/src/JT808.Gateway.Services/JT808.Gateway.ReplyMessage/JT808ReplyMessageInMemoryHostedService.cs deleted file mode 100644 index cb25d30..0000000 --- a/src/JT808.Gateway.Services/JT808.Gateway.ReplyMessage/JT808ReplyMessageInMemoryHostedService.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Threading.Tasks; -using Microsoft.Extensions.Hosting; -using System.Threading; -using JT808.Gateway.Abstractions; -using JT808.Gateway.Abstractions.Enums; - -namespace JT808.Gateway.ReplyMessage -{ - public class JT808ReplyMessageInMemoryHostedService : IHostedService - { - private readonly IJT808MsgConsumer jT808MsgConsumer; - private readonly JT808ReplyMessageHandler jT808ReplyMessageHandler; - - public JT808ReplyMessageInMemoryHostedService( - JT808ReplyMessageHandler jT808ReplyMessageHandler, - IJT808MsgConsumerFactory jT808MsgConsumerFactory) - { - this.jT808MsgConsumer = jT808MsgConsumerFactory.Create(JT808ConsumerType.ReplyMessageConsumer); - this.jT808ReplyMessageHandler = jT808ReplyMessageHandler; - } - - public Task StartAsync(CancellationToken cancellationToken) - { - jT808MsgConsumer.Subscribe(); - jT808MsgConsumer.OnMessage(jT808ReplyMessageHandler.Processor); - return Task.CompletedTask; - } - - public Task StopAsync(CancellationToken cancellationToken) - { - jT808MsgConsumer.Unsubscribe(); - return Task.CompletedTask; - } - } -} diff --git a/src/JT808.Gateway.Services/JT808.Gateway.SessionNotice/JT808SessionNoticeExtensions.cs b/src/JT808.Gateway.Services/JT808.Gateway.SessionNotice/JT808SessionNoticeExtensions.cs index 5622a64..945286b 100644 --- a/src/JT808.Gateway.Services/JT808.Gateway.SessionNotice/JT808SessionNoticeExtensions.cs +++ b/src/JT808.Gateway.Services/JT808.Gateway.SessionNotice/JT808SessionNoticeExtensions.cs @@ -14,7 +14,7 @@ namespace JT808.Gateway.SessionNotice /// /// /// - public static IJT808ClientBuilder AddInPlugSessionNotice(this IJT808ClientBuilder jT808ClientBuilder) + public static IJT808ClientBuilder AddSessionNotice(this IJT808ClientBuilder jT808ClientBuilder) { jT808ClientBuilder.JT808Builder.Services.AddSingleton(); jT808ClientBuilder.JT808Builder.Services.AddHostedService(); @@ -27,7 +27,7 @@ namespace JT808.Gateway.SessionNotice /// 自定义会话通知服务 /// /// - public static IJT808ClientBuilder AddInPlugSessionNotice(this IJT808ClientBuilder jT808ClientBuilder) + public static IJT808ClientBuilder AddSessionNotice(this IJT808ClientBuilder jT808ClientBuilder) where TSessionNoticeService : JT808SessionNoticeService { jT808ClientBuilder.JT808Builder.Services.AddSingleton(); @@ -36,29 +36,29 @@ namespace JT808.Gateway.SessionNotice } /// - /// 消息会话通知服务(消费者单实例) + /// 会话通知服务(不同的消费者实例) /// - /// 自定义会话通知服务 - /// + /// /// - public static IJT808GatewayBuilder AddInMemorySessionNotice(this IJT808GatewayBuilder jT808GatewayBuilder) - where TSessionNoticeService : JT808SessionNoticeService + public static IJT808NormalGatewayBuilder AddSessionNotice(this IJT808NormalGatewayBuilder jT808NormalGatewayBuilder) { - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddHostedService(); - return jT808GatewayBuilder; + jT808NormalGatewayBuilder.JT808Builder.Services.AddSingleton(); + jT808NormalGatewayBuilder.JT808Builder.Services.AddHostedService(); + return jT808NormalGatewayBuilder; } /// - /// 消息会话通知服务(消费者单实例) + /// 消息会话通知服务(不同的消费者实例) /// - /// + /// 自定义会话通知服务 + /// /// - public static IJT808GatewayBuilder AddInMemorySessionNotice(this IJT808GatewayBuilder jT808GatewayBuilder) + public static IJT808NormalGatewayBuilder AddSessionNotice(this IJT808NormalGatewayBuilder jT808NormalGatewayBuilder) + where TSessionNoticeService : JT808SessionNoticeService { - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddHostedService(); - return jT808GatewayBuilder; + jT808NormalGatewayBuilder.JT808Builder.Services.AddSingleton(); + jT808NormalGatewayBuilder.JT808Builder.Services.AddHostedService(); + return jT808NormalGatewayBuilder; } } } diff --git a/src/JT808.Gateway.Services/JT808.Gateway.Traffic/IJT808Traffic.cs b/src/JT808.Gateway.Services/JT808.Gateway.Traffic/IJT808Traffic.cs index 084cc4e..c7c6f94 100644 --- a/src/JT808.Gateway.Services/JT808.Gateway.Traffic/IJT808Traffic.cs +++ b/src/JT808.Gateway.Services/JT808.Gateway.Traffic/IJT808Traffic.cs @@ -13,7 +13,7 @@ namespace JT808.Gateway.Traffic List<(string,long)> GetAll(); } - public class JT808TrafficDefault : IJT808Traffic + class JT808TrafficDefault : IJT808Traffic { private ConcurrentDictionary dict = new ConcurrentDictionary(); diff --git a/src/JT808.Gateway.Services/JT808.Gateway.Traffic/JT808TrafficServiceExtensions.cs b/src/JT808.Gateway.Services/JT808.Gateway.Traffic/JT808TrafficServiceExtensions.cs index 26cf199..7ea99b5 100644 --- a/src/JT808.Gateway.Services/JT808.Gateway.Traffic/JT808TrafficServiceExtensions.cs +++ b/src/JT808.Gateway.Services/JT808.Gateway.Traffic/JT808TrafficServiceExtensions.cs @@ -13,36 +13,48 @@ namespace JT808.Gateway.Traffic /// /// /// - public static IJT808ClientBuilder AddInPlugTraffic(this IJT808ClientBuilder jT808ClientBuilder) + public static IJT808ClientBuilder AddTraffic(this IJT808ClientBuilder jT808ClientBuilder) where TIJT808Traffic:IJT808Traffic { jT808ClientBuilder.JT808Builder.Services.AddSingleton(typeof(IJT808Traffic), typeof(TIJT808Traffic)); jT808ClientBuilder.JT808Builder.Services.AddHostedService(); return jT808ClientBuilder; } + /// - /// 消息流量统计服务(消费者单实例) + /// 消息流量统计服务(不同的消费者实例) /// - /// - /// + /// /// - public static IJT808GatewayBuilder AddInMemoryTraffic(this IJT808GatewayBuilder jT808GatewayBuilder) + public static IJT808ClientBuilder AddTraffic(this IJT808ClientBuilder jT808ClientBuilder) { - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(typeof(IJT808Traffic), typeof(JT808TrafficDefault)); - jT808GatewayBuilder.JT808Builder.Services.AddHostedService(); - return jT808GatewayBuilder; + jT808ClientBuilder.JT808Builder.Services.AddSingleton(typeof(IJT808Traffic), typeof(JT808TrafficDefault)); + jT808ClientBuilder.JT808Builder.Services.AddHostedService(); + return jT808ClientBuilder; } + /// - /// 消息流量统计服务(消费者单实例) + /// 消息流量统计服务(不同的消费者实例) + /// + /// + /// + public static IJT808NormalGatewayBuilder AddTraffic(this IJT808NormalGatewayBuilder jT808NormalGatewayBuilder) + where TIJT808Traffic : IJT808Traffic + { + jT808NormalGatewayBuilder.JT808Builder.Services.AddSingleton(typeof(IJT808Traffic), typeof(TIJT808Traffic)); + return jT808NormalGatewayBuilder; + } + + + /// + /// 消息流量统计服务(不同的消费者实例) /// - /// - /// + /// /// - public static IJT808GatewayBuilder AddInMemoryTraffic(this IJT808GatewayBuilder jT808GatewayBuilder) + public static IJT808NormalGatewayBuilder AddTraffic(this IJT808NormalGatewayBuilder jT808NormalGatewayBuilder) { - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(typeof(IJT808Traffic), typeof(TIJT808Traffic)); - jT808GatewayBuilder.JT808Builder.Services.AddHostedService(); - return jT808GatewayBuilder; + jT808NormalGatewayBuilder.JT808Builder.Services.AddSingleton(typeof(IJT808Traffic), typeof(JT808TrafficDefault)); + return jT808NormalGatewayBuilder; } } } diff --git a/src/JT808.Gateway.Services/JT808.Gateway.Traffic/JT808TrafficServiceInMemoryHostedService.cs b/src/JT808.Gateway.Services/JT808.Gateway.Traffic/JT808TrafficServiceInMemoryHostedService.cs deleted file mode 100644 index bc64a69..0000000 --- a/src/JT808.Gateway.Services/JT808.Gateway.Traffic/JT808TrafficServiceInMemoryHostedService.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System.Threading.Tasks; -using Microsoft.Extensions.Hosting; -using System.Threading; -using JT808.Protocol.Extensions; -using JT808.Gateway.Abstractions; -using JT808.Gateway.Abstractions.Enums; -using System; - -namespace JT808.Gateway.Traffic -{ - public class JT808TrafficServiceInMemoryHostedService : IHostedService - { - private readonly IJT808MsgConsumer jT808MsgConsumer; - private readonly IJT808Traffic jT808Traffic; - - public JT808TrafficServiceInMemoryHostedService( - IJT808Traffic jT808Traffic, - IJT808MsgConsumerFactory jT808MsgConsumerFactory) - { - this.jT808MsgConsumer = jT808MsgConsumerFactory.Create(JT808ConsumerType.TrafficConsumer); - this.jT808Traffic = jT808Traffic; - } - - public Task StartAsync(CancellationToken cancellationToken) - { - jT808MsgConsumer.Subscribe(); - jT808MsgConsumer.OnMessage((item)=> { - //string str = item.Data.ToHexString(); - jT808Traffic.Increment(item.TerminalNo, DateTime.Now.ToString("yyyyMMdd"), item.Data.Length); - }); - return Task.CompletedTask; - } - - public Task StopAsync(CancellationToken cancellationToken) - { - jT808MsgConsumer.Unsubscribe(); - return Task.CompletedTask; - } - } -} diff --git a/src/JT808.Gateway.Services/JT808.Gateway.Transmit/JT808TransmitExtensions.cs b/src/JT808.Gateway.Services/JT808.Gateway.Transmit/JT808TransmitExtensions.cs index 22507a8..f06c214 100644 --- a/src/JT808.Gateway.Services/JT808.Gateway.Transmit/JT808TransmitExtensions.cs +++ b/src/JT808.Gateway.Services/JT808.Gateway.Transmit/JT808TransmitExtensions.cs @@ -17,25 +17,25 @@ namespace JT808.Gateway.Transmit /// /// /// - public static IJT808ClientBuilder AddInPlugTransmit(this IJT808ClientBuilder jT808ClientBuilder,IConfiguration configuration) + public static IJT808ClientBuilder AddTransmit(this IJT808ClientBuilder jT808ClientBuilder,IConfiguration configuration) { jT808ClientBuilder.JT808Builder.Services.Configure(configuration.GetSection("RemoteServerOptions")); jT808ClientBuilder.JT808Builder.Services.AddSingleton(); jT808ClientBuilder.JT808Builder.Services.AddHostedService(); return jT808ClientBuilder; } + /// - /// 转发服务(消费者单实例) + /// 转发服务(不同的消费者实例) /// - /// + /// /// /// - public static IJT808GatewayBuilder AddInMemoryTransmit(this IJT808GatewayBuilder jT808GatewayBuilder, IConfiguration configuration) + public static IJT808NormalGatewayBuilder AddTransmit(this IJT808NormalGatewayBuilder jT808NormalGatewayBuilder, IConfiguration configuration) { - jT808GatewayBuilder.JT808Builder.Services.Configure(configuration.GetSection("RemoteServerOptions")); - jT808GatewayBuilder.JT808Builder.Services.AddSingleton(); - jT808GatewayBuilder.JT808Builder.Services.AddHostedService(); - return jT808GatewayBuilder; + jT808NormalGatewayBuilder.JT808Builder.Services.Configure(configuration.GetSection("RemoteServerOptions")); + jT808NormalGatewayBuilder.JT808Builder.Services.AddSingleton(); + return jT808NormalGatewayBuilder; } } } diff --git a/src/JT808.Gateway.Services/JT808.Gateway.Transmit/JT808TransmitInMemoryHostedService.cs b/src/JT808.Gateway.Services/JT808.Gateway.Transmit/JT808TransmitInMemoryHostedService.cs deleted file mode 100644 index 51547bb..0000000 --- a/src/JT808.Gateway.Services/JT808.Gateway.Transmit/JT808TransmitInMemoryHostedService.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System.Threading.Tasks; -using Microsoft.Extensions.Hosting; -using System.Threading; -using JT808.Gateway.Abstractions; -using JT808.Gateway.Abstractions.Enums; - -namespace JT808.Gateway.Transmit -{ - public class JT808TransmitInMemoryHostedService : IHostedService - { - private readonly JT808TransmitService jT808TransmitService; - private readonly IJT808MsgConsumer jT808MsgConsumer; - public JT808TransmitInMemoryHostedService( - IJT808MsgConsumerFactory jT808MsgConsumerFactory, - JT808TransmitService jT808TransmitService) - { - this.jT808TransmitService = jT808TransmitService; - this.jT808MsgConsumer = jT808MsgConsumerFactory.Create(JT808ConsumerType.TransmitConsumer); - } - - public Task StartAsync(CancellationToken cancellationToken) - { - jT808MsgConsumer.Subscribe(); - jT808MsgConsumer.OnMessage(jT808TransmitService.Send); - return Task.CompletedTask; - } - - public Task StopAsync(CancellationToken cancellationToken) - { - jT808MsgConsumer.Unsubscribe(); - return Task.CompletedTask; - } - } -} diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.InMemoryMQ.Test/JT808.Gateway.InMemoryMQ.Test.csproj b/src/JT808.Gateway.Tests/JT808.Gateway.InMemoryMQ.Test/JT808.Gateway.InMemoryMQ.Test.csproj deleted file mode 100644 index 2d4b6b2..0000000 --- a/src/JT808.Gateway.Tests/JT808.Gateway.InMemoryMQ.Test/JT808.Gateway.InMemoryMQ.Test.csproj +++ /dev/null @@ -1,23 +0,0 @@ - - - - netcoreapp3.1 - - false - - - - - - - - - - - - - - - - - diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.InMemoryMQ.Test/JT808MsgProducerTest.cs b/src/JT808.Gateway.Tests/JT808.Gateway.InMemoryMQ.Test/JT808MsgProducerTest.cs deleted file mode 100644 index 549b37f..0000000 --- a/src/JT808.Gateway.Tests/JT808.Gateway.InMemoryMQ.Test/JT808MsgProducerTest.cs +++ /dev/null @@ -1,124 +0,0 @@ -using JT808.Gateway.Abstractions; -using JT808.Gateway.Abstractions.Enums; -using JT808.Gateway.Internal; -using JT808.Protocol; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Text; -using Xunit; - -namespace JT808.Gateway.InMemoryMQ.Test -{ - public class JT808MsgProducerTest - { - [Fact] - public void Test1() - { - IServiceCollection serviceDescriptors = new ServiceCollection(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(typeof(ILogger<>), typeof(Logger<>)); - serviceDescriptors.AddServerInMemoryMQ(JT808ConsumerType.MsgIdHandlerConsumer | JT808ConsumerType.ReplyMessageConsumer); - IServiceProvider serviceProvider = serviceDescriptors.BuildServiceProvider(); - IJT808MsgProducer producer = serviceProvider.GetRequiredService(); - producer.ProduceAsync("123", new byte[] { 1, 2, 3, 4 }); - IJT808MsgConsumer consumer = serviceProvider.GetRequiredService(); - consumer.OnMessage((item) => { - Assert.Equal("123", item.TerminalNo); - Assert.Equal(new byte[] { 1, 2, 3, 4 }, item.Data); - }); - IJT808MsgConsumerFactory consumerFactory = serviceProvider.GetRequiredService(); - var msgIdHandlerConsumer = consumerFactory.Create(JT808ConsumerType.MsgIdHandlerConsumer); - msgIdHandlerConsumer.OnMessage((item) => - { - Assert.Equal("123", item.TerminalNo); - Assert.Equal(new byte[] { 1, 2, 3, 4 }, item.Data); - }); - var replyMessageConsumer = consumerFactory.Create(JT808ConsumerType.ReplyMessageConsumer); - replyMessageConsumer.OnMessage((item) => - { - Assert.Equal("123", item.TerminalNo); - Assert.Equal(new byte[] { 1, 2, 3, 4 }, item.Data); - }); - } - - [Fact] - public void Test2() - { - IServiceCollection serviceDescriptors = new ServiceCollection(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(typeof(ILogger<>), typeof(Logger<>)); - serviceDescriptors.AddServerInMemoryMQ(JT808ConsumerType.MsgIdHandlerConsumer,JT808ConsumerType.ReplyMessageConsumer); - IServiceProvider serviceProvider = serviceDescriptors.BuildServiceProvider(); - IJT808MsgProducer producer = serviceProvider.GetRequiredService(); - producer.ProduceAsync("123", new byte[] { 1, 2, 3, 4 }); - IJT808MsgConsumer consumer = serviceProvider.GetRequiredService(); - consumer.OnMessage((item) => { - Assert.Equal("123", item.TerminalNo); - Assert.Equal(new byte[] { 1, 2, 3, 4 }, item.Data); - }); - IJT808MsgConsumerFactory consumerFactory = serviceProvider.GetRequiredService(); - var msgIdHandlerConsumer = consumerFactory.Create(JT808ConsumerType.MsgIdHandlerConsumer); - msgIdHandlerConsumer.OnMessage((item) => - { - Assert.Equal("123", item.TerminalNo); - Assert.Equal(new byte[] { 1, 2, 3, 4 }, item.Data); - }); - var replyMessageConsumer = consumerFactory.Create(JT808ConsumerType.ReplyMessageConsumer); - replyMessageConsumer.OnMessage((item) => - { - Assert.Equal("123", item.TerminalNo); - Assert.Equal(new byte[] { 1, 2, 3, 4 }, item.Data); - }); - } - - [Fact] - public void Test3() - { - IServiceCollection serviceDescriptors = new ServiceCollection(); - serviceDescriptors.AddSingleton(); - serviceDescriptors.AddSingleton(typeof(ILogger<>), typeof(Logger<>)); - serviceDescriptors.AddServerInMemoryMQ(JT808ConsumerType.All); - IServiceProvider serviceProvider = serviceDescriptors.BuildServiceProvider(); - IJT808MsgProducer producer = serviceProvider.GetRequiredService(); - producer.ProduceAsync("123", new byte[] { 1, 2, 3, 4 }); - IJT808MsgConsumer consumer = serviceProvider.GetRequiredService(); - consumer.OnMessage((item) => { - Assert.Equal("123", item.TerminalNo); - Assert.Equal(new byte[] { 1, 2, 3, 4 }, item.Data); - }); - IJT808MsgConsumerFactory consumerFactory = serviceProvider.GetRequiredService(); - var msgIdHandlerConsumer = consumerFactory.Create(JT808ConsumerType.MsgIdHandlerConsumer); - msgIdHandlerConsumer.OnMessage((item) => - { - Assert.Equal("123", item.TerminalNo); - Assert.Equal(new byte[] { 1, 2, 3, 4 }, item.Data); - }); - var replyMessageConsumer = consumerFactory.Create(JT808ConsumerType.ReplyMessageConsumer); - replyMessageConsumer.OnMessage((item) => - { - Assert.Equal("123", item.TerminalNo); - Assert.Equal(new byte[] { 1, 2, 3, 4 }, item.Data); - }); - var msgLoggingConsumer = consumerFactory.Create(JT808ConsumerType.MsgLoggingConsumer); - msgLoggingConsumer.OnMessage((item) => - { - Assert.Equal("123", item.TerminalNo); - Assert.Equal(new byte[] { 1, 2, 3, 4 }, item.Data); - }); - var trafficConsumer = consumerFactory.Create(JT808ConsumerType.TrafficConsumer); - trafficConsumer.OnMessage((item) => - { - Assert.Equal("123", item.TerminalNo); - Assert.Equal(new byte[] { 1, 2, 3, 4 }, item.Data); - }); - var transmitConsumer = consumerFactory.Create(JT808ConsumerType.TransmitConsumer); - transmitConsumer.OnMessage((item) => - { - Assert.Equal("123", item.TerminalNo); - Assert.Equal(new byte[] { 1, 2, 3, 4 }, item.Data); - }); - } - } -} diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.InMemoryMQ.Test/Services/JT808MsgServiceTest.cs b/src/JT808.Gateway.Tests/JT808.Gateway.InMemoryMQ.Test/Services/JT808MsgServiceTest.cs deleted file mode 100644 index 84bd004..0000000 --- a/src/JT808.Gateway.Tests/JT808.Gateway.InMemoryMQ.Test/Services/JT808MsgServiceTest.cs +++ /dev/null @@ -1,22 +0,0 @@ -using JT808.Gateway.InMemoryMQ.Services; -using System; -using System.Collections.Concurrent; -using System.Threading; -using System.Threading.Tasks; -using Xunit; - -namespace JT808.Gateway.InMemoryMQ.Test.Services -{ - public class JT808MsgServiceTest - { - [Fact] - public void Test1() - { - JT808MsgService jT808MsgService = new JT808MsgService(); - jT808MsgService.WriteAsync("132", new byte[] { 1, 2, 3 }).GetAwaiter().GetResult(); - var result = jT808MsgService.ReadAsync(CancellationToken.None).GetAwaiter().GetResult(); - Assert.Equal("132", result.TerminalNo); - Assert.Equal(new byte[] { 1, 2, 3 }, result.Data); - } - } -} diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.InMemoryMQ.Test/Services/JT808SessionServiceTest.cs b/src/JT808.Gateway.Tests/JT808.Gateway.InMemoryMQ.Test/Services/JT808SessionServiceTest.cs deleted file mode 100644 index 3381c0e..0000000 --- a/src/JT808.Gateway.Tests/JT808.Gateway.InMemoryMQ.Test/Services/JT808SessionServiceTest.cs +++ /dev/null @@ -1,32 +0,0 @@ -using JT808.Gateway.Abstractions; -using JT808.Gateway.InMemoryMQ.Services; -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading; -using Xunit; - -namespace JT808.Gateway.InMemoryMQ.Test.Services -{ - public class JT808SessionServiceTest - { - [Fact] - public void Test1() - { - JT808SessionService jT808SessionService = new JT808SessionService(); - jT808SessionService.WriteAsync(JT808GatewayConstants.SessionOnline, "123456").GetAwaiter().GetResult(); - jT808SessionService.WriteAsync(JT808GatewayConstants.SessionOffline, "123457").GetAwaiter().GetResult(); - jT808SessionService.WriteAsync(JT808GatewayConstants.SessionOnline, "123456,123457").GetAwaiter().GetResult(); - var result1 = jT808SessionService.ReadAsync(CancellationToken.None).GetAwaiter().GetResult(); - var result2 = jT808SessionService.ReadAsync(CancellationToken.None).GetAwaiter().GetResult(); - var result3 = jT808SessionService.ReadAsync(CancellationToken.None).GetAwaiter().GetResult(); - Assert.Equal(JT808GatewayConstants.SessionOnline, result1.Notice); - Assert.Equal("123456", result1.TerminalNo); - Assert.Equal(JT808GatewayConstants.SessionOffline, result2.Notice); - Assert.Equal("123457", result2.TerminalNo); - //转发 - Assert.Equal(JT808GatewayConstants.SessionOnline, result3.Notice); - Assert.Equal("123456,123457", result3.TerminalNo); - } - } -} diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Configs/NLog.xsd b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Configs/NLog.xsd new file mode 100644 index 0000000..2f57d09 --- /dev/null +++ b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Configs/NLog.xsd @@ -0,0 +1,3106 @@ + + + + + + + + + + + + + + + Watch config file for changes and reload automatically. + + + + + Print internal NLog messages to the console. Default value is: false + + + + + Print internal NLog messages to the console error output. Default value is: false + + + + + Write internal NLog messages to the specified file. + + + + + Log level threshold for internal log messages. Default value is: Info. + + + + + Global log level threshold for application log messages. Messages below this level won't be logged.. + + + + + Throw an exception when there is an internal error. Default value is: false. + + + + + Throw an exception when there is a configuration error. If not set, determined by throwExceptions. + + + + + Gets or sets a value indicating whether Variables should be kept on configuration reload. Default value is: false. + + + + + Write internal NLog messages to the System.Diagnostics.Trace. Default value is: false. + + + + + Write timestamps for internal NLog messages. Default value is: true. + + + + + Use InvariantCulture as default culture instead of CurrentCulture. Default value is: false. + + + + + Perform mesage template parsing and formatting of LogEvent messages (true = Always, false = Never, empty = Auto Detect). Default value is: empty. + + + + + + + + + + + + + + Make all targets within this section asynchronous (creates additional threads but the calling thread isn't blocked by any target writes). + + + + + + + + + + + + + + + + + Prefix for targets/layout renderers/filters/conditions loaded from this assembly. + + + + + Load NLog extensions from the specified file (*.dll) + + + + + Load NLog extensions from the specified assembly. Assembly name should be fully qualified. + + + + + + + + + + Name of the logger. May include '*' character which acts like a wildcard. Allowed forms are: *, Name, *Name, Name* and *Name* + + + + + Comma separated list of levels that this rule matches. + + + + + Minimum level that this rule matches. + + + + + Maximum level that this rule matches. + + + + + Level that this rule matches. + + + + + Comma separated list of target names. + + + + + Ignore further rules if this one matches. + + + + + Enable or disable logging rule. Disabled rules are ignored. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the file to be included. You could use * wildcard. The name is relative to the name of the current config file. + + + + + Ignore any errors in the include file. + + + + + + + Variable name. + + + + + Variable value. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Number of log events that should be processed in a batch by the lazy writer thread. + + + + + Limit of full s to write before yielding into Performance is better when writing many small batches, than writing a single large batch + + + + + Action to be taken when the lazy writer thread request queue count exceeds the set limit. + + + + + Limit on the number of requests in the lazy writer thread request queue. + + + + + Time in milliseconds to sleep between batches. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Delay the flush until the LogEvent has been confirmed as written + + + + + Condition expression. Log events who meet this condition will cause a flush on the wrapped target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Number of log events to be buffered. + + + + + Timeout (in milliseconds) after which the contents of buffer will be flushed if there's no write in the specified period of time. Use -1 to disable timed flushes. + + + + + Indicates whether to use sliding timeout. + + + + + Action to take if the buffer overflows. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Encoding to be used. + + + + + Instance of that is used to format log messages. + + + + + End of line value if a newline is appended at the end of log message . + + + + + Maximum message size in bytes. + + + + + Indicates whether to append newline at the end of log message. + + + + + Action that should be taken if the will be more connections than . + + + + + Action that should be taken if the message is larger than maxMessageSize. + + + + + Maximum current connections. 0 = no maximum. + + + + + Indicates whether to keep connection open whenever possible. + + + + + Size of the connection cache (number of connections which are kept alive). + + + + + Network address. + + + + + Maximum queue size. + + + + + NDC item separator. + + + + + Indicates whether to include source info (file name and line number) in the information sent over the network. + + + + + Indicates whether to include dictionary contents. + + + + + Indicates whether to include contents of the stack. + + + + + Indicates whether to include stack contents. + + + + + Indicates whether to include dictionary contents. + + + + + Indicates whether to include call site (class and method name) in the information sent over the network. + + + + + Option to include all properties from the log events + + + + + AppInfo field. By default it's the friendly name of the current AppDomain. + + + + + Indicates whether to include NLog-specific extensions to log4j schema. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + Layout that should be use to calcuate the value for the parameter. + + + + + Viewer parameter name. + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + Indicates whether to use default row highlighting rules. + + + + + Indicates whether to auto-check if the console is available. - Disables console writing if Environment.UserInteractive = False (Windows Service) - Disables console writing if Console Standard Input is not available (Non-Console-App) + + + + + The encoding for writing messages to the . + + + + + Indicates whether the error stream (stderr) should be used instead of the output stream (stdout). + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Condition that must be met in order to set the specified foreground and background color. + + + + + Background color. + + + + + Foreground color. + + + + + + + + + + + + + + + + Indicates whether to ignore case when comparing texts. + + + + + Regular expression to be matched. You must specify either text or regex. + + + + + Text to be matched. You must specify either text or regex. + + + + + Indicates whether to match whole words only. + + + + + Compile the ? This can improve the performance, but at the costs of more memory usage. If false, the Regex Cache is used. + + + + + Background color. + + + + + Foreground color. + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + Indicates whether to send the log messages to the standard error instead of the standard output. + + + + + Indicates whether to auto-check if the console is available - Disables console writing if Environment.UserInteractive = False (Windows Service) - Disables console writing if Console Standard Input is not available (Non-Console-App) + + + + + The encoding for writing messages to the . + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Obsolete - value will be ignored! The logging code always runs outside of transaction. Gets or sets a value indicating whether to use database transactions. Some data providers require this. + + + + + Database user name. If the ConnectionString is not provided this value will be used to construct the "User ID=" part of the connection string. + + + + + Name of the database provider. + + + + + Database password. If the ConnectionString is not provided this value will be used to construct the "Password=" part of the connection string. + + + + + Indicates whether to keep the database connection open between the log events. + + + + + Database name. If the ConnectionString is not provided this value will be used to construct the "Database=" part of the connection string. + + + + + Name of the connection string (as specified in <connectionStrings> configuration section. + + + + + Connection string. When provided, it overrides the values specified in DBHost, DBUserName, DBPassword, DBDatabase. + + + + + Database host name. If the ConnectionString is not provided this value will be used to construct the "Server=" part of the connection string. + + + + + Connection string using for installation and uninstallation. If not provided, regular ConnectionString is being used. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + Text of the SQL command to be run on each log level. + + + + + Type of the SQL command to be run on each log level. + + + + + + + + + + + + + + + + + + + + + + + Type of the command. + + + + + Connection string to run the command against. If not provided, connection string from the target is used. + + + + + Indicates whether to ignore failures. + + + + + Command text. + + + + + + + + + + + + + + Layout that should be use to calcuate the value for the parameter. + + + + + Database parameter name. + + + + + Database parameter precision. + + + + + Database parameter scale. + + + + + Database parameter size. + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Layout that renders event Category. + + + + + Layout that renders event ID. + + + + + Name of the Event Log to write to. This can be System, Application or any user-defined name. + + + + + Name of the machine on which Event Log service is running. + + + + + Value to be used as the event Source. + + + + + Action to take if the message is larger than the option. + + + + + Optional entrytype. When not set, or when not convertable to then determined by + + + + + Maximum Event log size in kilobytes. If null, the value won't be set. Default is 512 Kilobytes as specified by Eventlog API + + + + + Message length limit to write to the Event Log. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Indicates whether to return to the first target after any successful write. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + File encoding. + + + + + Line ending mode. + + + + + Way file archives are numbered. + + + + + Name of the file to be used for an archive. + + + + + Indicates whether to automatically archive log files every time the specified time passes. + + + + + Size in bytes above which log files will be automatically archived. Warning: combining this with isn't supported. We cannot create multiple archive files, if they should have the same name. Choose: + + + + + Indicates whether to compress archive files into the zip archive format. + + + + + Maximum number of archive files that should be kept. + + + + + Gets or set a value indicating whether a managed file stream is forced, instead of using the native implementation. + + + + + Is the an absolute or relative path? + + + + + Cleanup invalid values in a filename, e.g. slashes in a filename. If set to true, this can impact the performance of massive writes. If set to false, nothing gets written when the filename is wrong. + + + + + Whether or not this target should just discard all data that its asked to write. Mostly used for when testing NLog Stack except final write + + + + + Is the an absolute or relative path? + + + + + Value indicationg whether file creation calls should be synchronized by a system global mutex. + + + + + Maximum number of log filenames that should be stored as existing. + + + + + Indicates whether the footer should be written only when the file is archived. + + + + + Name of the file to write to. + + + + + Value specifying the date format to use when archiving files. + + + + + Indicates whether to archive old log file on startup. + + + + + Indicates whether to create directories if they do not exist. + + + + + File attributes (Windows only). + + + + + Indicates whether to delete old log file on startup. + + + + + Indicates whether to replace file contents on each write instead of appending log message at the end. + + + + + Indicates whether to enable log file(s) to be deleted. + + + + + Number of times the write is appended on the file before NLog discards the log message. + + + + + Indicates whether concurrent writes to the log file by multiple processes on the same host. + + + + + Indicates whether to keep log file open instead of opening and closing it on each logging event. + + + + + Indicates whether concurrent writes to the log file by multiple processes on different network hosts. + + + + + Number of files to be kept open. Setting this to a higher value may improve performance in a situation where a single File target is writing to many files (such as splitting by level or by logger). + + + + + Maximum number of seconds that files are kept open. If this number is negative the files are not automatically closed after a period of inactivity. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + Log file buffer size in bytes. + + + + + Indicates whether to automatically flush the file buffers after each log message. + + + + + Delay in milliseconds to wait before attempting to write to the file again. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Condition expression. Log events who meet this condition will be forwarded to the wrapped target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Windows domain name to change context to. + + + + + Required impersonation level. + + + + + Type of the logon provider. + + + + + Logon Type. + + + + + User account password. + + + + + Indicates whether to revert to the credentials of the process instead of impersonating another user. + + + + + Username to change context to. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Interval in which messages will be written up to the number of messages. + + + + + Maximum allowed number of messages written per . + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Endpoint address. + + + + + Name of the endpoint configuration in WCF configuration file. + + + + + Indicates whether to use a WCF service contract that is one way (fire and forget) or two way (request-reply) + + + + + Client ID. + + + + + Indicates whether to include per-event properties in the payload sent to the server. + + + + + Indicates whether to use binary message encoding. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + Layout that should be use to calculate the value for the parameter. + + + + + Name of the parameter. + + + + + Type of the parameter. + + + + + Type of the parameter. Obsolete alias for + + + + + Parameter can combine multiple LogEvents into a single parameter value + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + Indicates whether to send message as HTML instead of plain text. + + + + + Encoding to be used for sending e-mail. + + + + + Indicates whether to add new lines between log entries. + + + + + CC email addresses separated by semicolons (e.g. john@domain.com;jane@domain.com). + + + + + Recipients' email addresses separated by semicolons (e.g. john@domain.com;jane@domain.com). + + + + + BCC email addresses separated by semicolons (e.g. john@domain.com;jane@domain.com). + + + + + Mail message body (repeated for each log message send in one mail). + + + + + Mail subject. + + + + + Sender's email address (e.g. joe@domain.com). + + + + + Indicates the SMTP client timeout. + + + + + Priority used for sending mails. + + + + + Indicates whether NewLine characters in the body should be replaced with tags. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + SMTP Server to be used for sending. + + + + + SMTP Authentication mode. + + + + + Username used to connect to SMTP server (used when SmtpAuthentication is set to "basic"). + + + + + Password used to authenticate against SMTP server (used when SmtpAuthentication is set to "basic"). + + + + + Indicates whether SSL (secure sockets layer) should be used when communicating with SMTP server. + + + + + Port number that SMTP Server is listening on. + + + + + Indicates whether the default Settings from System.Net.MailSettings should be used. + + + + + Folder where applications save mail messages to be processed by the local SMTP server. + + + + + Specifies how outgoing email messages will be handled. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Class name. + + + + + Method name. The method must be public and static. Use the AssemblyQualifiedName , https://msdn.microsoft.com/en-us/library/system.type.assemblyqualifiedname(v=vs.110).aspx e.g. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Encoding to be used. + + + + + End of line value if a newline is appended at the end of log message . + + + + + Maximum message size in bytes. + + + + + Indicates whether to append newline at the end of log message. + + + + + Action that should be taken if the will be more connections than . + + + + + Action that should be taken if the message is larger than maxMessageSize. + + + + + Network address. + + + + + Size of the connection cache (number of connections which are kept alive). + + + + + Indicates whether to keep connection open whenever possible. + + + + + Maximum current connections. 0 = no maximum. + + + + + Maximum queue size. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Encoding to be used. + + + + + Instance of that is used to format log messages. + + + + + End of line value if a newline is appended at the end of log message . + + + + + Maximum message size in bytes. + + + + + Indicates whether to append newline at the end of log message. + + + + + Action that should be taken if the will be more connections than . + + + + + Action that should be taken if the message is larger than maxMessageSize. + + + + + Maximum current connections. 0 = no maximum. + + + + + Indicates whether to keep connection open whenever possible. + + + + + Size of the connection cache (number of connections which are kept alive). + + + + + Network address. + + + + + Maximum queue size. + + + + + NDC item separator. + + + + + Indicates whether to include source info (file name and line number) in the information sent over the network. + + + + + Indicates whether to include dictionary contents. + + + + + Indicates whether to include contents of the stack. + + + + + Indicates whether to include stack contents. + + + + + Indicates whether to include dictionary contents. + + + + + Indicates whether to include call site (class and method name) in the information sent over the network. + + + + + Option to include all properties from the log events + + + + + AppInfo field. By default it's the friendly name of the current AppDomain. + + + + + Indicates whether to include NLog-specific extensions to log4j schema. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Indicates whether to perform layout calculation. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Indicates whether performance counter should be automatically created. + + + + + Name of the performance counter category. + + + + + Counter help text. + + + + + Name of the performance counter. + + + + + Performance counter type. + + + + + The value by which to increment the counter. + + + + + Performance counter instance name. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Default filter to be applied when no specific rule matches. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + Condition to be tested. + + + + + Resulting filter to be applied when the condition matches. + + + + + + + + + + + + + Name of the target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + Name of the target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + Number of times to repeat each log message. + + + + + + + + + + + + + + + + + Name of the target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + Number of retries that should be attempted on the wrapped target in case of a failure. + + + + + Time to wait between retries in milliseconds. + + + + + + + + + + + + + + + Name of the target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + Name of the target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Always use independent of + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Should we include the BOM (Byte-order-mark) for UTF? Influences the property. This will only work for UTF-8. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + Encoding. + + + + + Value whether escaping be done according to the old NLog style (Very non-standard) + + + + + Value whether escaping be done according to Rfc3986 (Supports Internationalized Resource Identifiers - IRIs) + + + + + Web service method name. Only used with Soap. + + + + + Web service namespace. Only used with Soap. + + + + + Indicates whether to pre-authenticate the HttpWebRequest (Requires 'Authorization' in parameters) + + + + + Protocol to be used when calling web service. + + + + + Web service URL. + + + + + Name of the root XML element, if POST of XML document chosen. If so, this property must not be null. (see and ). + + + + + (optional) root namespace of the XML document, if POST of XML document chosen. (see and ). + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Footer layout. + + + + + Header layout. + + + + + Body layout (can be repeated multiple times). + + + + + Custom column delimiter value (valid when ColumnDelimiter is set to 'Custom'). + + + + + Column delimiter. + + + + + Quote Character. + + + + + Quoting mode. + + + + + Indicates whether CVS should include header. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Layout of the column. + + + + + Name of the column. + + + + + + + + + + + + + + + + + + List of property names to exclude when is true + + + + + Option to include all properties from the log events + + + + + Indicates whether to include contents of the dictionary. + + + + + Indicates whether to include contents of the dictionary. + + + + + Option to render the empty object value {} + + + + + Option to suppress the extra spaces in the output json + + + + + + + + + + + + + + + Determines wether or not this attribute will be Json encoded. + + + + + Indicates whether to escape non-ascii characters + + + + + Layout that will be rendered as the attribute's value. + + + + + Name of the attribute. + + + + + + + + + + + + + + Footer layout. + + + + + Header layout. + + + + + Body layout (can be repeated multiple times). + + + + + + + + + + + + + + + + + + Option to include all properties from the log events + + + + + Indicates whether to include contents of the dictionary. + + + + + Indicates whether to include contents of the dictionary. + + + + + Indicates whether to include contents of the stack. + + + + + Indicates whether to include contents of the stack. + + + + + + + + + + + + + + Layout text. + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + Condition expression. + + + + + + + + + + + + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + Indicates whether to ignore case when comparing strings. + + + + + Layout to be used to filter log messages. + + + + + Substring to be matched. + + + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + String to compare the layout to. + + + + + Indicates whether to ignore case when comparing strings. + + + + + Layout to be used to filter log messages. + + + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + Indicates whether to ignore case when comparing strings. + + + + + Layout to be used to filter log messages. + + + + + Substring to be matched. + + + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + String to compare the layout to. + + + + + Indicates whether to ignore case when comparing strings. + + + + + Layout to be used to filter log messages. + + + + + + + + + + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + Layout to be used to filter log messages. + + + + + Default number of unique filter values to expect, will automatically increase if needed + + + + + Append FilterCount to the when an event is no longer filtered + + + + + Insert FilterCount value into when an event is no longer filtered + + + + + Applies the configured action to the initial logevent that starts the timeout period. Used to configure that it should ignore all events until timeout. + + + + + Max number of unique filter values to expect simultaneously + + + + + Max length of filter values, will truncate if above limit + + + + + Default buffer size for the internal buffers + + + + + Reuse internal buffers, and doesn't have to constantly allocate new buffers + + + + + How long before a filter expires, and logging is accepted again + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Configs/nlog.Unix.config b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Configs/nlog.Unix.config new file mode 100644 index 0000000..95469d6 --- /dev/null +++ b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Configs/nlog.Unix.config @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Configs/nlog.Win32NT.config b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Configs/nlog.Win32NT.config new file mode 100644 index 0000000..a4e9705 --- /dev/null +++ b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Configs/nlog.Win32NT.config @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/Impl/JT808MsgLogging.cs b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Impl/JT808MsgLogging.cs similarity index 94% rename from src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/Impl/JT808MsgLogging.cs rename to src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Impl/JT808MsgLogging.cs index 77c378e..95f2a87 100644 --- a/src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/Impl/JT808MsgLogging.cs +++ b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Impl/JT808MsgLogging.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; using System.Text; -namespace JT808.Gateway.TestHosting.Impl +namespace JT808.Gateway.NormalHosting.Impl { public class JT808MsgLogging : IJT808MsgLogging { diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Impl/JT808NormalReplyMessageHandlerImpl.cs b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Impl/JT808NormalReplyMessageHandlerImpl.cs new file mode 100644 index 0000000..3dd9216 --- /dev/null +++ b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Impl/JT808NormalReplyMessageHandlerImpl.cs @@ -0,0 +1,79 @@ +using JT808.Gateway.Abstractions; +using JT808.Gateway.MsgLogging; +using JT808.Gateway.Traffic; +using JT808.Gateway.Transmit; +using JT808.Protocol; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT808.Gateway.NormalHosting.Impl +{ + public class JT808NormalReplyMessageHandlerImpl : JT808NormalReplyMessageHandler + { + private readonly ILogger logger; + private readonly IJT808Traffic jT808Traffic; + private readonly IJT808MsgLogging jT808MsgLogging; + private readonly JT808TransmitService jT808TransmitService; + public JT808NormalReplyMessageHandlerImpl( + JT808TransmitService jT808TransmitService, + IJT808MsgLogging jT808MsgLogging, + IJT808Traffic jT808Traffic, + ILoggerFactory loggerFactory, + IJT808Config jT808Config) : base(jT808Config) + { + this.jT808TransmitService = jT808TransmitService; + this.jT808Traffic = jT808Traffic; + this.jT808MsgLogging = jT808MsgLogging; + logger =loggerFactory.CreateLogger("JT808NormalReplyMessageHandlerImpl"); + //添加自定义消息 + HandlerDict.Add(0x9999, Msg0x9999); + } + + /// + /// 重写消息处理器 + /// + /// + /// + public override byte[] Processor(JT808HeaderPackage request, IJT808Session session) + { + //AOP 可以自定义添加一些东西:上下行日志、数据转发 + logger.LogDebug("可以自定义添加一些东西:上下行日志、数据转发"); + //流量 + jT808Traffic.Increment(request.Header.TerminalPhoneNo, DateTime.Now.ToString("yyyyMMdd"), request.OriginalData.Length); + var parameter = (request.Header.TerminalPhoneNo, request.OriginalData.ToArray()); + //转发数据(可同步也可以使用队列进行异步) + jT808TransmitService.Send(parameter); + //上行日志(可同步也可以使用队列进行异步) + jT808MsgLogging.Processor(parameter, JT808MsgLoggingType.up); + //处理上行消息 + var down= base.Processor(request, session); + //下行日志(可同步也可以使用队列进行异步) + jT808MsgLogging.Processor((request.Header.TerminalPhoneNo, down), JT808MsgLoggingType.down); + return down; + } + + /// + /// 重写自带的消息 + /// + /// + /// + public override byte[] Msg0x0200(JT808HeaderPackage request, IJT808Session session) + { + logger.LogDebug("重写自带Msg0x0200的消息"); + return base.Msg0x0200(request, session); + } + + /// + /// 自定义消息 + /// + /// + /// + public byte[] Msg0x9999(JT808HeaderPackage request, IJT808Session session) + { + logger.LogDebug("自定义消息"); + return default; + } + } +} diff --git a/src/JT808.Gateway.InMemoryMQ/JT808SessionConsumer.cs b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Impl/JT808SessionConsumer.cs similarity index 94% rename from src/JT808.Gateway.InMemoryMQ/JT808SessionConsumer.cs rename to src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Impl/JT808SessionConsumer.cs index 13719fa..b26ce6f 100644 --- a/src/JT808.Gateway.InMemoryMQ/JT808SessionConsumer.cs +++ b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Impl/JT808SessionConsumer.cs @@ -5,9 +5,9 @@ using System.Collections.Generic; using System.Text; using System.Threading; using System.Threading.Tasks; -using JT808.Gateway.InMemoryMQ.Services; +using JT808.Gateway.NormalHosting.Services; -namespace JT808.Gateway.InMemoryMQ +namespace JT808.Gateway.NormalHosting.Impl { public class JT808SessionConsumer : IJT808SessionConsumer { diff --git a/src/JT808.Gateway.InMemoryMQ/JT808SessionProducer.cs b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Impl/JT808SessionProducer.cs similarity index 89% rename from src/JT808.Gateway.InMemoryMQ/JT808SessionProducer.cs rename to src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Impl/JT808SessionProducer.cs index 58c4f0b..23c1e5b 100644 --- a/src/JT808.Gateway.InMemoryMQ/JT808SessionProducer.cs +++ b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Impl/JT808SessionProducer.cs @@ -1,11 +1,11 @@ using JT808.Gateway.Abstractions; -using JT808.Gateway.InMemoryMQ.Services; +using JT808.Gateway.NormalHosting.Services; using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; -namespace JT808.Gateway.InMemoryMQ +namespace JT808.Gateway.NormalHosting.Impl { public class JT808SessionProducer : IJT808SessionProducer { diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/JT808.Gateway.NormalHosting.csproj b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/JT808.Gateway.NormalHosting.csproj new file mode 100644 index 0000000..c1ac1e8 --- /dev/null +++ b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/JT808.Gateway.NormalHosting.csproj @@ -0,0 +1,40 @@ + + + + Exe + netcoreapp3.1 + + + + + + + + + + + + + + + + + + + + + + Always + + + Always + + + Always + + + Always + + + + diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Jobs/CallGrpcClientJob.cs b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Jobs/CallGrpcClientJob.cs new file mode 100644 index 0000000..7a4810c --- /dev/null +++ b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Jobs/CallGrpcClientJob.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Grpc.Core; +using JT808.Gateway.Configurations; +using JT808.Gateway.GrpcService; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using System.Text.Json; + +namespace JT808.Gateway.NormalHosting.Jobs +{ + public class CallGrpcClientJob :IHostedService + { + private Channel channel; + private readonly ILogger Logger; + private Grpc.Core.Metadata AuthMetadata; + public CallGrpcClientJob( + ILoggerFactory loggerFactory, + JT808Configuration configuration) + { + Logger = loggerFactory.CreateLogger("CallGrpcClientJob"); + channel = new Channel($"{configuration.WebApiHost}:{configuration.WebApiPort}", + ChannelCredentials.Insecure); + AuthMetadata = new Grpc.Core.Metadata(); + AuthMetadata.Add("token", configuration.WebApiToken); + } + + public Task StartAsync(CancellationToken cancellationToken) + { + Task.Run(() => + { + while (!cancellationToken.IsCancellationRequested) + { + JT808Gateway.JT808GatewayClient jT808GatewayClient = new JT808Gateway.JT808GatewayClient(channel); + try + { + var result1 = jT808GatewayClient.GetTcpAtomicCounter(new Empty(), AuthMetadata); + var result2 = jT808GatewayClient.GetTcpSessionAll(new Empty(), AuthMetadata); + Logger.LogInformation($"[GetTcpAtomicCounter]:{JsonSerializer.Serialize(result1)}"); + Logger.LogInformation($"[GetTcpSessionAll]:{JsonSerializer.Serialize(result2)}"); + } + catch (Exception ex) + { + Logger.LogError(ex, "Call Grpc Error"); + } + try + { + var result1 = jT808GatewayClient.GetTcpAtomicCounter(new Empty()); + } + catch (RpcException ex) + { + Logger.LogError($"{ex.StatusCode.ToString()}-{ex.Message}"); + } + Thread.Sleep(3000); + } + }, cancellationToken); + return Task.CompletedTask; + } + + public Task StopAsync(CancellationToken cancellationToken) + { + channel.ShutdownAsync(); + return Task.CompletedTask; + } + } +} diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/Jobs/TrafficJob.cs b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Jobs/TrafficJob.cs similarity index 93% rename from src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/Jobs/TrafficJob.cs rename to src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Jobs/TrafficJob.cs index 5e1ee64..084cd87 100644 --- a/src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/Jobs/TrafficJob.cs +++ b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Jobs/TrafficJob.cs @@ -1,5 +1,4 @@ -using JT808.Gateway.Client; -using JT808.Gateway.Traffic; +using JT808.Gateway.Traffic; using JT808.Protocol.Enums; using JT808.Protocol.Extensions; using JT808.Protocol.MessageBody; @@ -11,7 +10,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; -namespace JT808.Gateway.TestHosting.Jobs +namespace JT808.Gateway.NormalHosting.Jobs { public class TrafficJob : IHostedService { diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Jobs/UpJob.cs b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Jobs/UpJob.cs new file mode 100644 index 0000000..eadef50 --- /dev/null +++ b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Jobs/UpJob.cs @@ -0,0 +1,70 @@ +using JT808.Gateway.Client; +using JT808.Protocol.Enums; +using JT808.Protocol.Extensions; +using JT808.Protocol.MessageBody; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace JT808.Gateway.NormalHosting.Jobs +{ + public class UpJob : IHostedService + { + private readonly IJT808TcpClientFactory jT808TcpClientFactory; + private readonly ILogger Logger; + public UpJob( + ILoggerFactory loggerFactory, + IJT808TcpClientFactory jT808TcpClientFactory) + { + Logger = loggerFactory.CreateLogger("UpJob"); + this.jT808TcpClientFactory = jT808TcpClientFactory; + } + + public Task StartAsync(CancellationToken cancellationToken) + { + Task.Run(async () => + { + await Task.Delay(2 * 1000); + var client = await jT808TcpClientFactory.Create(new JT808DeviceConfig("1234567890", "127.0.0.1", 808), cancellationToken); + if (client != null) + { + while (!cancellationToken.IsCancellationRequested) + { + try + { + int lat = new Random(1000).Next(100000, 180000); + int Lng = new Random(1000).Next(100000, 180000); + await client.SendAsync(JT808MsgId.位置信息汇报.Create(client.DeviceConfig.TerminalPhoneNo, new JT808_0x0200() + { + Lat = lat, + Lng = Lng, + GPSTime = DateTime.Now, + Speed = 50, + Direction = 30, + AlarmFlag = 5, + Altitude = 50, + StatusFlag = 10 + })); + } + catch (Exception ex) + { + Logger.LogError(ex.Message); + } + await Task.Delay(3 * 1000); + } + } + }, cancellationToken); + return Task.CompletedTask; + } + + public Task StopAsync(CancellationToken cancellationToken) + { + jT808TcpClientFactory.Dispose(); + return Task.CompletedTask; + } + } +} diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/Program.cs b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Program.cs similarity index 60% rename from src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/Program.cs rename to src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Program.cs index 7c84796..807e32c 100644 --- a/src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/Program.cs +++ b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Program.cs @@ -6,20 +6,17 @@ using Microsoft.Extensions.Logging; using JT808.Protocol; using Microsoft.Extensions.Configuration; using NLog.Extensions.Logging; -using JT808.Gateway.TestHosting.Jobs; -using JT808.Gateway.Kafka; -using JT808.Gateway.InMemoryMQ; -using JT808.Gateway.ReplyMessage; -using JT808.Gateway.Client; -using JT808.Gateway.SessionNotice; -using JT808.Gateway.Abstractions.Enums; -using JT808.Gateway.MsgIdHandler; +using JT808.Gateway.NormalHosting.Impl; using JT808.Gateway.MsgLogging; -using JT808.Gateway.Traffic; using JT808.Gateway.Transmit; -using JT808.Gateway.TestHosting.Impl; +using JT808.Gateway.Traffic; +using JT808.Gateway.NormalHosting.Services; +using JT808.Gateway.Abstractions; +using JT808.Gateway.SessionNotice; +using JT808.Gateway.Client; +using JT808.Gateway.NormalHosting.Jobs; -namespace JT808.Gateway.TestHosting +namespace JT808.Gateway.NormalHosting { class Program { @@ -43,38 +40,30 @@ namespace JT808.Gateway.TestHosting { services.AddSingleton(); services.AddSingleton(typeof(ILogger<>), typeof(Logger<>)); + //使用内存队列实现会话通知 + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); services.AddJT808Configure() //添加客户端工具 //.AddClient() - //.AddGateway(options => + //.AddNormalGateway(options => ////{ //// options.TcpPort = 808; //// options.UdpPort = 808; ////}) - .AddGateway(hostContext.Configuration) + .AddNormalGateway(hostContext.Configuration) + .ReplaceNormalReplyMessageHandler() + .AddMsgLogging() + .AddTraffic() + .AddSessionNotice() + .AddTransmit(hostContext.Configuration) .AddTcp() .AddUdp() .AddGrpc() - //InMemoryMQ 按需要加载对应的服务 - //注意:不需要的就不用add进来了 - .AddServerInMemoryMQ(JT808ConsumerType.All) - //方式1 - //.AddServerInMemoryMQ(JT808ConsumerType.MsgIdHandlerConsumer| JT808ConsumerType.ReplyMessageConsumer) - //方式2 - //.AddServerInMemoryMQ(JT808ConsumerType.MsgIdHandlerConsumer,JT808ConsumerType.ReplyMessageConsumer) - .AddInMemoryTraffic() - .AddInMemoryTransmit(hostContext.Configuration) - .AddInMemoryMsgIdHandler() - .AddInMemoryMsgLogging() - .AddInMemorySessionNotice() - .AddInMemoryReplyMessage() - //kafka插件 - //.AddServerKafkaMsgProducer(hostContext.Configuration) - //.AddServerKafkaMsgReplyConsumer(hostContext.Configuration) - //.AddServerKafkaSessionProducer(hostContext.Configuration) ; //流量统计 - //services.AddHostedService(); + services.AddHostedService(); //grpc客户端调用 //services.AddHostedService(); //客户端测试 diff --git a/src/JT808.Gateway.InMemoryMQ/Services/JT808SessionService.cs b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Services/JT808SessionService.cs similarity index 94% rename from src/JT808.Gateway.InMemoryMQ/Services/JT808SessionService.cs rename to src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Services/JT808SessionService.cs index 696b004..baf07f0 100644 --- a/src/JT808.Gateway.InMemoryMQ/Services/JT808SessionService.cs +++ b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Services/JT808SessionService.cs @@ -5,7 +5,7 @@ using System.Threading; using System.Threading.Channels; using System.Threading.Tasks; -namespace JT808.Gateway.InMemoryMQ.Services +namespace JT808.Gateway.NormalHosting.Services { public class JT808SessionService { diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/Configs/NLog.xsd b/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/Configs/NLog.xsd new file mode 100644 index 0000000..2f57d09 --- /dev/null +++ b/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/Configs/NLog.xsd @@ -0,0 +1,3106 @@ + + + + + + + + + + + + + + + Watch config file for changes and reload automatically. + + + + + Print internal NLog messages to the console. Default value is: false + + + + + Print internal NLog messages to the console error output. Default value is: false + + + + + Write internal NLog messages to the specified file. + + + + + Log level threshold for internal log messages. Default value is: Info. + + + + + Global log level threshold for application log messages. Messages below this level won't be logged.. + + + + + Throw an exception when there is an internal error. Default value is: false. + + + + + Throw an exception when there is a configuration error. If not set, determined by throwExceptions. + + + + + Gets or sets a value indicating whether Variables should be kept on configuration reload. Default value is: false. + + + + + Write internal NLog messages to the System.Diagnostics.Trace. Default value is: false. + + + + + Write timestamps for internal NLog messages. Default value is: true. + + + + + Use InvariantCulture as default culture instead of CurrentCulture. Default value is: false. + + + + + Perform mesage template parsing and formatting of LogEvent messages (true = Always, false = Never, empty = Auto Detect). Default value is: empty. + + + + + + + + + + + + + + Make all targets within this section asynchronous (creates additional threads but the calling thread isn't blocked by any target writes). + + + + + + + + + + + + + + + + + Prefix for targets/layout renderers/filters/conditions loaded from this assembly. + + + + + Load NLog extensions from the specified file (*.dll) + + + + + Load NLog extensions from the specified assembly. Assembly name should be fully qualified. + + + + + + + + + + Name of the logger. May include '*' character which acts like a wildcard. Allowed forms are: *, Name, *Name, Name* and *Name* + + + + + Comma separated list of levels that this rule matches. + + + + + Minimum level that this rule matches. + + + + + Maximum level that this rule matches. + + + + + Level that this rule matches. + + + + + Comma separated list of target names. + + + + + Ignore further rules if this one matches. + + + + + Enable or disable logging rule. Disabled rules are ignored. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the file to be included. You could use * wildcard. The name is relative to the name of the current config file. + + + + + Ignore any errors in the include file. + + + + + + + Variable name. + + + + + Variable value. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Number of log events that should be processed in a batch by the lazy writer thread. + + + + + Limit of full s to write before yielding into Performance is better when writing many small batches, than writing a single large batch + + + + + Action to be taken when the lazy writer thread request queue count exceeds the set limit. + + + + + Limit on the number of requests in the lazy writer thread request queue. + + + + + Time in milliseconds to sleep between batches. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Delay the flush until the LogEvent has been confirmed as written + + + + + Condition expression. Log events who meet this condition will cause a flush on the wrapped target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Number of log events to be buffered. + + + + + Timeout (in milliseconds) after which the contents of buffer will be flushed if there's no write in the specified period of time. Use -1 to disable timed flushes. + + + + + Indicates whether to use sliding timeout. + + + + + Action to take if the buffer overflows. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Encoding to be used. + + + + + Instance of that is used to format log messages. + + + + + End of line value if a newline is appended at the end of log message . + + + + + Maximum message size in bytes. + + + + + Indicates whether to append newline at the end of log message. + + + + + Action that should be taken if the will be more connections than . + + + + + Action that should be taken if the message is larger than maxMessageSize. + + + + + Maximum current connections. 0 = no maximum. + + + + + Indicates whether to keep connection open whenever possible. + + + + + Size of the connection cache (number of connections which are kept alive). + + + + + Network address. + + + + + Maximum queue size. + + + + + NDC item separator. + + + + + Indicates whether to include source info (file name and line number) in the information sent over the network. + + + + + Indicates whether to include dictionary contents. + + + + + Indicates whether to include contents of the stack. + + + + + Indicates whether to include stack contents. + + + + + Indicates whether to include dictionary contents. + + + + + Indicates whether to include call site (class and method name) in the information sent over the network. + + + + + Option to include all properties from the log events + + + + + AppInfo field. By default it's the friendly name of the current AppDomain. + + + + + Indicates whether to include NLog-specific extensions to log4j schema. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + Layout that should be use to calcuate the value for the parameter. + + + + + Viewer parameter name. + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + Indicates whether to use default row highlighting rules. + + + + + Indicates whether to auto-check if the console is available. - Disables console writing if Environment.UserInteractive = False (Windows Service) - Disables console writing if Console Standard Input is not available (Non-Console-App) + + + + + The encoding for writing messages to the . + + + + + Indicates whether the error stream (stderr) should be used instead of the output stream (stdout). + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Condition that must be met in order to set the specified foreground and background color. + + + + + Background color. + + + + + Foreground color. + + + + + + + + + + + + + + + + Indicates whether to ignore case when comparing texts. + + + + + Regular expression to be matched. You must specify either text or regex. + + + + + Text to be matched. You must specify either text or regex. + + + + + Indicates whether to match whole words only. + + + + + Compile the ? This can improve the performance, but at the costs of more memory usage. If false, the Regex Cache is used. + + + + + Background color. + + + + + Foreground color. + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + Indicates whether to send the log messages to the standard error instead of the standard output. + + + + + Indicates whether to auto-check if the console is available - Disables console writing if Environment.UserInteractive = False (Windows Service) - Disables console writing if Console Standard Input is not available (Non-Console-App) + + + + + The encoding for writing messages to the . + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Obsolete - value will be ignored! The logging code always runs outside of transaction. Gets or sets a value indicating whether to use database transactions. Some data providers require this. + + + + + Database user name. If the ConnectionString is not provided this value will be used to construct the "User ID=" part of the connection string. + + + + + Name of the database provider. + + + + + Database password. If the ConnectionString is not provided this value will be used to construct the "Password=" part of the connection string. + + + + + Indicates whether to keep the database connection open between the log events. + + + + + Database name. If the ConnectionString is not provided this value will be used to construct the "Database=" part of the connection string. + + + + + Name of the connection string (as specified in <connectionStrings> configuration section. + + + + + Connection string. When provided, it overrides the values specified in DBHost, DBUserName, DBPassword, DBDatabase. + + + + + Database host name. If the ConnectionString is not provided this value will be used to construct the "Server=" part of the connection string. + + + + + Connection string using for installation and uninstallation. If not provided, regular ConnectionString is being used. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + Text of the SQL command to be run on each log level. + + + + + Type of the SQL command to be run on each log level. + + + + + + + + + + + + + + + + + + + + + + + Type of the command. + + + + + Connection string to run the command against. If not provided, connection string from the target is used. + + + + + Indicates whether to ignore failures. + + + + + Command text. + + + + + + + + + + + + + + Layout that should be use to calcuate the value for the parameter. + + + + + Database parameter name. + + + + + Database parameter precision. + + + + + Database parameter scale. + + + + + Database parameter size. + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Layout that renders event Category. + + + + + Layout that renders event ID. + + + + + Name of the Event Log to write to. This can be System, Application or any user-defined name. + + + + + Name of the machine on which Event Log service is running. + + + + + Value to be used as the event Source. + + + + + Action to take if the message is larger than the option. + + + + + Optional entrytype. When not set, or when not convertable to then determined by + + + + + Maximum Event log size in kilobytes. If null, the value won't be set. Default is 512 Kilobytes as specified by Eventlog API + + + + + Message length limit to write to the Event Log. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Indicates whether to return to the first target after any successful write. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + File encoding. + + + + + Line ending mode. + + + + + Way file archives are numbered. + + + + + Name of the file to be used for an archive. + + + + + Indicates whether to automatically archive log files every time the specified time passes. + + + + + Size in bytes above which log files will be automatically archived. Warning: combining this with isn't supported. We cannot create multiple archive files, if they should have the same name. Choose: + + + + + Indicates whether to compress archive files into the zip archive format. + + + + + Maximum number of archive files that should be kept. + + + + + Gets or set a value indicating whether a managed file stream is forced, instead of using the native implementation. + + + + + Is the an absolute or relative path? + + + + + Cleanup invalid values in a filename, e.g. slashes in a filename. If set to true, this can impact the performance of massive writes. If set to false, nothing gets written when the filename is wrong. + + + + + Whether or not this target should just discard all data that its asked to write. Mostly used for when testing NLog Stack except final write + + + + + Is the an absolute or relative path? + + + + + Value indicationg whether file creation calls should be synchronized by a system global mutex. + + + + + Maximum number of log filenames that should be stored as existing. + + + + + Indicates whether the footer should be written only when the file is archived. + + + + + Name of the file to write to. + + + + + Value specifying the date format to use when archiving files. + + + + + Indicates whether to archive old log file on startup. + + + + + Indicates whether to create directories if they do not exist. + + + + + File attributes (Windows only). + + + + + Indicates whether to delete old log file on startup. + + + + + Indicates whether to replace file contents on each write instead of appending log message at the end. + + + + + Indicates whether to enable log file(s) to be deleted. + + + + + Number of times the write is appended on the file before NLog discards the log message. + + + + + Indicates whether concurrent writes to the log file by multiple processes on the same host. + + + + + Indicates whether to keep log file open instead of opening and closing it on each logging event. + + + + + Indicates whether concurrent writes to the log file by multiple processes on different network hosts. + + + + + Number of files to be kept open. Setting this to a higher value may improve performance in a situation where a single File target is writing to many files (such as splitting by level or by logger). + + + + + Maximum number of seconds that files are kept open. If this number is negative the files are not automatically closed after a period of inactivity. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + Log file buffer size in bytes. + + + + + Indicates whether to automatically flush the file buffers after each log message. + + + + + Delay in milliseconds to wait before attempting to write to the file again. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Condition expression. Log events who meet this condition will be forwarded to the wrapped target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Windows domain name to change context to. + + + + + Required impersonation level. + + + + + Type of the logon provider. + + + + + Logon Type. + + + + + User account password. + + + + + Indicates whether to revert to the credentials of the process instead of impersonating another user. + + + + + Username to change context to. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Interval in which messages will be written up to the number of messages. + + + + + Maximum allowed number of messages written per . + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Endpoint address. + + + + + Name of the endpoint configuration in WCF configuration file. + + + + + Indicates whether to use a WCF service contract that is one way (fire and forget) or two way (request-reply) + + + + + Client ID. + + + + + Indicates whether to include per-event properties in the payload sent to the server. + + + + + Indicates whether to use binary message encoding. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + Layout that should be use to calculate the value for the parameter. + + + + + Name of the parameter. + + + + + Type of the parameter. + + + + + Type of the parameter. Obsolete alias for + + + + + Parameter can combine multiple LogEvents into a single parameter value + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + Indicates whether to send message as HTML instead of plain text. + + + + + Encoding to be used for sending e-mail. + + + + + Indicates whether to add new lines between log entries. + + + + + CC email addresses separated by semicolons (e.g. john@domain.com;jane@domain.com). + + + + + Recipients' email addresses separated by semicolons (e.g. john@domain.com;jane@domain.com). + + + + + BCC email addresses separated by semicolons (e.g. john@domain.com;jane@domain.com). + + + + + Mail message body (repeated for each log message send in one mail). + + + + + Mail subject. + + + + + Sender's email address (e.g. joe@domain.com). + + + + + Indicates the SMTP client timeout. + + + + + Priority used for sending mails. + + + + + Indicates whether NewLine characters in the body should be replaced with tags. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + SMTP Server to be used for sending. + + + + + SMTP Authentication mode. + + + + + Username used to connect to SMTP server (used when SmtpAuthentication is set to "basic"). + + + + + Password used to authenticate against SMTP server (used when SmtpAuthentication is set to "basic"). + + + + + Indicates whether SSL (secure sockets layer) should be used when communicating with SMTP server. + + + + + Port number that SMTP Server is listening on. + + + + + Indicates whether the default Settings from System.Net.MailSettings should be used. + + + + + Folder where applications save mail messages to be processed by the local SMTP server. + + + + + Specifies how outgoing email messages will be handled. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Class name. + + + + + Method name. The method must be public and static. Use the AssemblyQualifiedName , https://msdn.microsoft.com/en-us/library/system.type.assemblyqualifiedname(v=vs.110).aspx e.g. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Encoding to be used. + + + + + End of line value if a newline is appended at the end of log message . + + + + + Maximum message size in bytes. + + + + + Indicates whether to append newline at the end of log message. + + + + + Action that should be taken if the will be more connections than . + + + + + Action that should be taken if the message is larger than maxMessageSize. + + + + + Network address. + + + + + Size of the connection cache (number of connections which are kept alive). + + + + + Indicates whether to keep connection open whenever possible. + + + + + Maximum current connections. 0 = no maximum. + + + + + Maximum queue size. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Encoding to be used. + + + + + Instance of that is used to format log messages. + + + + + End of line value if a newline is appended at the end of log message . + + + + + Maximum message size in bytes. + + + + + Indicates whether to append newline at the end of log message. + + + + + Action that should be taken if the will be more connections than . + + + + + Action that should be taken if the message is larger than maxMessageSize. + + + + + Maximum current connections. 0 = no maximum. + + + + + Indicates whether to keep connection open whenever possible. + + + + + Size of the connection cache (number of connections which are kept alive). + + + + + Network address. + + + + + Maximum queue size. + + + + + NDC item separator. + + + + + Indicates whether to include source info (file name and line number) in the information sent over the network. + + + + + Indicates whether to include dictionary contents. + + + + + Indicates whether to include contents of the stack. + + + + + Indicates whether to include stack contents. + + + + + Indicates whether to include dictionary contents. + + + + + Indicates whether to include call site (class and method name) in the information sent over the network. + + + + + Option to include all properties from the log events + + + + + AppInfo field. By default it's the friendly name of the current AppDomain. + + + + + Indicates whether to include NLog-specific extensions to log4j schema. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Indicates whether to perform layout calculation. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Indicates whether performance counter should be automatically created. + + + + + Name of the performance counter category. + + + + + Counter help text. + + + + + Name of the performance counter. + + + + + Performance counter type. + + + + + The value by which to increment the counter. + + + + + Performance counter instance name. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Default filter to be applied when no specific rule matches. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + Condition to be tested. + + + + + Resulting filter to be applied when the condition matches. + + + + + + + + + + + + + Name of the target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + Name of the target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + Number of times to repeat each log message. + + + + + + + + + + + + + + + + + Name of the target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + Number of retries that should be attempted on the wrapped target in case of a failure. + + + + + Time to wait between retries in milliseconds. + + + + + + + + + + + + + + + Name of the target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + Name of the target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Always use independent of + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Should we include the BOM (Byte-order-mark) for UTF? Influences the property. This will only work for UTF-8. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + Encoding. + + + + + Value whether escaping be done according to the old NLog style (Very non-standard) + + + + + Value whether escaping be done according to Rfc3986 (Supports Internationalized Resource Identifiers - IRIs) + + + + + Web service method name. Only used with Soap. + + + + + Web service namespace. Only used with Soap. + + + + + Indicates whether to pre-authenticate the HttpWebRequest (Requires 'Authorization' in parameters) + + + + + Protocol to be used when calling web service. + + + + + Web service URL. + + + + + Name of the root XML element, if POST of XML document chosen. If so, this property must not be null. (see and ). + + + + + (optional) root namespace of the XML document, if POST of XML document chosen. (see and ). + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Footer layout. + + + + + Header layout. + + + + + Body layout (can be repeated multiple times). + + + + + Custom column delimiter value (valid when ColumnDelimiter is set to 'Custom'). + + + + + Column delimiter. + + + + + Quote Character. + + + + + Quoting mode. + + + + + Indicates whether CVS should include header. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Layout of the column. + + + + + Name of the column. + + + + + + + + + + + + + + + + + + List of property names to exclude when is true + + + + + Option to include all properties from the log events + + + + + Indicates whether to include contents of the dictionary. + + + + + Indicates whether to include contents of the dictionary. + + + + + Option to render the empty object value {} + + + + + Option to suppress the extra spaces in the output json + + + + + + + + + + + + + + + Determines wether or not this attribute will be Json encoded. + + + + + Indicates whether to escape non-ascii characters + + + + + Layout that will be rendered as the attribute's value. + + + + + Name of the attribute. + + + + + + + + + + + + + + Footer layout. + + + + + Header layout. + + + + + Body layout (can be repeated multiple times). + + + + + + + + + + + + + + + + + + Option to include all properties from the log events + + + + + Indicates whether to include contents of the dictionary. + + + + + Indicates whether to include contents of the dictionary. + + + + + Indicates whether to include contents of the stack. + + + + + Indicates whether to include contents of the stack. + + + + + + + + + + + + + + Layout text. + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + Condition expression. + + + + + + + + + + + + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + Indicates whether to ignore case when comparing strings. + + + + + Layout to be used to filter log messages. + + + + + Substring to be matched. + + + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + String to compare the layout to. + + + + + Indicates whether to ignore case when comparing strings. + + + + + Layout to be used to filter log messages. + + + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + Indicates whether to ignore case when comparing strings. + + + + + Layout to be used to filter log messages. + + + + + Substring to be matched. + + + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + String to compare the layout to. + + + + + Indicates whether to ignore case when comparing strings. + + + + + Layout to be used to filter log messages. + + + + + + + + + + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + Layout to be used to filter log messages. + + + + + Default number of unique filter values to expect, will automatically increase if needed + + + + + Append FilterCount to the when an event is no longer filtered + + + + + Insert FilterCount value into when an event is no longer filtered + + + + + Applies the configured action to the initial logevent that starts the timeout period. Used to configure that it should ignore all events until timeout. + + + + + Max number of unique filter values to expect simultaneously + + + + + Max length of filter values, will truncate if above limit + + + + + Default buffer size for the internal buffers + + + + + Reuse internal buffers, and doesn't have to constantly allocate new buffers + + + + + How long before a filter expires, and logging is accepted again + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/Configs/nlog.Unix.config b/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/Configs/nlog.Unix.config new file mode 100644 index 0000000..95469d6 --- /dev/null +++ b/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/Configs/nlog.Unix.config @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/Configs/nlog.Win32NT.config b/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/Configs/nlog.Win32NT.config new file mode 100644 index 0000000..a4e9705 --- /dev/null +++ b/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/Configs/nlog.Win32NT.config @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/JT808.Gateway.TestHosting.csproj b/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/JT808.Gateway.QueueHosting.csproj similarity index 86% rename from src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/JT808.Gateway.TestHosting.csproj rename to src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/JT808.Gateway.QueueHosting.csproj index 85459c8..a700cb0 100644 --- a/src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/JT808.Gateway.TestHosting.csproj +++ b/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/JT808.Gateway.QueueHosting.csproj @@ -1,11 +1,8 @@ - + Exe netcoreapp3.1 - Linux - @@ -16,16 +13,15 @@ + + + - - - - diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/Jobs/CallGrpcClientJob.cs b/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/Jobs/CallGrpcClientJob.cs similarity index 98% rename from src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/Jobs/CallGrpcClientJob.cs rename to src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/Jobs/CallGrpcClientJob.cs index c233069..2572bbb 100644 --- a/src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/Jobs/CallGrpcClientJob.cs +++ b/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/Jobs/CallGrpcClientJob.cs @@ -10,7 +10,7 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using System.Text.Json; -namespace JT808.Gateway.TestHosting.Jobs +namespace JT808.Gateway.QueueHosting.Jobs { public class CallGrpcClientJob :IHostedService { diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/Jobs/UpJob.cs b/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/Jobs/UpJob.cs similarity index 92% rename from src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/Jobs/UpJob.cs rename to src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/Jobs/UpJob.cs index bb2437e..789d107 100644 --- a/src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/Jobs/UpJob.cs +++ b/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/Jobs/UpJob.cs @@ -10,7 +10,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; -namespace JT808.Gateway.TestHosting.Jobs +namespace JT808.Gateway.QueueHosting.Jobs { public class UpJob : IHostedService { @@ -38,7 +38,7 @@ namespace JT808.Gateway.TestHosting.Jobs { int lat = new Random(1000).Next(100000, 180000); int Lng = new Random(1000).Next(100000, 180000); - client.SendAsync(JT808MsgId.位置信息汇报.Create(client.DeviceConfig.TerminalPhoneNo, new JT808_0x0200() + await client.SendAsync(JT808MsgId.位置信息汇报.Create(client.DeviceConfig.TerminalPhoneNo, new JT808_0x0200() { Lat = lat, Lng = Lng, diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/Program.cs b/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/Program.cs new file mode 100644 index 0000000..2a01222 --- /dev/null +++ b/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/Program.cs @@ -0,0 +1,67 @@ +using System; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using JT808.Protocol; +using Microsoft.Extensions.Configuration; +using NLog.Extensions.Logging; +using JT808.Gateway.MsgLogging; +using JT808.Gateway.Transmit; +using JT808.Gateway.Traffic; +using JT808.Gateway.Abstractions; +using JT808.Gateway.SessionNotice; +using JT808.Gateway.Client; +using JT808.Gateway.QueueHosting.Jobs; +using JT808.Gateway.Kafka; + +namespace JT808.Gateway.QueueHosting +{ + class Program + { + static async Task Main(string[] args) + { + var serverHostBuilder = new HostBuilder() + .ConfigureAppConfiguration((hostingContext, config) => + { + config.SetBasePath(AppDomain.CurrentDomain.BaseDirectory) + .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) + .AddJsonFile($"appsettings.{ hostingContext.HostingEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true); + }) + .ConfigureLogging((context, logging) => + { + Console.WriteLine($"Environment.OSVersion.Platform:{Environment.OSVersion.Platform.ToString()}"); + NLog.LogManager.LoadConfiguration($"Configs/nlog.{Environment.OSVersion.Platform.ToString()}.config"); + logging.AddNLog(new NLogProviderOptions { CaptureMessageTemplates = true, CaptureMessageProperties = true }); + logging.SetMinimumLevel(LogLevel.Trace); + }) + .ConfigureServices((hostContext, services) => + { + services.AddSingleton(); + services.AddSingleton(typeof(ILogger<>), typeof(Logger<>)); + services.AddJT808Configure() + //添加客户端工具 + //.AddClient() + //.AddQueueGateway(options => + //{ + // options.TcpPort = 808; + // options.UdpPort = 808; + //}) + .AddQueueGateway(hostContext.Configuration) + .AddServerKafkaMsgProducer(hostContext.Configuration) + .AddServerKafkaSessionProducer(hostContext.Configuration) + .AddServerKafkaMsgReplyConsumer(hostContext.Configuration) + .AddTcp() + .AddUdp() + .AddGrpc() + ; + //grpc客户端调用 + //services.AddHostedService(); + //客户端测试 + //services.AddHostedService(); + }); + + await serverHostBuilder.RunConsoleAsync(); + } + } +} diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/Dockerfile b/src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/Dockerfile deleted file mode 100644 index 6a33faf..0000000 --- a/src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/Dockerfile +++ /dev/null @@ -1,23 +0,0 @@ -#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. - -FROM mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim AS base -EXPOSE 808/tcp -WORKDIR /app - -FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build -WORKDIR /src -COPY ["JT808.Gateway.TestHosting/JT808.Gateway.TestHosting.csproj", "JT808.Gateway.TestHosting/"] -COPY ["JT808.Gateway/JT808.Gateway.csproj", "JT808.Gateway/"] -COPY ["JT808.Gateway.Abstractions/JT808.Gateway.Abstractions.csproj", "JT808.Gateway.Abstractions/"] -RUN dotnet restore "JT808.Gateway.TestHosting/JT808.Gateway.TestHosting.csproj" -COPY . . -WORKDIR "/src/JT808.Gateway.TestHosting" -RUN dotnet build "JT808.Gateway.TestHosting.csproj" -c Release -o /app/build - -FROM build AS publish -RUN dotnet publish "JT808.Gateway.TestHosting.csproj" -c Release -o /app/publish - -FROM base AS final -WORKDIR /app -COPY --from=publish /app/publish . -ENTRYPOINT ["dotnet", "JT808.Gateway.TestHosting.dll"] \ No newline at end of file diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/Impl/JT808MsgIdHandler.cs b/src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/Impl/JT808MsgIdHandler.cs deleted file mode 100644 index b50922d..0000000 --- a/src/JT808.Gateway.Tests/JT808.Gateway.TestHosting/Impl/JT808MsgIdHandler.cs +++ /dev/null @@ -1,22 +0,0 @@ -using JT808.Gateway.MsgIdHandler; -using JT808.Protocol.Extensions; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Text; - -namespace JT808.Gateway.TestHosting.Impl -{ - public class JT808MsgIdHandler : IJT808MsgIdHandler - { - private readonly ILogger Logger; - public JT808MsgIdHandler(ILoggerFactory loggerFactory) - { - Logger = loggerFactory.CreateLogger("JT808MsgIdHandler"); - } - public void Processor((string TerminalNo, byte[] Data) parameter) - { - Logger.LogDebug($"{parameter.TerminalNo}-{parameter.Data.ToHexString()}"); - } - } -} diff --git a/src/JT808.Gateway.sln b/src/JT808.Gateway.sln index 92845e7..02ca89a 100644 --- a/src/JT808.Gateway.sln +++ b/src/JT808.Gateway.sln @@ -23,19 +23,21 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT808.Gateway.Transmit", "J EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT808.Gateway.Traffic", "JT808.Gateway.Services\JT808.Gateway.Traffic\JT808.Gateway.Traffic.csproj", "{8FCC6D65-8A49-4AE7-8B19-F255100849D6}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT808.Gateway.InMemoryMQ", "JT808.Gateway.InMemoryMQ\JT808.Gateway.InMemoryMQ.csproj", "{F7460E8F-B23E-4407-8802-375DE37BED00}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT808.Gateway.Client", "JT808.Gateway.Client\JT808.Gateway.Client.csproj", "{AC3070AC-A938-4213-A562-C079BB4A3F9E}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{7CBAACEE-19BF-499A-8C41-36A1324D45E9}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT808.Gateway.CleintBenchmark", "JT808.Gateway.CleintBenchmark\JT808.Gateway.CleintBenchmark.csproj", "{0FBC9E4F-8585-4820-ACF1-145A14B3A727}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT808.Gateway.Test", "JT808.Gateway.Tests\JT808.Gateway.Test\JT808.Gateway.Test.csproj", "{E3DC260E-0B55-4993-B051-402E44D4E883}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT808.Gateway.TestHosting", "JT808.Gateway.Tests\JT808.Gateway.TestHosting\JT808.Gateway.TestHosting.csproj", "{69C815FE-3C32-473E-99C9-F3C4B3BCFF81}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT808.Gateway.NormalHosting", "JT808.Gateway.Tests\JT808.Gateway.NormalHosting\JT808.Gateway.NormalHosting.csproj", "{22368AAD-A1F3-446B-B68F-98A0933BF1F6}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT808.Gateway.QueueHosting", "JT808.Gateway.Tests\JT808.Gateway.QueueHosting\JT808.Gateway.QueueHosting.csproj", "{52D895BD-C60B-42D8-9229-C85927546FDA}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Benchmark", "Benchmark", "{6FAEC008-93CB-4730-8C58-D31FFD342C4F}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT808.Gateway.CleintBenchmark", "JT808.Gateway.Benchmark\JT808.Gateway.CleintBenchmark\JT808.Gateway.CleintBenchmark.csproj", "{E34C6B7D-A48B-4871-895C-07AC12F959D3}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT808.Gateway.InMemoryMQ.Test", "JT808.Gateway.Tests\JT808.Gateway.InMemoryMQ.Test\JT808.Gateway.InMemoryMQ.Test.csproj", "{E103E89D-3069-4AAE-99CE-2AD633AD351E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT808.Gateway.ServerBenchmark", "JT808.Gateway.Benchmark\JT808.Gateway.ServerBenchmark\JT808.Gateway.ServerBenchmark.csproj", "{AF0C529A-D3CA-4FE4-93B4-735D0934EBEF}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -79,30 +81,30 @@ Global {8FCC6D65-8A49-4AE7-8B19-F255100849D6}.Debug|Any CPU.Build.0 = Debug|Any CPU {8FCC6D65-8A49-4AE7-8B19-F255100849D6}.Release|Any CPU.ActiveCfg = Release|Any CPU {8FCC6D65-8A49-4AE7-8B19-F255100849D6}.Release|Any CPU.Build.0 = Release|Any CPU - {F7460E8F-B23E-4407-8802-375DE37BED00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F7460E8F-B23E-4407-8802-375DE37BED00}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F7460E8F-B23E-4407-8802-375DE37BED00}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F7460E8F-B23E-4407-8802-375DE37BED00}.Release|Any CPU.Build.0 = Release|Any CPU {AC3070AC-A938-4213-A562-C079BB4A3F9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {AC3070AC-A938-4213-A562-C079BB4A3F9E}.Debug|Any CPU.Build.0 = Debug|Any CPU {AC3070AC-A938-4213-A562-C079BB4A3F9E}.Release|Any CPU.ActiveCfg = Release|Any CPU {AC3070AC-A938-4213-A562-C079BB4A3F9E}.Release|Any CPU.Build.0 = Release|Any CPU - {0FBC9E4F-8585-4820-ACF1-145A14B3A727}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0FBC9E4F-8585-4820-ACF1-145A14B3A727}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0FBC9E4F-8585-4820-ACF1-145A14B3A727}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0FBC9E4F-8585-4820-ACF1-145A14B3A727}.Release|Any CPU.Build.0 = Release|Any CPU {E3DC260E-0B55-4993-B051-402E44D4E883}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E3DC260E-0B55-4993-B051-402E44D4E883}.Debug|Any CPU.Build.0 = Debug|Any CPU {E3DC260E-0B55-4993-B051-402E44D4E883}.Release|Any CPU.ActiveCfg = Release|Any CPU {E3DC260E-0B55-4993-B051-402E44D4E883}.Release|Any CPU.Build.0 = Release|Any CPU - {69C815FE-3C32-473E-99C9-F3C4B3BCFF81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {69C815FE-3C32-473E-99C9-F3C4B3BCFF81}.Debug|Any CPU.Build.0 = Debug|Any CPU - {69C815FE-3C32-473E-99C9-F3C4B3BCFF81}.Release|Any CPU.ActiveCfg = Release|Any CPU - {69C815FE-3C32-473E-99C9-F3C4B3BCFF81}.Release|Any CPU.Build.0 = Release|Any CPU - {E103E89D-3069-4AAE-99CE-2AD633AD351E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E103E89D-3069-4AAE-99CE-2AD633AD351E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E103E89D-3069-4AAE-99CE-2AD633AD351E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E103E89D-3069-4AAE-99CE-2AD633AD351E}.Release|Any CPU.Build.0 = Release|Any CPU + {22368AAD-A1F3-446B-B68F-98A0933BF1F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {22368AAD-A1F3-446B-B68F-98A0933BF1F6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {22368AAD-A1F3-446B-B68F-98A0933BF1F6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {22368AAD-A1F3-446B-B68F-98A0933BF1F6}.Release|Any CPU.Build.0 = Release|Any CPU + {52D895BD-C60B-42D8-9229-C85927546FDA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {52D895BD-C60B-42D8-9229-C85927546FDA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {52D895BD-C60B-42D8-9229-C85927546FDA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {52D895BD-C60B-42D8-9229-C85927546FDA}.Release|Any CPU.Build.0 = Release|Any CPU + {E34C6B7D-A48B-4871-895C-07AC12F959D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E34C6B7D-A48B-4871-895C-07AC12F959D3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E34C6B7D-A48B-4871-895C-07AC12F959D3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E34C6B7D-A48B-4871-895C-07AC12F959D3}.Release|Any CPU.Build.0 = Release|Any CPU + {AF0C529A-D3CA-4FE4-93B4-735D0934EBEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AF0C529A-D3CA-4FE4-93B4-735D0934EBEF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AF0C529A-D3CA-4FE4-93B4-735D0934EBEF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AF0C529A-D3CA-4FE4-93B4-735D0934EBEF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -115,8 +117,10 @@ Global {598E445A-AF2E-42F0-98F4-18EC22E473FC} = {3EF8490D-C993-49D8-8A3D-493B7F259D70} {8FCC6D65-8A49-4AE7-8B19-F255100849D6} = {3EF8490D-C993-49D8-8A3D-493B7F259D70} {E3DC260E-0B55-4993-B051-402E44D4E883} = {7CBAACEE-19BF-499A-8C41-36A1324D45E9} - {69C815FE-3C32-473E-99C9-F3C4B3BCFF81} = {7CBAACEE-19BF-499A-8C41-36A1324D45E9} - {E103E89D-3069-4AAE-99CE-2AD633AD351E} = {7CBAACEE-19BF-499A-8C41-36A1324D45E9} + {22368AAD-A1F3-446B-B68F-98A0933BF1F6} = {7CBAACEE-19BF-499A-8C41-36A1324D45E9} + {52D895BD-C60B-42D8-9229-C85927546FDA} = {7CBAACEE-19BF-499A-8C41-36A1324D45E9} + {E34C6B7D-A48B-4871-895C-07AC12F959D3} = {6FAEC008-93CB-4730-8C58-D31FFD342C4F} + {AF0C529A-D3CA-4FE4-93B4-735D0934EBEF} = {6FAEC008-93CB-4730-8C58-D31FFD342C4F} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {AA9303A7-6FB3-4572-88AA-3302E85330D1} diff --git a/src/JT808.Gateway/Internal/JT808NormalGatewayBuilderDefault.cs b/src/JT808.Gateway/Internal/JT808NormalGatewayBuilderDefault.cs new file mode 100644 index 0000000..23f2de3 --- /dev/null +++ b/src/JT808.Gateway/Internal/JT808NormalGatewayBuilderDefault.cs @@ -0,0 +1,20 @@ +using JT808.Gateway.Abstractions; +using JT808.Protocol; + +namespace JT808.Gateway.Internal +{ + public class JT808NormalGatewayBuilderDefault : IJT808NormalGatewayBuilder + { + public IJT808Builder JT808Builder { get; } + + public JT808NormalGatewayBuilderDefault(IJT808Builder builder) + { + JT808Builder = builder; + } + + public IJT808Builder Builder() + { + return JT808Builder; + } + } +} \ No newline at end of file diff --git a/src/JT808.Gateway/Internal/JT808QueueGatewayBuilderDefault.cs b/src/JT808.Gateway/Internal/JT808QueueGatewayBuilderDefault.cs new file mode 100644 index 0000000..d37792f --- /dev/null +++ b/src/JT808.Gateway/Internal/JT808QueueGatewayBuilderDefault.cs @@ -0,0 +1,20 @@ +using JT808.Gateway.Abstractions; +using JT808.Protocol; + +namespace JT808.Gateway.Internal +{ + public class JT808QueueGatewayBuilderDefault : IJT808QueueGatewayBuilder + { + public IJT808Builder JT808Builder { get; } + + public JT808QueueGatewayBuilderDefault(IJT808Builder builder) + { + JT808Builder = builder; + } + + public IJT808Builder Builder() + { + return JT808Builder; + } + } +} \ No newline at end of file diff --git a/src/JT808.Gateway/JT808GatewayExtensions.cs b/src/JT808.Gateway/JT808GatewayExtensions.cs index 2c0f1f5..38fbc8e 100644 --- a/src/JT808.Gateway/JT808GatewayExtensions.cs +++ b/src/JT808.Gateway/JT808GatewayExtensions.cs @@ -1,5 +1,6 @@ using JT808.Gateway.Abstractions; using JT808.Gateway.Configurations; +using JT808.Gateway.Enums; using JT808.Gateway.Internal; using JT808.Gateway.Services; using JT808.Gateway.Session; @@ -16,22 +17,49 @@ namespace JT808.Gateway { public static partial class JT808GatewayExtensions { - public static IJT808GatewayBuilder AddGateway(this IJT808Builder jt808Builder,Action config) + public static IJT808QueueGatewayBuilder AddQueueGateway(this IJT808Builder jT808Builder, Action config) { - IJT808GatewayBuilder server = new JT808GatewayBuilderDefault(jt808Builder); + IJT808QueueGatewayBuilder server = new JT808QueueGatewayBuilderDefault(jT808Builder); server.JT808Builder.Services.Configure(config); server.AddJT808Core(); + server.JT808Builder.Services.AddHostedService(); return server; } - public static IJT808GatewayBuilder AddGateway(this IJT808Builder jt808Builder, IConfiguration configuration) + public static IJT808NormalGatewayBuilder AddNormalGateway(this IJT808Builder jT808Builder, Action config) { - IJT808GatewayBuilder server = new JT808GatewayBuilderDefault(jt808Builder); + IJT808NormalGatewayBuilder server = new JT808NormalGatewayBuilderDefault(jT808Builder); + server.JT808Builder.Services.AddSingleton(); + server.JT808Builder.Services.Configure(config); + server.AddJT808Core(); + return server; + } + + public static IJT808QueueGatewayBuilder AddQueueGateway(this IJT808Builder jT808Builder, IConfiguration configuration) + { + IJT808QueueGatewayBuilder server = new JT808QueueGatewayBuilderDefault(jT808Builder); + server.JT808Builder.Services.Configure(configuration.GetSection("JT808Configuration")); + server.AddJT808Core(); + server.JT808Builder.Services.AddHostedService(); + return server; + } + + public static IJT808NormalGatewayBuilder AddNormalGateway(this IJT808Builder jT808Builder, IConfiguration configuration) + { + IJT808NormalGatewayBuilder server = new JT808NormalGatewayBuilderDefault(jT808Builder); + server.JT808Builder.Services.AddSingleton(); server.JT808Builder.Services.Configure(configuration.GetSection("JT808Configuration")); server.AddJT808Core(); return server; } + public static IJT808NormalGatewayBuilder ReplaceNormalReplyMessageHandler(this IJT808NormalGatewayBuilder config) + where TJT808NormalReplyMessageHandler : JT808NormalReplyMessageHandler + { + config.JT808Builder.Services.Replace(new ServiceDescriptor(typeof(JT808NormalReplyMessageHandler),typeof(TJT808NormalReplyMessageHandler), ServiceLifetime.Singleton)); + return config; + } + public static IJT808GatewayBuilder AddTcp(this IJT808GatewayBuilder config) { config.JT808Builder.Services.AddHostedService(); @@ -56,7 +84,6 @@ namespace JT808.Gateway { config.JT808Builder.Services.TryAddSingleton(); config.JT808Builder.Services.TryAddSingleton(); - config.JT808Builder.Services.AddHostedService(); return config; } } diff --git a/src/JT808.Gateway/JT808TcpServer.cs b/src/JT808.Gateway/JT808TcpServer.cs index 5dc3827..72a685e 100644 --- a/src/JT808.Gateway/JT808TcpServer.cs +++ b/src/JT808.Gateway/JT808TcpServer.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using JT808.Gateway.Abstractions; using JT808.Gateway.Abstractions.Enums; using JT808.Gateway.Configurations; +using JT808.Gateway.Enums; using JT808.Gateway.Services; using JT808.Gateway.Session; using JT808.Protocol; @@ -23,7 +24,7 @@ namespace JT808.Gateway { public class JT808TcpServer : IHostedService { - private readonly Socket server; + private Socket server; private readonly ILogger Logger; @@ -37,6 +38,19 @@ namespace JT808.Gateway private readonly JT808Configuration Configuration; + private readonly JT808NormalReplyMessageHandler JT808NormalReplyMessageHandler; + + private JT808UseType JT808UseType; + + /// + /// 使用队列方式 + /// + /// + /// + /// + /// + /// + /// public JT808TcpServer( IOptions jT808ConfigurationAccessor, IJT808Config jT808Config, @@ -51,6 +65,38 @@ namespace JT808.Gateway MsgProducer = jT808MsgProducer; AtomicCounterService = jT808AtomicCounterServiceFactory.Create(JT808TransportProtocolType.tcp); Configuration = jT808ConfigurationAccessor.Value; + JT808UseType = JT808UseType.Queue; + InitServer(); + } + /// + /// 使用正常方式 + /// + /// + /// + /// + /// + /// + /// + public JT808TcpServer( + IOptions jT808ConfigurationAccessor, + IJT808Config jT808Config, + ILoggerFactory loggerFactory, + JT808SessionManager jT808SessionManager, + JT808NormalReplyMessageHandler replyMessageHandler, + JT808AtomicCounterServiceFactory jT808AtomicCounterServiceFactory) + { + SessionManager = jT808SessionManager; + Logger = loggerFactory.CreateLogger("JT808TcpServer"); + Serializer = jT808Config.GetSerializer(); + JT808NormalReplyMessageHandler = replyMessageHandler; + AtomicCounterService = jT808AtomicCounterServiceFactory.Create(JT808TransportProtocolType.tcp); + Configuration = jT808ConfigurationAccessor.Value; + JT808UseType = JT808UseType.Normal; + InitServer(); + } + + private void InitServer() + { var IPEndPoint = new System.Net.IPEndPoint(IPAddress.Any, Configuration.TcpPort); server = new Socket(IPEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, true); @@ -193,7 +239,14 @@ namespace JT808.Gateway if (Logger.IsEnabled(LogLevel.Debug)) Logger.LogDebug($"[Atomic Success Counter]:{AtomicCounterService.MsgSuccessCount}"); if (Logger.IsEnabled(LogLevel.Trace)) Logger.LogTrace($"[Accept Hex {session.Client.RemoteEndPoint}]:{package.OriginalData.ToArray().ToHexString()}"); SessionManager.TryLink(package.Header.TerminalPhoneNo, session); - MsgProducer.ProduceAsync(package.Header.TerminalPhoneNo, package.OriginalData.ToArray()); + if(JT808UseType== JT808UseType.Normal) + { + JT808NormalReplyMessageHandler.Processor(package, session); + } + else if(JT808UseType== JT808UseType.Queue) + { + MsgProducer.ProduceAsync(package.Header.TerminalPhoneNo, package.OriginalData.ToArray()); + } } } catch (JT808Exception ex) diff --git a/src/JT808.Gateway/JT808UdpServer.cs b/src/JT808.Gateway/JT808UdpServer.cs index fa1aa52..718f964 100644 --- a/src/JT808.Gateway/JT808UdpServer.cs +++ b/src/JT808.Gateway/JT808UdpServer.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using JT808.Gateway.Abstractions; using JT808.Gateway.Abstractions.Enums; using JT808.Gateway.Configurations; +using JT808.Gateway.Enums; using JT808.Gateway.Services; using JT808.Gateway.Session; using JT808.Protocol; @@ -39,6 +40,10 @@ namespace JT808.Gateway private readonly IPEndPoint LocalIPEndPoint; + private readonly JT808NormalReplyMessageHandler JT808NormalReplyMessageHandler; + + private JT808UseType JT808UseType; + public JT808UdpServer( IOptions jT808ConfigurationAccessor, IJT808Config jT808Config, @@ -53,11 +58,32 @@ namespace JT808.Gateway MsgProducer = jT808MsgProducer; AtomicCounterService = jT808AtomicCounterServiceFactory.Create(JT808TransportProtocolType.udp); Configuration = jT808ConfigurationAccessor.Value; + JT808UseType = JT808UseType.Queue; LocalIPEndPoint = new System.Net.IPEndPoint(IPAddress.Any, Configuration.UdpPort); server = new Socket(LocalIPEndPoint.AddressFamily, SocketType.Dgram, ProtocolType.Udp); server.Bind(LocalIPEndPoint); } + public JT808UdpServer( + IOptions jT808ConfigurationAccessor, + IJT808Config jT808Config, + ILoggerFactory loggerFactory, + JT808SessionManager jT808SessionManager, + JT808NormalReplyMessageHandler replyMessageHandler, + JT808AtomicCounterServiceFactory jT808AtomicCounterServiceFactory) + { + SessionManager = jT808SessionManager; + Logger = loggerFactory.CreateLogger("JT808UdpServer"); + Serializer = jT808Config.GetSerializer(); + JT808NormalReplyMessageHandler = replyMessageHandler; + AtomicCounterService = jT808AtomicCounterServiceFactory.Create(JT808TransportProtocolType.udp); + Configuration = jT808ConfigurationAccessor.Value; + JT808UseType = JT808UseType.Normal; + LocalIPEndPoint = new System.Net.IPEndPoint(IPAddress.Any, Configuration.UdpPort); + server = new Socket(LocalIPEndPoint.AddressFamily, SocketType.Dgram, ProtocolType.Udp); + server.Bind(LocalIPEndPoint); + } + public Task StartAsync(CancellationToken cancellationToken) { Logger.LogInformation($"JT808 Udp Server start at {IPAddress.Any}:{Configuration.UdpPort}."); @@ -97,12 +123,19 @@ namespace JT808.Gateway AtomicCounterService.MsgSuccessIncrement(); if (Logger.IsEnabled(LogLevel.Debug)) Logger.LogDebug($"[Atomic Success Counter]:{AtomicCounterService.MsgSuccessCount}"); if (Logger.IsEnabled(LogLevel.Trace)) Logger.LogTrace($"[Accept Hex {receiveMessageFromResult.RemoteEndPoint}]:{package.OriginalData.ToArray().ToHexString()}"); - SessionManager.TryLink(package.Header.TerminalPhoneNo, socket, receiveMessageFromResult.RemoteEndPoint); + var session = SessionManager.TryLink(package.Header.TerminalPhoneNo, socket, receiveMessageFromResult.RemoteEndPoint); if (Logger.IsEnabled(LogLevel.Information)) { Logger.LogInformation($"[Connected]:{receiveMessageFromResult.RemoteEndPoint}"); } - MsgProducer.ProduceAsync(package.Header.TerminalPhoneNo, package.OriginalData.ToArray()); + if (JT808UseType == JT808UseType.Normal) + { + JT808NormalReplyMessageHandler.Processor(package, session); + } + else if (JT808UseType == JT808UseType.Queue) + { + MsgProducer.ProduceAsync(package.Header.TerminalPhoneNo, package.OriginalData.ToArray()); + } } catch (JT808Exception ex) { diff --git a/src/JT808.Gateway/Session/JT808SessionManager.cs b/src/JT808.Gateway/Session/JT808SessionManager.cs index ddb1289..3f2d47d 100644 --- a/src/JT808.Gateway/Session/JT808SessionManager.cs +++ b/src/JT808.Gateway/Session/JT808SessionManager.cs @@ -1,6 +1,5 @@ using JT808.Gateway.Abstractions; using JT808.Gateway.Abstractions.Enums; -using JT808.Gateway.Interfaces; using Microsoft.Extensions.Logging; using System; using System.Collections.Concurrent; diff --git a/src/JT808.Gateway/Session/JT808TcpSession.cs b/src/JT808.Gateway/Session/JT808TcpSession.cs index 70d044a..5b11fd4 100644 --- a/src/JT808.Gateway/Session/JT808TcpSession.cs +++ b/src/JT808.Gateway/Session/JT808TcpSession.cs @@ -1,5 +1,5 @@ -using JT808.Gateway.Abstractions.Enums; -using JT808.Gateway.Interfaces; +using JT808.Gateway.Abstractions; +using JT808.Gateway.Abstractions.Enums; using System; using System.Net; using System.Net.Sockets; diff --git a/src/JT808.Gateway/Session/JT808UdpSession.cs b/src/JT808.Gateway/Session/JT808UdpSession.cs index bdd4c87..d168dab 100644 --- a/src/JT808.Gateway/Session/JT808UdpSession.cs +++ b/src/JT808.Gateway/Session/JT808UdpSession.cs @@ -1,5 +1,5 @@ -using JT808.Gateway.Abstractions.Enums; -using JT808.Gateway.Interfaces; +using JT808.Gateway.Abstractions; +using JT808.Gateway.Abstractions.Enums; using System; using System.Net; using System.Net.Sockets; diff --git a/src/Version.props b/src/Version.props index 9d2758c..ca515ef 100644 --- a/src/Version.props +++ b/src/Version.props @@ -1,6 +1,6 @@  2.3.1 - 1.0.0-preview5 + 1.0.0-preview6 \ No newline at end of file