diff --git a/src/JT808.Gateway.Abstractions/Enums/JT808UseType.cs b/src/JT808.Gateway.Abstractions/Enums/JT808UseType.cs
deleted file mode 100644
index ffef406..0000000
--- a/src/JT808.Gateway.Abstractions/Enums/JT808UseType.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-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/JT808.Gateway.Abstractions.csproj b/src/JT808.Gateway.Abstractions/JT808.Gateway.Abstractions.csproj
index 3294e7d..28b7848 100644
--- a/src/JT808.Gateway.Abstractions/JT808.Gateway.Abstractions.csproj
+++ b/src/JT808.Gateway.Abstractions/JT808.Gateway.Abstractions.csproj
@@ -32,10 +32,10 @@
-
-
-
-
+
+
+
+
diff --git a/src/JT808.Gateway.Abstractions/JT808.Gateway.Abstractions.xml b/src/JT808.Gateway.Abstractions/JT808.Gateway.Abstractions.xml
index 8f06faa..ce77435 100644
--- a/src/JT808.Gateway.Abstractions/JT808.Gateway.Abstractions.xml
+++ b/src/JT808.Gateway.Abstractions/JT808.Gateway.Abstractions.xml
@@ -106,6 +106,14 @@
设备终端号
808 hex data
+
+
+
+
+ 请求数据
+ 当前会话
+ 应答消息数据
+
终端手机号
diff --git a/src/JT808.Gateway.Abstractions/JT808QueueReplyMessageHandler.cs b/src/JT808.Gateway.Abstractions/JT808QueueReplyMessageHandler.cs
deleted file mode 100644
index f31dd16..0000000
--- a/src/JT808.Gateway.Abstractions/JT808QueueReplyMessageHandler.cs
+++ /dev/null
@@ -1,307 +0,0 @@
-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 JT808QueueReplyMessageHandler
- {
- protected Dictionary HandlerDict { get; }
-
- protected delegate byte[] MsgIdMethodDelegate(JT808HeaderPackage package);
- protected JT808Serializer JT808Serializer { get; }
- protected IJT808MsgReplyProducer JT808MsgReplyProducer { get; }
- public JT808QueueReplyMessageHandler(
- IJT808Config jT808Config,
- IJT808MsgReplyProducer jT808MsgReplyProducer)
- {
- this.JT808Serializer = jT808Config.GetSerializer();
- this.JT808MsgReplyProducer = jT808MsgReplyProducer;
- 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 },
- {JT808MsgId.查询服务器时间请求.ToUInt16Value(),Msg0x0004 },
- {JT808MsgId.查询终端参数应答.ToUInt16Value(),Msg0x0104 },
- {JT808MsgId.查询终端属性应答.ToUInt16Value(),Msg0x0107 },
- {JT808MsgId.终端升级结果通知.ToUInt16Value(),Msg0x0108 },
- {JT808MsgId.位置信息查询应答.ToUInt16Value(),Msg0x0201 },
- {JT808MsgId.链路检测.ToUInt16Value(),Msg0x8204 },
- {JT808MsgId.车辆控制应答.ToUInt16Value(),Msg0x0500 },
- {JT808MsgId.摄像头立即拍摄命令.ToUInt16Value(),Msg0x8801 },
- {JT808MsgId.多媒体数据上传.ToUInt16Value(),Msg0x0801 },
- {JT808MsgId.多媒体事件信息上传.ToUInt16Value(),Msg0x0800 },
- {JT808MsgId.CAN总线数据上传.ToUInt16Value(),Msg0x0705 },
- };
- }
-
- public virtual void Processor((string TerminalNo, byte[] Data) parameter)
- {
- var request = JT808Serializer.HeaderDeserialize(parameter.Data);
- if (HandlerDict.TryGetValue(request.Header.MsgId, out var func))
- {
- var buffer = func(request);
- if (buffer != null)
- {
- JT808MsgReplyProducer.ProduceAsync(parameter.TerminalNo, buffer);
- }
- }
- }
-
- ///
- /// 终端通用应答
- /// 平台无需回复
- /// 实现自己的业务
- ///
- ///
- ///
- public virtual byte[] Msg0x0001(JT808HeaderPackage request)
- {
- return default;
- }
- ///
- /// 平台通用应答
- ///
- ///
- ///
- public virtual byte[] CommonReply(JT808HeaderPackage request)
- {
- 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
- }));
- 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
- }));
- return data;
- }
- }
- ///
- /// 终端心跳
- ///
- ///
- ///
- public virtual byte[] Msg0x0002(JT808HeaderPackage request)
- {
- return CommonReply(request);
- }
- ///
- /// 查询服务器时间
- /// 2019版本
- ///
- ///
- ///
- public virtual byte[] Msg0x0004(JT808HeaderPackage request)
- {
- byte[] data = JT808Serializer.Serialize(JT808MsgId.查询服务器时间应答.Create(request.Header.TerminalPhoneNo, new JT808_0x8004()
- {
- Time = DateTime.Now
- }));
- return data;
- }
- ///
- /// 服务器补传分包请求
- ///
- ///
- ///
- ///
- public virtual byte[] Msg0x8003(JT808HeaderPackage request)
- {
- throw new NotImplementedException("0x8003-服务器补传分包请求");
- }
- ///
- /// 终端补传分包请求
- ///
- ///
- ///
- public virtual byte[] Msg0x0005(JT808HeaderPackage request)
- {
- throw new NotImplementedException("0x0005-终端补传分包请求");
- }
- ///
- /// 终端注册
- ///
- ///
- ///
- public virtual byte[] Msg0x0100(JT808HeaderPackage request)
- {
- 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
- }));
- 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
- }));
- return data;
- }
- }
- ///
- /// 终端注销
- ///
- ///
- ///
- public virtual byte[] Msg0x0003(JT808HeaderPackage request)
- {
- return CommonReply(request);
- }
- ///
- /// 终端鉴权
- ///
- ///
- ///
- public virtual byte[] Msg0x0102(JT808HeaderPackage request)
- {
- return CommonReply(request);
- }
- ///
- /// 查询终端参数应答
- ///
- ///
- ///
- public virtual byte[] Msg0x0104(JT808HeaderPackage request)
- {
- return CommonReply(request);
- }
- ///
- /// 查询终端属性应答
- ///
- ///
- ///
- public virtual byte[] Msg0x0107(JT808HeaderPackage request)
- {
- return CommonReply(request);
- }
- ///
- /// 终端升级结果应答
- ///
- ///
- ///
- public virtual byte[] Msg0x0108(JT808HeaderPackage request)
- {
- return CommonReply(request);
- }
- ///
- /// 位置信息汇报
- ///
- ///
- ///
- ///
- public virtual byte[] Msg0x0200(JT808HeaderPackage request)
- {
- return CommonReply(request);
- }
- ///
- /// 位置信息查询应答
- ///
- ///
- ///
- public virtual byte[] Msg0x0201(JT808HeaderPackage request)
- {
- return CommonReply(request);
- }
- ///
- /// 链路检测
- /// 2019版本
- ///
- ///
- ///
- public virtual byte[] Msg0x8204(JT808HeaderPackage request)
- {
- return default;
- }
- ///
- /// 车辆控制应答
- ///
- ///
- ///
- public virtual byte[] Msg0x0500(JT808HeaderPackage request)
- {
- return CommonReply(request);
- }
- ///
- /// 定位数据批量上传
- ///
- ///
- ///
- public virtual byte[] Msg0x0704(JT808HeaderPackage request)
- {
- return CommonReply(request);
- }
- ///
- /// CAN总线数据上传
- ///
- ///
- ///
- public virtual byte[] Msg0x0705(JT808HeaderPackage request)
- {
- return CommonReply(request);
- }
- ///
- /// 多媒体事件信息上传
- ///
- ///
- ///
- public virtual byte[] Msg0x0800(JT808HeaderPackage request)
- {
- return CommonReply(request);
- }
- ///
- /// 多媒体数据上传
- ///
- ///
- ///
- public virtual byte[] Msg0x0801(JT808HeaderPackage request)
- {
- throw new NotImplementedException("0x8800多媒体数据上传应答");
- }
- ///
- /// 摄像头立即拍摄命令
- ///
- ///
- ///
- public virtual byte[] Msg0x8801(JT808HeaderPackage request)
- {
- throw new NotImplementedException("0x0805摄像头立即拍摄命令应答");
- }
- ///
- /// 数据上行透传
- ///
- ///
- ///
- public virtual byte[] Msg0x0900(JT808HeaderPackage request)
- {
- return CommonReply(request);
- }
- }
-}
diff --git a/src/JT808.Gateway.Benchmark/JT808.Gateway.CleintBenchmark/JT808.Gateway.CleintBenchmark.csproj b/src/JT808.Gateway.Benchmark/JT808.Gateway.CleintBenchmark/JT808.Gateway.CleintBenchmark.csproj
index d2b8bbd..7e2ca47 100644
--- a/src/JT808.Gateway.Benchmark/JT808.Gateway.CleintBenchmark/JT808.Gateway.CleintBenchmark.csproj
+++ b/src/JT808.Gateway.Benchmark/JT808.Gateway.CleintBenchmark/JT808.Gateway.CleintBenchmark.csproj
@@ -12,10 +12,10 @@
-
-
-
-
+
+
+
+
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
index 35a79af..969afbc 100644
--- a/src/JT808.Gateway.Benchmark/JT808.Gateway.ServerBenchmark/JT808.Gateway.ServerBenchmark.csproj
+++ b/src/JT808.Gateway.Benchmark/JT808.Gateway.ServerBenchmark/JT808.Gateway.ServerBenchmark.csproj
@@ -6,8 +6,8 @@
-
-
+
+
diff --git a/src/JT808.Gateway.Client/JT808.Gateway.Client.csproj b/src/JT808.Gateway.Client/JT808.Gateway.Client.csproj
index df8fdcf..8a38222 100644
--- a/src/JT808.Gateway.Client/JT808.Gateway.Client.csproj
+++ b/src/JT808.Gateway.Client/JT808.Gateway.Client.csproj
@@ -22,12 +22,12 @@
-
-
-
-
-
-
+
+
+
+
+
+
diff --git a/src/JT808.Gateway.Client/JT808TcpClient.cs b/src/JT808.Gateway.Client/JT808TcpClient.cs
index 7b8366e..9a10211 100644
--- a/src/JT808.Gateway.Client/JT808TcpClient.cs
+++ b/src/JT808.Gateway.Client/JT808TcpClient.cs
@@ -225,20 +225,15 @@ namespace JT808.Gateway.Client
public void Close()
{
if (disposed) return;
- var socket = clientSocket;
- if (socket == null)
- return;
- if (Interlocked.CompareExchange(ref clientSocket, null, socket) == socket)
+ if (clientSocket == null) return;
+ try
{
- try
- {
- clientSocket.Shutdown(SocketShutdown.Both);
- }
- finally
- {
- clientSocket.Close();
- }
+ clientSocket?.Shutdown(SocketShutdown.Both);
}
+ finally
+ {
+ clientSocket?.Close();
+ }
}
private void Dispose(bool disposing)
diff --git a/src/JT808.Gateway.Kafka/JT808.Gateway.Kafka.csproj b/src/JT808.Gateway.Kafka/JT808.Gateway.Kafka.csproj
index 79ce31c..b3cac6e 100644
--- a/src/JT808.Gateway.Kafka/JT808.Gateway.Kafka.csproj
+++ b/src/JT808.Gateway.Kafka/JT808.Gateway.Kafka.csproj
@@ -26,7 +26,7 @@
JT808.Gateway.Kafka.xml
-
+
diff --git a/src/JT808.Gateway.Services/JT808.Gateway.MsgLogging/JT808.Gateway.MsgLogging.csproj b/src/JT808.Gateway.Services/JT808.Gateway.MsgLogging/JT808.Gateway.MsgLogging.csproj
index a9a8058..2a0c131 100644
--- a/src/JT808.Gateway.Services/JT808.Gateway.MsgLogging/JT808.Gateway.MsgLogging.csproj
+++ b/src/JT808.Gateway.Services/JT808.Gateway.MsgLogging/JT808.Gateway.MsgLogging.csproj
@@ -22,7 +22,7 @@
LICENSE
-
+
diff --git a/src/JT808.Gateway.Services/JT808.Gateway.ReplyMessage/JT808.Gateway.ReplyMessage.csproj b/src/JT808.Gateway.Services/JT808.Gateway.ReplyMessage/JT808.Gateway.ReplyMessage.csproj
index 17f45f4..1953f2d 100644
--- a/src/JT808.Gateway.Services/JT808.Gateway.ReplyMessage/JT808.Gateway.ReplyMessage.csproj
+++ b/src/JT808.Gateway.Services/JT808.Gateway.ReplyMessage/JT808.Gateway.ReplyMessage.csproj
@@ -21,7 +21,7 @@
LICENSE
-
+
diff --git a/src/JT808.Gateway.Services/JT808.Gateway.SessionNotice/JT808.Gateway.SessionNotice.csproj b/src/JT808.Gateway.Services/JT808.Gateway.SessionNotice/JT808.Gateway.SessionNotice.csproj
index 6c3dd4f..c177de7 100644
--- a/src/JT808.Gateway.Services/JT808.Gateway.SessionNotice/JT808.Gateway.SessionNotice.csproj
+++ b/src/JT808.Gateway.Services/JT808.Gateway.SessionNotice/JT808.Gateway.SessionNotice.csproj
@@ -22,7 +22,7 @@
LICENSE
-
+
diff --git a/src/JT808.Gateway.Services/JT808.Gateway.SessionNotice/JT808SessionNoticeHostedService.cs b/src/JT808.Gateway.Services/JT808.Gateway.SessionNotice/JT808SessionNoticeHostedService.cs
index 44b83db..fcfcbd3 100644
--- a/src/JT808.Gateway.Services/JT808.Gateway.SessionNotice/JT808SessionNoticeHostedService.cs
+++ b/src/JT808.Gateway.Services/JT808.Gateway.SessionNotice/JT808SessionNoticeHostedService.cs
@@ -1,6 +1,4 @@
using System.Threading.Tasks;
-using JT808.Protocol;
-using JT808.Protocol.Interfaces;
using Microsoft.Extensions.Hosting;
using System.Threading;
using JT808.Gateway.Abstractions;
diff --git a/src/JT808.Gateway.Services/JT808.Gateway.SessionNotice/JT808SessionNoticeService.cs b/src/JT808.Gateway.Services/JT808.Gateway.SessionNotice/JT808SessionNoticeService.cs
index f76aee9..a3d9735 100644
--- a/src/JT808.Gateway.Services/JT808.Gateway.SessionNotice/JT808SessionNoticeService.cs
+++ b/src/JT808.Gateway.Services/JT808.Gateway.SessionNotice/JT808SessionNoticeService.cs
@@ -1,8 +1,4 @@
-using Microsoft.Extensions.Configuration;
-using Microsoft.Extensions.Logging;
-using System;
-using System.Collections.Generic;
-using System.Text;
+using Microsoft.Extensions.Logging;
namespace JT808.Gateway.SessionNotice
{
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
index 95469d6..5085888 100644
--- a/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Configs/nlog.Unix.config
+++ b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Configs/nlog.Unix.config
@@ -31,6 +31,6 @@
-
+
\ 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
index a4e9705..f6fe59d 100644
--- a/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Configs/nlog.Win32NT.config
+++ b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Configs/nlog.Win32NT.config
@@ -31,6 +31,6 @@
-
+
\ No newline at end of file
diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Impl/JT808CustomMessageHandlerImpl.cs b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Impl/JT808CustomMessageHandlerImpl.cs
index b22f357..7bd388e 100644
--- a/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Impl/JT808CustomMessageHandlerImpl.cs
+++ b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Impl/JT808CustomMessageHandlerImpl.cs
@@ -14,7 +14,7 @@ namespace JT808.Gateway.NormalHosting.Impl
public class JT808CustomMessageHandlerImpl : JT808MessageHandler
{
private readonly ILogger logger;
- //private readonly JT808TransmitService jT808TransmitService;
+ private readonly JT808TransmitService jT808TransmitService;
private readonly IJT808MsgLogging jT808MsgLogging;
private readonly IJT808MsgReplyProducer MsgReplyProducer;
@@ -25,13 +25,14 @@ namespace JT808.Gateway.NormalHosting.Impl
IOptionsMonitor jT808ConfigurationOptionsMonitor,
IJT808MsgProducer msgProducer,
IJT808MsgReplyLoggingProducer msgReplyLoggingProducer,
+ JT808TransmitService jT808TransmitService,
IJT808Config jT808Config) : base(jT808ConfigurationOptionsMonitor,
msgProducer,
msgReplyLoggingProducer,
jT808Config)
{
MsgReplyProducer = msgReplyProducer;
- //this.jT808TransmitService = jT808TransmitService;
+ this.jT808TransmitService = jT808TransmitService;
this.jT808MsgLogging = jT808MsgLogging;
logger = loggerFactory.CreateLogger();
//添加自定义消息
@@ -53,15 +54,13 @@ namespace JT808.Gateway.NormalHosting.Impl
{
//AOP 可以自定义添加一些东西:上下行日志、
logger.LogDebug("可以自定义添加一些东西:上下行日志、数据转发");
- //流量
- //jT808Traffic.Increment(request.Header.TerminalPhoneNo, DateTime.Now.ToString("yyyyMMdd"), request.OriginalData.Length);
var parameter = (request.Header.TerminalPhoneNo, request.OriginalData.ToArray());
- ////上行日志(可同步也可以使用队列进行异步)
- //jT808MsgLogging.Processor(parameter, JT808MsgLoggingType.up);
- ////下行日志(可同步也可以使用队列进行异步)
+ //上行日志(可同步也可以使用队列进行异步)
+ jT808MsgLogging.Processor(parameter, JT808MsgLoggingType.up);
+ //下行日志(可同步也可以使用队列进行异步)
jT808MsgLogging.Processor((request.Header.TerminalPhoneNo, down), JT808MsgLoggingType.down);
- ////转发数据(可同步也可以使用队列进行异步)
- //jT808TransmitService.SendAsync(parameter);
+ //转发数据(可同步也可以使用队列进行异步)
+ jT808TransmitService.SendAsync(parameter);
}
catch (Exception)
{
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
index f2d3c72..ae07c0a 100644
--- a/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/JT808.Gateway.NormalHosting.csproj
+++ b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/JT808.Gateway.NormalHosting.csproj
@@ -5,14 +5,10 @@
netcoreapp3.1
-
-
-
-
-
-
+
+
@@ -22,6 +18,7 @@
+
diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Jobs/CallGrpcClientJob.cs b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Jobs/CallGrpcClientJob.cs
deleted file mode 100644
index b2127ef..0000000
--- a/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Jobs/CallGrpcClientJob.cs
+++ /dev/null
@@ -1,76 +0,0 @@
-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;
-using JT808.Protocol.Extensions;
-using Microsoft.Extensions.Options;
-
-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,
- IOptions configurationAccessor)
- {
- Logger = loggerFactory.CreateLogger("CallGrpcClientJob");
- channel = new Channel($"{configurationAccessor.Value.WebApiHost}:{configurationAccessor.Value.WebApiPort}",
- ChannelCredentials.Insecure);
- AuthMetadata = new Grpc.Core.Metadata();
- AuthMetadata.Add("token", configurationAccessor.Value.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);
- var result3 = jT808GatewayClient.UnificationSend(new UnificationSendRequest
- {
- TerminalPhoneNo= "123456789012",
- Data=Google.Protobuf.ByteString.CopyFrom("7E02000026123456789012007D02000000010000000200BA7F0E07E4F11C0028003C00001810151010100104000000640202007D01137E".ToHexBytes())
- }, 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.NormalHosting/Jobs/CallHttpClientJob.cs b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Jobs/CallHttpClientJob.cs
new file mode 100644
index 0000000..c2c4dd4
--- /dev/null
+++ b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Jobs/CallHttpClientJob.cs
@@ -0,0 +1,54 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using Microsoft.Extensions.Hosting;
+using Microsoft.Extensions.Logging;
+using System.Text.Json;
+using JT808.Protocol.Extensions;
+using Microsoft.Extensions.Options;
+using JT808.Gateway.Abstractions.Configurations;
+using JT808.Gateway.WebApiClientTool;
+
+namespace JT808.Gateway.NormalHosting.Jobs
+{
+ public class CallHttpClientJob :IHostedService
+ {
+
+ private readonly ILogger Logger;
+ private JT808HttpClient jT808HttpClient;
+ public CallHttpClientJob(
+ ILoggerFactory loggerFactory,
+ JT808HttpClient jT808HttpClient)
+ {
+ Logger = loggerFactory.CreateLogger();
+ this.jT808HttpClient = jT808HttpClient;
+ }
+
+ public Task StartAsync(CancellationToken cancellationToken)
+ {
+ Task.Run(async() =>
+ {
+ while (!cancellationToken.IsCancellationRequested)
+ {
+ var result2 = await jT808HttpClient.GetTcpSessionAll();
+ var result3 = await jT808HttpClient.UnificationSend(new Abstractions.Dtos.JT808UnificationSendRequestDto
+ {
+ TerminalPhoneNo= "123456789012",
+ HexData= "7E02000026123456789012007D02000000010000000200BA7F0E07E4F11C0028003C00001810151010100104000000640202007D01137E"
+ });
+ Logger.LogInformation($"[GetTcpAtomicCounter]:{JsonSerializer.Serialize(result2)}");
+ Logger.LogInformation($"[GetTcpSessionAll]:{JsonSerializer.Serialize(result3)}");
+ Thread.Sleep(3000);
+ }
+ }, cancellationToken);
+ return Task.CompletedTask;
+ }
+
+ public Task StopAsync(CancellationToken cancellationToken)
+ {
+ return Task.CompletedTask;
+ }
+ }
+}
diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Program.cs b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Program.cs
index 08e07b0..e4c9c17 100644
--- a/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Program.cs
+++ b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Program.cs
@@ -14,6 +14,7 @@ using JT808.Gateway.Abstractions;
using JT808.Gateway.SessionNotice;
using JT808.Gateway.Client;
using JT808.Gateway.NormalHosting.Jobs;
+using JT808.Gateway.WebApiClientTool;
namespace JT808.Gateway.NormalHosting
{
@@ -48,23 +49,23 @@ namespace JT808.Gateway.NormalHosting
services.AddSingleton();
services.AddJT808Configure()
//添加客户端工具
- //.AddClient()
+ .AddClient()
+ .Builder()
.AddGateway(hostContext.Configuration)
.AddMessageHandler()
.AddMsgReplyConsumer()
.AddMsgLogging()
- //.AddSessionNotice()
- //.AddTransmit(hostContext.Configuration)
+ .AddSessionNotice()
+ .AddTransmit(hostContext.Configuration)
.AddTcp()
- //.AddUdp()
+ .AddUdp()
.AddHttp()
.Register();//必须注册的
- //流量统计
- //services.AddHostedService();
- //grpc客户端调用
- //services.AddHostedService();
+ services.AddJT808WebApiClientTool(hostContext.Configuration);
+ //httpclient客户端调用
+ services.AddHostedService();
//客户端测试 依赖AddClient()服务
- //services.AddHostedService();
+ services.AddHostedService();
});
await serverHostBuilder.RunConsoleAsync();
diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/appsettings.json b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/appsettings.json
index 97d513e..b6938ce 100644
--- a/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/appsettings.json
+++ b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/appsettings.json
@@ -3,9 +3,14 @@
"TcpPort": 808,
"UdpPort": 808,
"WebApiPort": 828,
+ "Token": "123456",
"MiniNumBufferSize": 51200,
"SoBacklog": 65535
},
+ "JT808WebApiClientToolConfig": {
+ "Token": "123456",
+ "Uri": "http://127.0.0.1:828/"
+ },
"RemoteServerOptions": {
"DataTransfer": [
{
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
index 95469d6..5085888 100644
--- a/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/Configs/nlog.Unix.config
+++ b/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/Configs/nlog.Unix.config
@@ -31,6 +31,6 @@
-
+
\ 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
index a4e9705..f6fe59d 100644
--- a/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/Configs/nlog.Win32NT.config
+++ b/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/Configs/nlog.Win32NT.config
@@ -31,6 +31,6 @@
-
+
\ No newline at end of file
diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/JT808.Gateway.QueueHosting.csproj b/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/JT808.Gateway.QueueHosting.csproj
index 0852ba0..4dd4b02 100644
--- a/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/JT808.Gateway.QueueHosting.csproj
+++ b/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/JT808.Gateway.QueueHosting.csproj
@@ -10,8 +10,8 @@
-
-
+
+
@@ -23,6 +23,7 @@
+
diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/Jobs/CallGrpcClientJob.cs b/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/Jobs/CallGrpcClientJob.cs
deleted file mode 100644
index 2572bbb..0000000
--- a/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/Jobs/CallGrpcClientJob.cs
+++ /dev/null
@@ -1,69 +0,0 @@
-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.QueueHosting.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.QueueHosting/Jobs/CallHttpClientJob.cs b/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/Jobs/CallHttpClientJob.cs
new file mode 100644
index 0000000..c81da0a
--- /dev/null
+++ b/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/Jobs/CallHttpClientJob.cs
@@ -0,0 +1,54 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using Microsoft.Extensions.Hosting;
+using Microsoft.Extensions.Logging;
+using System.Text.Json;
+using JT808.Gateway.Abstractions.Configurations;
+using JT808.Gateway.WebApiClientTool;
+
+namespace JT808.Gateway.QueueHosting.Jobs
+{
+ public class CallHttpClientJob : IHostedService
+ {
+
+ private readonly ILogger Logger;
+ private JT808HttpClient jT808HttpClient;
+ public CallHttpClientJob(
+ ILoggerFactory loggerFactory,
+ JT808HttpClient jT808HttpClient)
+ {
+ Logger = loggerFactory.CreateLogger();
+ this.jT808HttpClient = jT808HttpClient;
+ }
+
+ public Task StartAsync(CancellationToken cancellationToken)
+ {
+ Task.Run(async() =>
+ {
+ while (!cancellationToken.IsCancellationRequested)
+ {
+
+ try
+ {
+ var result2 = await jT808HttpClient.GetTcpSessionAll();
+ Logger.LogInformation($"[GetTcpSessionAll]:{JsonSerializer.Serialize(result2)}");
+ }
+ catch (Exception ex)
+ {
+ Logger.LogError(ex, "Call HttpClient Error");
+ }
+ Thread.Sleep(3000);
+ }
+ }, cancellationToken);
+ return Task.CompletedTask;
+ }
+
+ public Task StopAsync(CancellationToken cancellationToken)
+ {
+ return Task.CompletedTask;
+ }
+ }
+}
diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/Program.cs b/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/Program.cs
index 7277d8a..428e894 100644
--- a/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/Program.cs
+++ b/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/Program.cs
@@ -14,6 +14,7 @@ using JT808.Gateway.SessionNotice;
using JT808.Gateway.Client;
using JT808.Gateway.QueueHosting.Jobs;
using JT808.Gateway.Kafka;
+using JT808.Gateway.WebApiClientTool;
namespace JT808.Gateway.QueueHosting
{
@@ -40,18 +41,6 @@ namespace JT808.Gateway.QueueHosting
services.AddSingleton();
services.AddSingleton(typeof(ILogger<>), typeof(Logger<>));
services.AddJT808Configure()
- //.AddQueueGateway(options =>
- //{
- // options.TcpPort = 808;
- // options.UdpPort = 808;
- //})
- .AddGateway(hostContext.Configuration)
- .AddServerKafkaMsgProducer(hostContext.Configuration)
- .AddServerKafkaSessionProducer(hostContext.Configuration)
- .AddServerKafkaMsgReplyConsumer(hostContext.Configuration)
- .AddTcp()
- .AddUdp()
- .Builder()
//添加客户端工具
.AddClient()
.AddClientReport()
@@ -61,11 +50,20 @@ namespace JT808.Gateway.QueueHosting
.AddMsgConsumer(hostContext.Configuration)
//添加消息应答服务
.AddMsgReplyProducer(hostContext.Configuration)
+ .Builder()
//添加消息应答处理
- //.AddReplyMessage()
- ;
- //grpc客户端调用
- //services.AddHostedService();
+ //.AddReplyMessage();
+ .AddGateway(hostContext.Configuration)
+ .AddServerKafkaMsgProducer(hostContext.Configuration)
+ .AddServerKafkaSessionProducer(hostContext.Configuration)
+ .AddServerKafkaMsgReplyConsumer(hostContext.Configuration)
+ .AddTcp()
+ .AddUdp()
+ .AddHttp()
+ .Register();//必须注册的
+ services.AddJT808WebApiClientTool(hostContext.Configuration);
+ //httpclient客户端调用
+ services.AddHostedService();
//客户端测试
services.AddHostedService();
});
diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/appsettings.json b/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/appsettings.json
index e5d7c33..45067e7 100644
--- a/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/appsettings.json
+++ b/src/JT808.Gateway.Tests/JT808.Gateway.QueueHosting/appsettings.json
@@ -2,9 +2,15 @@
"JT808Configuration": {
"TcpPort": 808,
"UdpPort": 808,
+ "WebApiPort": 828,
+ "Token": "123456",
"MiniNumBufferSize": 51200,
"SoBacklog": 65535
},
+ "JT808WebApiClientToolConfig": {
+ "Token": "123456",
+ "Uri": "http://127.0.0.1:828/"
+ },
"JT808MsgProducerConfig": {
"TopicName": "JT808Msg",
"BootstrapServers": "127.0.0.1:9092"
diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.Test/JT808.Gateway.Test.csproj b/src/JT808.Gateway.Tests/JT808.Gateway.Test/JT808.Gateway.Test.csproj
index 06bb3fd..404196c 100644
--- a/src/JT808.Gateway.Tests/JT808.Gateway.Test/JT808.Gateway.Test.csproj
+++ b/src/JT808.Gateway.Tests/JT808.Gateway.Test/JT808.Gateway.Test.csproj
@@ -7,11 +7,11 @@
-
-
-
+
+
+
-
+
all
diff --git a/src/JT808.Gateway.WebApiClientTool/JT808.Gateway.WebApiClientTool.csproj b/src/JT808.Gateway.WebApiClientTool/JT808.Gateway.WebApiClientTool.csproj
index f38f02d..db15dd7 100644
--- a/src/JT808.Gateway.WebApiClientTool/JT808.Gateway.WebApiClientTool.csproj
+++ b/src/JT808.Gateway.WebApiClientTool/JT808.Gateway.WebApiClientTool.csproj
@@ -29,7 +29,7 @@
-
+
diff --git a/src/JT808.Gateway/JT808.Gateway.csproj b/src/JT808.Gateway/JT808.Gateway.csproj
index 1e1c236..75a7a4c 100644
--- a/src/JT808.Gateway/JT808.Gateway.csproj
+++ b/src/JT808.Gateway/JT808.Gateway.csproj
@@ -31,7 +31,7 @@
-
+
diff --git a/src/JT808.Gateway/JT808UdpServer.cs b/src/JT808.Gateway/JT808UdpServer.cs
index c21b320..b7f5d85 100644
--- a/src/JT808.Gateway/JT808UdpServer.cs
+++ b/src/JT808.Gateway/JT808UdpServer.cs
@@ -65,6 +65,10 @@ namespace JT808.Gateway
SocketReceiveMessageFromResult result = await server.ReceiveMessageFromAsync(segment, SocketFlags.None, LocalIPEndPoint);
ReaderBuffer(buffer.AsSpan(0, result.ReceivedBytes), server, result);
}
+ catch(System.ObjectDisposedException ex)
+ {
+ //Logger.LogInformation("Socket Received Bytes Close");
+ }
catch(AggregateException ex)
{
Logger.LogError(ex, "Receive MessageFrom Async");
diff --git a/src/Version.props b/src/Version.props
index 2d7bdef..5444c47 100644
--- a/src/Version.props
+++ b/src/Version.props
@@ -1,6 +1,6 @@
2.3.2
- 1.0.2-preview1
+ 1.0.2-preview2
\ No newline at end of file