diff --git a/src/JT808.Gateway/Configurations/JT808Configuration.cs b/src/JT808.Gateway.Abstractions/Configurations/JT808Configuration.cs
similarity index 78%
rename from src/JT808.Gateway/Configurations/JT808Configuration.cs
rename to src/JT808.Gateway.Abstractions/Configurations/JT808Configuration.cs
index 898c02a..eac429b 100644
--- a/src/JT808.Gateway/Configurations/JT808Configuration.cs
+++ b/src/JT808.Gateway.Abstractions/Configurations/JT808Configuration.cs
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;
-namespace JT808.Gateway.Configurations
+namespace JT808.Gateway.Abstractions.Configurations
{
public class JT808Configuration
{
@@ -19,7 +19,7 @@ namespace JT808.Gateway.Configurations
/// Tcp读超时
/// 默认10分钟检查一次
///
- public int TcpReaderIdleTimeSeconds { get; set; } = 60*10;
+ public int TcpReaderIdleTimeSeconds { get; set; } = 60 * 10;
///
/// Tcp 60s检查一次
///
@@ -32,5 +32,9 @@ namespace JT808.Gateway.Configurations
/// Udp 60s检查一次
///
public int UdpReceiveTimeoutCheckTimeSeconds { get; set; } = 60;
+ ///
+ /// 网关不做消息业务处理,往队列发送
+ ///
+ public List FilterMsgIdHandlerForQueue { get; set; }
}
}
diff --git a/src/JT808.Gateway.Abstractions/IJT808MsgReplyLoggingConsumer.cs b/src/JT808.Gateway.Abstractions/IJT808MsgReplyLoggingConsumer.cs
new file mode 100644
index 0000000..cef7fb4
--- /dev/null
+++ b/src/JT808.Gateway.Abstractions/IJT808MsgReplyLoggingConsumer.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading;
+
+namespace JT808.Gateway.Abstractions
+{
+ public interface IJT808MsgReplyLoggingConsumer : IJT808PubSub, IDisposable
+ {
+ void OnMessage(Action<(string TerminalNo, byte[] Data)> callback);
+ CancellationTokenSource Cts { get; }
+ void Subscribe();
+ void Unsubscribe();
+ }
+}
diff --git a/src/JT808.Gateway.Abstractions/IJT808MsgReplyLoggingProducer.cs b/src/JT808.Gateway.Abstractions/IJT808MsgReplyLoggingProducer.cs
new file mode 100644
index 0000000..8d687b0
--- /dev/null
+++ b/src/JT808.Gateway.Abstractions/IJT808MsgReplyLoggingProducer.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JT808.Gateway.Abstractions
+{
+ public interface IJT808MsgReplyLoggingProducer : IJT808PubSub, IDisposable
+ {
+ ///
+ ///
+ ///
+ /// 设备终端号
+ /// 808 hex data
+ ValueTask ProduceAsync(string terminalNo, byte[] data);
+ }
+}
diff --git a/src/JT808.Gateway.Abstractions/JT808.Gateway.Abstractions.csproj b/src/JT808.Gateway.Abstractions/JT808.Gateway.Abstractions.csproj
index b356590..aedca9b 100644
--- a/src/JT808.Gateway.Abstractions/JT808.Gateway.Abstractions.csproj
+++ b/src/JT808.Gateway.Abstractions/JT808.Gateway.Abstractions.csproj
@@ -35,6 +35,8 @@
+
+
diff --git a/src/JT808.Gateway.Abstractions/JT808MessageHandler.cs b/src/JT808.Gateway.Abstractions/JT808MessageHandler.cs
index 1421a0e..4bba55a 100644
--- a/src/JT808.Gateway.Abstractions/JT808MessageHandler.cs
+++ b/src/JT808.Gateway.Abstractions/JT808MessageHandler.cs
@@ -5,6 +5,9 @@ using JT808.Protocol.MessageBody;
using System;
using System.Collections.Generic;
using System.Text;
+using System.Threading.Tasks;
+using Microsoft.Extensions.Options;
+using JT808.Gateway.Abstractions.Configurations;
namespace JT808.Gateway.Abstractions
{
@@ -17,9 +20,19 @@ namespace JT808.Gateway.Abstractions
protected delegate byte[] MsgIdMethodDelegate(JT808HeaderPackage package, IJT808Session session);
protected JT808Serializer JT808Serializer { get; }
- public JT808MessageHandler(IJT808Config jT808Config)
+
+ protected IJT808MsgProducer MsgProducer;
+
+ protected IOptionsMonitor JT808ConfigurationOptionsMonitor;
+
+ public JT808MessageHandler(
+ IOptionsMonitor jT808ConfigurationOptionsMonitor,
+ IJT808MsgProducer msgProducer,
+ IJT808Config jT808Config)
{
this.JT808Serializer = jT808Config.GetSerializer();
+ this.MsgProducer = msgProducer;
+ this.JT808ConfigurationOptionsMonitor = jT808ConfigurationOptionsMonitor;
HandlerDict = new Dictionary {
{JT808MsgId.终端通用应答.ToUInt16Value(), Msg0x0001},
{JT808MsgId.终端鉴权.ToUInt16Value(), Msg0x0102},
@@ -39,9 +52,16 @@ namespace JT808.Gateway.Abstractions
{JT808MsgId.摄像头立即拍摄命令.ToUInt16Value(),Msg0x8801 },
{JT808MsgId.多媒体数据上传.ToUInt16Value(),Msg0x0801 },
{JT808MsgId.多媒体事件信息上传.ToUInt16Value(),Msg0x0800 },
- {JT808MsgId.CAN总线数据上传.ToUInt16Value(),Msg0x0705 },
+ {JT808MsgId.CAN总线数据上传.ToUInt16Value(),Msg0x0705 },
};
}
+
+ public JT808MessageHandler(IOptionsMonitor jT808ConfigurationOptionsMonitor
+ , IJT808Config jT808Config) : this(jT808ConfigurationOptionsMonitor, null, jT808Config)
+ {
+
+ }
+
///
/// 消息处理
///
@@ -52,15 +72,38 @@ namespace JT808.Gateway.Abstractions
{
if (HandlerDict.TryGetValue(request.Header.MsgId, out var func))
{
- return func(request, session);
+ if (JT808ConfigurationOptionsMonitor.CurrentValue.FilterMsgIdHandlerForQueue != null)
+ {
+ // 网关不做消息业务处理,往队列发送
+ if (JT808ConfigurationOptionsMonitor.CurrentValue.FilterMsgIdHandlerForQueue.Contains(request.Header.MsgId))
+ {
+ if (MsgProducer != null)
+ {
+ MsgProducer.ProduceAsync(request.Header.TerminalPhoneNo, request.OriginalData.ToArray());
+ }
+ return default;
+ }
+ else
+ {
+ return func(request, session);
+ }
+ }
+ else
+ {
+ return func(request, session);
+ }
+ }
+ else
+ {
+ //处理不了的消息Id统一发队列
+ if (MsgProducer != null)
+ {
+ MsgProducer.ProduceAsync(request.Header.TerminalPhoneNo, request.OriginalData.ToArray());
+ }
+ return default;
}
- return default;
- //else
- //{
- // //处理不了的消息统一回复通用应答
- // return CommonReply(request, session);
- //}
}
+
///
/// 终端通用应答
/// 平台无需回复
@@ -122,7 +165,7 @@ namespace JT808.Gateway.Abstractions
{
byte[] data = JT808Serializer.Serialize(JT808MsgId.查询服务器时间应答.Create(request.Header.TerminalPhoneNo, new JT808_0x8004()
{
- Time=DateTime.Now
+ Time = DateTime.Now
}));
session.Send(data);
return data;
diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Program.cs b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Program.cs
index 3d017d4..4e58ef3 100644
--- a/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Program.cs
+++ b/src/JT808.Gateway.Tests/JT808.Gateway.NormalHosting/Program.cs
@@ -51,7 +51,7 @@ namespace JT808.Gateway.NormalHosting
////{
//// options.TcpPort = 808;
//// options.UdpPort = 808;
- ////})
+ ////})
.AddGateway(hostContext.Configuration)
//.ReplaceNormalReplyMessageHandler()
//.AddMsgLogging()
diff --git a/src/JT808.Gateway.Tests/JT808.Gateway.Test/JT808HttpClientTest.cs b/src/JT808.Gateway.Tests/JT808.Gateway.Test/JT808HttpClientTest.cs
index 5ebb2c9..a618b19 100644
--- a/src/JT808.Gateway.Tests/JT808.Gateway.Test/JT808HttpClientTest.cs
+++ b/src/JT808.Gateway.Tests/JT808.Gateway.Test/JT808HttpClientTest.cs
@@ -50,34 +50,5 @@ namespace JT808.Gateway.Test
//123456789
//http://127.0.0.1:828/jt808api/Udp/Session/QueryUdpSessionByTerminalPhoneNo
}
-
- [Fact]
- public void Test3()
- {
- IServiceCollection serviceDescriptors = new ServiceCollection();
- serviceDescriptors.AddSingleton();
-
- IServiceProvider aa = serviceDescriptors.BuildServiceProvider();
- IServiceCollection sc= aa.GetRequiredService();
- sc.AddSingleton();
-
- IServiceProvider aa1 = serviceDescriptors.BuildServiceProvider();
- B b = aa.GetRequiredService();
- }
- }
-
- public class A
- {
-
- }
-
- public class B
- {
-
- }
-
- public class C
- {
-
}
}
diff --git a/src/JT808.Gateway/Authorization/JT808AuthorizationDefault.cs b/src/JT808.Gateway/Authorization/JT808AuthorizationDefault.cs
index 039938f..2782bbe 100644
--- a/src/JT808.Gateway/Authorization/JT808AuthorizationDefault.cs
+++ b/src/JT808.Gateway/Authorization/JT808AuthorizationDefault.cs
@@ -1,5 +1,5 @@
using JT808.Gateway.Abstractions;
-using JT808.Gateway.Configurations;
+using JT808.Gateway.Abstractions.Configurations;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
diff --git a/src/JT808.Gateway/JT808.Gateway.csproj b/src/JT808.Gateway/JT808.Gateway.csproj
index 09ada4d..8a04f7e 100644
--- a/src/JT808.Gateway/JT808.Gateway.csproj
+++ b/src/JT808.Gateway/JT808.Gateway.csproj
@@ -25,8 +25,6 @@
-
-
diff --git a/src/JT808.Gateway/JT808GatewayExtensions.cs b/src/JT808.Gateway/JT808GatewayExtensions.cs
index baee533..289207b 100644
--- a/src/JT808.Gateway/JT808GatewayExtensions.cs
+++ b/src/JT808.Gateway/JT808GatewayExtensions.cs
@@ -1,6 +1,6 @@
using JT808.Gateway.Abstractions;
using JT808.Gateway.Authorization;
-using JT808.Gateway.Configurations;
+using JT808.Gateway.Abstractions.Configurations;
using JT808.Gateway.Handlers;
using JT808.Gateway.Internal;
using JT808.Gateway.Services;
diff --git a/src/JT808.Gateway/JT808HttpServer.cs b/src/JT808.Gateway/JT808HttpServer.cs
index 085d1cd..fa9d448 100644
--- a/src/JT808.Gateway/JT808HttpServer.cs
+++ b/src/JT808.Gateway/JT808HttpServer.cs
@@ -1,5 +1,5 @@
using JT808.Gateway.Abstractions;
-using JT808.Gateway.Configurations;
+using JT808.Gateway.Abstractions.Configurations;
using JT808.Gateway.Extensions;
using JT808.Gateway.Handlers;
using JT808.Gateway.Session;
diff --git a/src/JT808.Gateway/JT808TcpServer.cs b/src/JT808.Gateway/JT808TcpServer.cs
index eb06588..5304786 100644
--- a/src/JT808.Gateway/JT808TcpServer.cs
+++ b/src/JT808.Gateway/JT808TcpServer.cs
@@ -6,7 +6,7 @@ using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
using JT808.Gateway.Abstractions;
-using JT808.Gateway.Configurations;
+using JT808.Gateway.Abstractions.Configurations;
using JT808.Gateway.Session;
using JT808.Protocol;
using JT808.Protocol.Exceptions;
diff --git a/src/JT808.Gateway/JT808UdpServer.cs b/src/JT808.Gateway/JT808UdpServer.cs
index a66e1d1..0fda03e 100644
--- a/src/JT808.Gateway/JT808UdpServer.cs
+++ b/src/JT808.Gateway/JT808UdpServer.cs
@@ -8,7 +8,7 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using JT808.Gateway.Abstractions;
-using JT808.Gateway.Configurations;
+using JT808.Gateway.Abstractions.Configurations;
using JT808.Gateway.Session;
using JT808.Protocol;
using JT808.Protocol.Exceptions;
diff --git a/src/JT808.Gateway/Services/JT808MsgReplyHostedService.cs b/src/JT808.Gateway/Services/JT808MsgReplyHostedService.cs
index 6af5c31..dff56f4 100644
--- a/src/JT808.Gateway/Services/JT808MsgReplyHostedService.cs
+++ b/src/JT808.Gateway/Services/JT808MsgReplyHostedService.cs
@@ -1,5 +1,5 @@
using JT808.Gateway.Abstractions;
-using JT808.Gateway.Configurations;
+using JT808.Gateway.Abstractions.Configurations;
using JT808.Gateway.Session;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
diff --git a/src/JT808.Gateway/Services/JT808TcpReceiveTimeoutHostedService.cs b/src/JT808.Gateway/Services/JT808TcpReceiveTimeoutHostedService.cs
index 0d9cb89..40dc321 100644
--- a/src/JT808.Gateway/Services/JT808TcpReceiveTimeoutHostedService.cs
+++ b/src/JT808.Gateway/Services/JT808TcpReceiveTimeoutHostedService.cs
@@ -1,4 +1,4 @@
-using JT808.Gateway.Configurations;
+using JT808.Gateway.Abstractions.Configurations;
using JT808.Gateway.Session;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
diff --git a/src/JT808.Gateway/Services/JT808UdpReceiveTimeoutHostedService.cs b/src/JT808.Gateway/Services/JT808UdpReceiveTimeoutHostedService.cs
index b969dd5..3e79fc3 100644
--- a/src/JT808.Gateway/Services/JT808UdpReceiveTimeoutHostedService.cs
+++ b/src/JT808.Gateway/Services/JT808UdpReceiveTimeoutHostedService.cs
@@ -1,4 +1,4 @@
-using JT808.Gateway.Configurations;
+using JT808.Gateway.Abstractions.Configurations;
using JT808.Gateway.Session;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;