@@ -21,18 +21,62 @@ | |||
 | |||
## 集成功能实现 | |||
## 基于Tcp的消息业务处理程序(JT808.DotNetty.Tcp) | |||
### 1.集成原包分发器 | |||
通过继承JT808.DotNetty.Core.Handlers.JT808MsgIdTcpHandlerBase去实现自定义的消息业务处理程序。 | |||
### 2.集成WebApi服务器 | |||
## 基于Udp的消息业务处理程序(JT808.DotNetty.Udp) | |||
[WebApi接口服务](https://github.com/SmallChi/JT808DotNetty/blob/master/api/README.md) | |||
通过继承JT808.DotNetty.Core.Handlers.JT808MsgIdUdpHandlerBase去实现自定义的消息业务处理程序。 | |||
### 3.集成会话通知(在线/离线) | |||
## 基于WebApi的消息业务处理程序(JT808.DotNetty.WebApi) | |||
使用场景:有些超长待机的设备,不会实时保持连接,那么通过平台下发的命令是无法到达的,这时候就需要设备一上线,就即时通知服务去处理,然后在即时的下发消息到设备。 | |||
通过继承JT808.DotNetty.Core.Handlers.JT808MsgIdHttpHandlerBase去实现自定义的WebApi接口服务。 | |||
[WebApi公共接口服务](https://github.com/SmallChi/JT808DotNetty/blob/master/api/README.md) | |||
## 集成接口功能(JT808.DotNetty.Abstractions) | |||
|接口名称|接口说明|使用场景| | |||
|:------:|:------|:------| | |||
| IJT808SessionPublishing| 会话通知(在线/离线)| 有些超长待机的设备,不会实时保持连接,那么通过平台下发的命令是无法到达的,这时候就需要设备一上线,就即时通知服务去处理,然后在即时的下发消息到设备。| | |||
| IJT808SourcePackageDispatcher| 原包分发器| 需要将源数据转给其他平台| | |||
> 只要实现IJT808SessionPublishing接口的任意一款MQ都能实现该功能。 | |||
### 4.集成业务消息处理程序 | |||
## 参考1 | |||
``` demo1 | |||
static async Task Main(string[] args) | |||
{ | |||
var serverHostBuilder = new HostBuilder() | |||
.ConfigureAppConfiguration((hostingContext, config) => | |||
{ | |||
config.SetBasePath(AppDomain.CurrentDomain.BaseDirectory); | |||
config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); | |||
}) | |||
.ConfigureLogging((context, logging) => | |||
{ | |||
logging.AddConsole(); | |||
logging.SetMinimumLevel(LogLevel.Trace); | |||
}) | |||
.ConfigureServices((hostContext, services) => | |||
{ | |||
services.AddSingleton<ILoggerFactory, LoggerFactory>(); | |||
services.AddSingleton(typeof(ILogger<>), typeof(Logger<>)) | |||
services.AddJT808Core(hostContext.Configuration) | |||
.AddJT808TcpHost() | |||
.AddJT808UdpHost() | |||
.AddJT808WebApiHost(); | |||
// 自定义Tcp消息处理业务 | |||
services.Replace(new ServiceDescriptor(typeof(JT808MsgIdTcpHandlerBase), typeof(JT808MsgIdTcpCustomHandler), ServiceLifetime.Singleton)); | |||
// 自定义Udp消息处理业务 | |||
services.Replace(new ServiceDescriptor(typeof(JT808MsgIdUdpHandlerBase), typeof(JT808MsgIdUdpCustomHandler), ServiceLifetime.Singleton)); | |||
}); | |||
await serverHostBuilder.RunConsoleAsync(); | |||
} | |||
``` | |||
如图所示: | |||
 |
@@ -6,15 +6,27 @@ | |||
默认端口:828 | |||
## [统一下发设备消息服务](#send) | |||
## 1.统一下发设备消息服务 | |||
## [管理会话服务](#session) | |||
[基于Tcp统一下发设备消息服务](#tcp_send) | |||
## [原包分发器通道服务](#sourcepackage) | |||
[基于Udp统一下发设备消息服务](#udp_send) | |||
## [转发地址过滤服务](#transmit) | |||
## 2.管理会话服务 | |||
## [消息包计数服务](#counter) | |||
[基于Tcp管理会话服务](#tcp_session) | |||
[基于Udp管理会话服务](#udp_session) | |||
## 3.转发地址过滤服务 | |||
[基于Tcp转发地址过滤服务](#tcp_transmit) | |||
## 4.消息包计数服务 | |||
[基于Tcp消息包计数服务](#tcp_counter) | |||
[基于Udp消息包计数服务](#udp_counter) | |||
### 统一对象返回 JT808ResultDto\<T> | |||
@@ -33,9 +45,38 @@ | |||
| 404 | 没有该服务 | | |||
| 500 | 服务内部错误 | | |||
### <span id="send">统一下发设备消息接口</span> | |||
### <span id="tcp_send">基于Tcp统一下发设备消息服务</span> | |||
请求地址:UnificationTcpSend | |||
请求方式:POST | |||
请求参数: | |||
|属性|数据类型|参数说明| | |||
|------|:------:|:------| | |||
| TerminalPhoneNo| string| 设备终端号| | |||
| Data| byte[]| JT808 byte[]数组| | |||
返回数据: | |||
|属性|数据类型|参数说明| | |||
|:------:|:------:|:------| | |||
| Data| bool| 是否成功| | |||
返回结果: | |||
``` result1 | |||
{ | |||
"Message":"", | |||
"Code":200, | |||
"Data":true | |||
} | |||
``` | |||
### <span id="udp_send">基于Udp统一下发设备消息服务</span> | |||
请求地址:UnificationSend | |||
请求地址:UnificationUdpSend | |||
请求方式:POST | |||
@@ -62,13 +103,12 @@ | |||
} | |||
``` | |||
### <span id="session">会话服务接口</span> | |||
### <span id="tcp_session">基于Tcp管理会话服务</span> | |||
#### 统一会话信息对象返回 JT808SessionInfoDto | |||
#### 统一会话信息对象返回 JT808TcpSessionInfoDto | |||
|属性|数据类型|参数说明| | |||
|------|------|------| | |||
| ChannelId| string| 通道Id| | |||
| LastActiveTime| DateTime| 最后上线时间| | |||
| StartTime| DateTime| 上线时间| | |||
| TerminalPhoneNo|string| 终端手机号| | |||
@@ -76,7 +116,7 @@ | |||
#### 1.获取会话集合 | |||
请求地址:Session/GetAll | |||
请求地址:Session/Tcp/GetAll | |||
请求方式:GET | |||
@@ -84,7 +124,7 @@ | |||
|属性|数据类型|参数说明| | |||
|:------:|:------:|:------| | |||
| Data| List\<JT808SessionInfoDto> | 实际会话信息集合 | | |||
| Data| List\<JT808TcpSessionInfoDto> | 实际会话信息集合 | | |||
返回结果: | |||
@@ -94,13 +134,11 @@ | |||
"Code":200, | |||
"Data":[ | |||
{ | |||
"ChannelId":"eadad23", | |||
"LastActiveTime":"2018-11-27 20:00:00", | |||
"StartTime":"2018-11-25 20:00:00", | |||
"TerminalPhoneNo":"123456789012", | |||
"RemoteAddressIP":"127.0.0.1:11808" | |||
},{ | |||
"ChannelId":"eadad23", | |||
"LastActiveTime":"2018-11-27 20:00:00", | |||
"StartTime":"2018-11-25 20:00:00", | |||
"TerminalPhoneNo":"123456789013", | |||
@@ -112,7 +150,7 @@ | |||
#### 2.通过设备终端号移除对应会话 | |||
请求地址:Session/RemoveByTerminalPhoneNo | |||
请求地址:Session/Tcp/RemoveByTerminalPhoneNo | |||
请求方式:POST | |||
@@ -138,11 +176,11 @@ | |||
} | |||
``` | |||
### <span id="sourcepackage">原包分发器通道服务</span> | |||
### <span id="tcp_transmit">基于Tcp转发地址过滤服务</span> | |||
#### 1.添加原包转发地址 | |||
#### 1.添加转发过滤地址 | |||
请求地址:SourcePackage/Add | |||
请求地址:Transmit/Add | |||
请求方式:POST | |||
@@ -161,7 +199,7 @@ | |||
返回结果: | |||
``` sp1 | |||
``` tr1 | |||
{ | |||
"Message":"", | |||
"Code":200, | |||
@@ -169,77 +207,54 @@ | |||
} | |||
``` | |||
#### 2.删除原包转发地址(不能删除在网关服务器配置文件配的地址) | |||
### <span id="udp_session">基于Udp管理会话服务</span> | |||
请求地址:SourcePackage/Remove | |||
请求方式:POST | |||
请求参数: | |||
#### 统一会话信息对象返回 JT808UdpSessionInfoDto | |||
|属性|数据类型|参数说明| | |||
|:------:|:------:|:------| | |||
| Host| string| ip地址| | |||
| Port| int| 端口号| | |||
返回数据: | |||
|属性|数据类型|参数说明| | |||
|:------:|:------:|:------| | |||
| Data| bool | 是否成功| | |||
返回结果: | |||
``` sp2 | |||
{ | |||
"Message":"", | |||
"Code":200, | |||
"Data":true | |||
} | |||
``` | |||
|------|------|------| | |||
| LastActiveTime| DateTime| 最后上线时间| | |||
| StartTime| DateTime| 上线时间| | |||
| TerminalPhoneNo|string| 终端手机号| | |||
| RemoteAddressIP| string| 远程ip地址| | |||
#### 3.获取原包信息集合 | |||
#### 1.获取会话集合 | |||
请求地址:SourcePackage/GetAll | |||
请求地址:Session/Udp/GetAll | |||
请求方式:GET | |||
返回数据: | |||
|属性|数据类型|参数说明| | |||
|------|:------:|:------| | |||
| RemoteAddress| string | 远程ip地址| | |||
| Registered| bool | 通道是否注册| | |||
| Active| bool | 通道是否激活| | |||
| Open| bool | 通道是否打开| | |||
|:------:|:------:|:------| | |||
| Data| List\<JT808UdpSessionInfoDto> | 实际会话信息集合 | | |||
返回结果: | |||
``` sp3 | |||
``` session1 | |||
{ | |||
"Message":"", | |||
"Code":200, | |||
"Data":[ | |||
{ | |||
"RemoteAddress":"127.0.0.1:6665", | |||
"Registered":true, | |||
"Active":true, | |||
"Open":true | |||
{ | |||
"LastActiveTime":"2018-11-27 20:00:00", | |||
"StartTime":"2018-11-25 20:00:00", | |||
"TerminalPhoneNo":"123456789012", | |||
"RemoteAddressIP":"127.0.0.1:11808" | |||
},{ | |||
"RemoteAddress":"127.0.0.1:6667", | |||
"Registered":true, | |||
"Active":true, | |||
"Open":true | |||
"LastActiveTime":"2018-11-27 20:00:00", | |||
"StartTime":"2018-11-25 20:00:00", | |||
"TerminalPhoneNo":"123456789013", | |||
"RemoteAddressIP":"127.0.0.1:11808" | |||
} | |||
] | |||
} | |||
``` | |||
### <span id="transmit">转发地址过滤服务</span> | |||
#### 1.添加转发过滤地址 | |||
#### 2.通过设备终端号移除对应会话 | |||
请求地址:Transmit/Add | |||
请求地址:Session/Udp/RemoveByTerminalPhoneNo | |||
请求方式:POST | |||
@@ -247,8 +262,7 @@ | |||
|属性|数据类型|参数说明| | |||
|:------:|:------:|:------| | |||
| Host| string| ip地址| | |||
| Port| int| 端口号| | |||
| terminalPhoneNo| string| 设备终端号| | |||
返回数据: | |||
@@ -258,7 +272,7 @@ | |||
返回结果: | |||
``` tr1 | |||
``` session3 | |||
{ | |||
"Message":"", | |||
"Code":200, | |||
@@ -320,9 +334,9 @@ | |||
} | |||
``` | |||
### <span id="counter">计数服务接口</span> | |||
### <span id="tcp_counter">基于Tcp消息包计数服务</span> | |||
请求地址:GetAtomicCounter | |||
请求地址:GetTcpAtomicCounter | |||
请求方式:GET | |||
@@ -344,4 +358,30 @@ | |||
"MsgFailCount":0 | |||
} | |||
} | |||
``` | |||
### <span id="udp_counter">基于Udp消息包计数服务</span> | |||
请求地址:GetUdpAtomicCounter | |||
请求方式:GET | |||
返回数据: | |||
|属性|数据类型|参数说明| | |||
|------|:------:|:------| | |||
| MsgSuccessCount| long| 消息包成功数| | |||
| MsgFailCount| long| 消息包失败数| | |||
返回结果: | |||
``` counter | |||
{ | |||
"Message":"", | |||
"Code":200, | |||
"Data":{ | |||
"MsgSuccessCount":1000, | |||
"MsgFailCount":0 | |||
} | |||
} | |||
``` |
@@ -34,11 +34,6 @@ namespace JT808.DotNetty.Core.Configurations | |||
/// </summary> | |||
public int WebApiPort { get; set; } = 828; | |||
/// <summary> | |||
/// 源包分发器配置 | |||
/// </summary> | |||
public List<JT808ClientConfiguration> SourcePackageDispatcherClientConfigurations { get; set; } | |||
/// <summary> | |||
/// 转发远程地址 (可选项)知道转发的地址有利于提升性能 | |||
/// 按照808的消息,有些请求必须要应答,但是转发可以不需要有应答可以节省部分资源包括: | |||
@@ -31,4 +31,10 @@ | |||
<ProjectReference Include="..\JT808.Protocol\src\JT808.Protocol\JT808.Protocol.csproj" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<Reference Include="Microsoft.Extensions.Hosting.Abstractions"> | |||
<HintPath>C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.extensions.hosting.abstractions\2.2.0\lib\netstandard2.0\Microsoft.Extensions.Hosting.Abstractions.dll</HintPath> | |||
</Reference> | |||
</ItemGroup> | |||
</Project> |
@@ -0,0 +1,78 @@ | |||
using Microsoft.Extensions.Hosting; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using System.Threading; | |||
using System.Threading.Tasks; | |||
namespace JT808.DotNetty.Core | |||
{ | |||
/// <summary> | |||
/// | |||
/// <see cref="https://blogs.msdn.microsoft.com/cesardelatorre/2017/11/18/implementing-background-tasks-in-microservices-with-ihostedservice-and-the-backgroundservice-class-net-core-2-x/"/> | |||
/// </summary> | |||
public abstract class JT808BackgroundService : IHostedService, IDisposable | |||
{ | |||
/// <summary> | |||
/// 默认次日过期 | |||
/// </summary> | |||
public virtual TimeSpan DelayTimeSpan | |||
{ | |||
get | |||
{ | |||
DateTime current = DateTime.Now; | |||
#if DEBUG | |||
DateTime tmp = current.AddSeconds(10); | |||
#else | |||
DateTime tmp = current.Date.AddDays(1).AddMilliseconds(-1); | |||
#endif | |||
return tmp.Subtract(current); | |||
} | |||
set { } | |||
} | |||
private Task _executingTask; | |||
private readonly CancellationTokenSource _stoppingCts = new CancellationTokenSource(); | |||
protected abstract Task ExecuteAsync(CancellationToken stoppingToken); | |||
public void Dispose() | |||
{ | |||
_stoppingCts.Cancel(); | |||
} | |||
public virtual Task StartAsync(CancellationToken cancellationToken) | |||
{ | |||
// Store the task we're executing | |||
_executingTask = ExecuteAsync(_stoppingCts.Token); | |||
// If the task is completed then return it, | |||
// this will bubble cancellation and failure to the caller | |||
if (_executingTask.IsCompleted) | |||
{ | |||
return _executingTask; | |||
} | |||
// Otherwise it's running | |||
return Task.CompletedTask; | |||
} | |||
public virtual async Task StopAsync(CancellationToken cancellationToken) | |||
{ | |||
// Stop called without start | |||
if (_executingTask == null) | |||
{ | |||
return; | |||
} | |||
try | |||
{ | |||
// Signal cancellation to the executing method | |||
_stoppingCts.Cancel(); | |||
} | |||
finally | |||
{ | |||
// Wait until the task completes or the stop token triggers | |||
await Task.WhenAny(_executingTask, Task.Delay(Timeout.Infinite,cancellationToken)); | |||
} | |||
} | |||
} | |||
} |
@@ -0,0 +1,35 @@ | |||
using JT808.DotNetty.Core.Services; | |||
using Microsoft.Extensions.Logging; | |||
using System.Threading; | |||
using System.Threading.Tasks; | |||
namespace JT808.DotNetty.Core.Jobs | |||
{ | |||
public class JT808TcpAtomicCouterResetDailyJob : JT808BackgroundService | |||
{ | |||
private readonly ILogger<JT808TcpAtomicCouterResetDailyJob> _logger; | |||
private readonly JT808TcpAtomicCounterService _jT808TcpAtomicCounterService; | |||
public JT808TcpAtomicCouterResetDailyJob( | |||
JT808TcpAtomicCounterService jT808TcpAtomicCounterService, | |||
ILoggerFactory loggerFactory) | |||
{ | |||
_jT808TcpAtomicCounterService = jT808TcpAtomicCounterService; | |||
_logger =loggerFactory.CreateLogger<JT808TcpAtomicCouterResetDailyJob>(); | |||
} | |||
protected override async Task ExecuteAsync(CancellationToken stoppingToken) | |||
{ | |||
_logger.LogInformation($"{nameof(JT808TcpAtomicCouterResetDailyJob)} is starting."); | |||
stoppingToken.Register(() => _logger.LogInformation($"{nameof(JT808TcpAtomicCouterResetDailyJob)} background task is stopping.")); | |||
while (!stoppingToken.IsCancellationRequested) | |||
{ | |||
_logger.LogInformation($"{nameof(JT808TcpAtomicCouterResetDailyJob)} task doing background work."); | |||
_jT808TcpAtomicCounterService.Reset(); | |||
await Task.Delay(DelayTimeSpan, stoppingToken); | |||
} | |||
_logger.LogInformation($"{nameof(JT808TcpAtomicCouterResetDailyJob)} background task is stopping."); | |||
} | |||
} | |||
} |
@@ -0,0 +1,39 @@ | |||
using JT808.DotNetty.Core.Services; | |||
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.DotNetty.Core.Jobs | |||
{ | |||
public class JT808UdpAtomicCouterResetDailyJob : JT808BackgroundService | |||
{ | |||
private readonly ILogger<JT808UdpAtomicCouterResetDailyJob> _logger; | |||
private readonly JT808UdpAtomicCounterService _jT808UdpAtomicCounterService; | |||
public JT808UdpAtomicCouterResetDailyJob( | |||
JT808UdpAtomicCounterService jT808UdpAtomicCounterService, | |||
ILoggerFactory loggerFactory) | |||
{ | |||
_jT808UdpAtomicCounterService = jT808UdpAtomicCounterService; | |||
_logger =loggerFactory.CreateLogger<JT808UdpAtomicCouterResetDailyJob>(); | |||
} | |||
protected override async Task ExecuteAsync(CancellationToken stoppingToken) | |||
{ | |||
_logger.LogInformation($"{nameof(JT808UdpAtomicCouterResetDailyJob)} is starting."); | |||
stoppingToken.Register(() => _logger.LogInformation($"{nameof(JT808UdpAtomicCouterResetDailyJob)} background task is stopping.")); | |||
while (!stoppingToken.IsCancellationRequested) | |||
{ | |||
_logger.LogInformation($"{nameof(JT808UdpAtomicCouterResetDailyJob)} task doing background work."); | |||
_jT808UdpAtomicCounterService.Reset(); | |||
await Task.Delay(DelayTimeSpan, stoppingToken); | |||
} | |||
_logger.LogInformation($"{nameof(JT808UdpAtomicCouterResetDailyJob)} background task is stopping."); | |||
} | |||
} | |||
} |
@@ -18,6 +18,11 @@ namespace JT808.DotNetty.Core.Metadata | |||
this.counter = initialCount; | |||
} | |||
public void Reset() | |||
{ | |||
Interlocked.Exchange(ref counter, 0); | |||
} | |||
public long Increment() | |||
{ | |||
return Interlocked.Increment(ref counter); | |||
@@ -16,6 +16,12 @@ namespace JT808.DotNetty.Core.Services | |||
} | |||
public void Reset() | |||
{ | |||
MsgSuccessCounter.Reset(); | |||
MsgFailCounter.Reset(); | |||
} | |||
public long MsgSuccessIncrement() | |||
{ | |||
return MsgSuccessCounter.Increment(); | |||
@@ -16,6 +16,12 @@ namespace JT808.DotNetty.Core.Services | |||
} | |||
public void Reset() | |||
{ | |||
MsgSuccessCounter.Reset(); | |||
MsgFailCounter.Reset(); | |||
} | |||
public long MsgSuccessIncrement() | |||
{ | |||
return MsgSuccessCounter.Increment(); | |||
@@ -0,0 +1,28 @@ | |||
using JT808.DotNetty.Core; | |||
using JT808.DotNetty.Core.Handlers; | |||
using JT808.DotNetty.Core.Metadata; | |||
using Microsoft.Extensions.Logging; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
namespace JT808.DotNetty.Hosting.Handlers | |||
{ | |||
public class JT808MsgIdTcpCustomHandler : JT808MsgIdTcpHandlerBase | |||
{ | |||
public JT808MsgIdTcpCustomHandler( | |||
ILoggerFactory loggerFactory, | |||
JT808TcpSessionManager sessionManager) : base(sessionManager) | |||
{ | |||
logger = loggerFactory.CreateLogger<JT808MsgIdTcpCustomHandler>(); | |||
} | |||
private readonly ILogger<JT808MsgIdTcpCustomHandler> logger; | |||
public override JT808Response Msg0x0200(JT808Request request) | |||
{ | |||
logger.LogDebug("Tcp_Msg0x0200"); | |||
return base.Msg0x0200(request); | |||
} | |||
} | |||
} |
@@ -0,0 +1,28 @@ | |||
using JT808.DotNetty.Core; | |||
using JT808.DotNetty.Core.Handlers; | |||
using JT808.DotNetty.Core.Metadata; | |||
using Microsoft.Extensions.Logging; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
namespace JT808.DotNetty.Hosting.Handlers | |||
{ | |||
public class JT808MsgIdUdpCustomHandler : JT808MsgIdUdpHandlerBase | |||
{ | |||
public JT808MsgIdUdpCustomHandler( | |||
ILoggerFactory loggerFactory, | |||
JT808UdpSessionManager sessionManager) : base(sessionManager) | |||
{ | |||
logger = loggerFactory.CreateLogger<JT808MsgIdUdpCustomHandler>(); | |||
} | |||
private readonly ILogger<JT808MsgIdUdpCustomHandler> logger; | |||
public override JT808Response Msg0x0200(JT808Request request) | |||
{ | |||
logger.LogDebug("Udp_Msg0x0200"); | |||
return base.Msg0x0200(request); | |||
} | |||
} | |||
} |
@@ -1,4 +1,6 @@ | |||
using JT808.DotNetty.Core; | |||
using JT808.DotNetty.Core.Handlers; | |||
using JT808.DotNetty.Hosting.Handlers; | |||
using JT808.DotNetty.Tcp; | |||
using JT808.DotNetty.Udp; | |||
using JT808.DotNetty.WebApi; | |||
@@ -33,11 +35,15 @@ namespace JT808.DotNetty.Hosting | |||
.ConfigureServices((hostContext, services) => | |||
{ | |||
services.AddSingleton<ILoggerFactory, LoggerFactory>(); | |||
services.AddSingleton(typeof(ILogger<>), typeof(Logger<>)); | |||
services.AddSingleton(typeof(ILogger<>), typeof(Logger<>)); | |||
services.AddJT808Core(hostContext.Configuration) | |||
.AddJT808TcpHost() | |||
.AddJT808UdpHost() | |||
.AddJT808WebApiHost(); | |||
// 自定义Tcp消息处理业务 | |||
services.Replace(new ServiceDescriptor(typeof(JT808MsgIdTcpHandlerBase), typeof(JT808MsgIdTcpCustomHandler), ServiceLifetime.Singleton)); | |||
// 自定义Udp消息处理业务 | |||
services.Replace(new ServiceDescriptor(typeof(JT808MsgIdUdpHandlerBase), typeof(JT808MsgIdUdpCustomHandler), ServiceLifetime.Singleton)); | |||
}); | |||
await serverHostBuilder.RunConsoleAsync(); | |||
@@ -11,6 +11,7 @@ using Newtonsoft.Json; | |||
using System; | |||
using System.Reflection; | |||
using System.Runtime.CompilerServices; | |||
using JT808.DotNetty.Core.Jobs; | |||
[assembly: InternalsVisibleTo("JT808.DotNetty.Tcp.Test")] | |||
@@ -27,6 +28,7 @@ namespace JT808.DotNetty.Tcp | |||
serviceDescriptors.TryAddScoped<JT808TcpConnectionHandler>(); | |||
serviceDescriptors.TryAddScoped<JT808TcpDecoder>(); | |||
serviceDescriptors.TryAddScoped<JT808TcpServerHandler>(); | |||
serviceDescriptors.AddHostedService<JT808TcpAtomicCouterResetDailyJob>(); | |||
serviceDescriptors.AddHostedService<JT808TcpServerHost>(); | |||
return serviceDescriptors; | |||
} | |||
@@ -1,6 +1,7 @@ | |||
using JT808.DotNetty.Core; | |||
using JT808.DotNetty.Core.Codecs; | |||
using JT808.DotNetty.Core.Handlers; | |||
using JT808.DotNetty.Core.Jobs; | |||
using JT808.DotNetty.Core.Services; | |||
using JT808.DotNetty.Udp.Handlers; | |||
using Microsoft.Extensions.DependencyInjection; | |||
@@ -20,6 +21,7 @@ namespace JT808.DotNetty.Udp | |||
serviceDescriptors.TryAddSingleton<JT808MsgIdUdpHandlerBase, JT808MsgIdDefaultUdpHandler>(); | |||
serviceDescriptors.TryAddScoped<JT808UdpDecoder>(); | |||
serviceDescriptors.TryAddScoped<JT808UdpServerHandler>(); | |||
serviceDescriptors.AddHostedService<JT808UdpAtomicCouterResetDailyJob>(); | |||
serviceDescriptors.AddHostedService<JT808UdpServerHost>(); | |||
return serviceDescriptors; | |||
} | |||
@@ -1 +1 @@ | |||
Subproject commit 59070584b9f74902431463ec770b9069429ac633 | |||
Subproject commit 641907ad8373cf62d8973dedf76b84aaa894e52f |