From ded12729d9d6f4b4f72ea00d6eb308754e07d6dd Mon Sep 17 00:00:00 2001 From: cli <377476583@qq.com> Date: Wed, 13 Nov 2024 17:50:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ICommandService.cs | 9 ++ ...he.CollectBus.Application.Contracts.csproj | 9 ++ .../CommandService.cs | 116 ++++++++++++++++++ .../JiShe.CollectBus.Application.csproj | 2 + .../JiSheCollectBusApplicationModule.cs | 9 +- .../DependencyInjectionExtensions.cs | 104 ---------------- .../DependencyInjections/IScopedDependency.cs | 6 - .../ISingletonDependency.cs | 6 - .../ITransientDependency.cs | 6 - .../Interfaces/IReceived.cs | 7 ++ .../JiShe.CollectBus.Common.csproj | 10 +- .../Models/MessageIssuedEvent.cs | 2 +- .../Models/MessageReceivedEvent.cs | 8 +- .../ServiceCollectionExtensions.cs | 7 -- .../JiShe.CollectBus.Console.csproj | 5 +- JiShe.CollectBus.Console/Program.cs | 12 +- .../Exceptions/CloseException.cs | 8 +- ...csproj => JiShe.CollectBus.Network.csproj} | 5 +- ...ule.cs => JiSheCollectBusNetworkModule.cs} | 26 ++-- .../{ClosePlugin.cs => CloseMonitor.cs} | 8 +- .../ServerMonitor.cs} | 9 +- .../{TcpServicePlugin.cs => TcpMonitor.cs} | 77 ++++-------- .../{UdpServicePlugin.cs => UdpMonitor.cs} | 4 +- .../Controllers/CommandController.cs | 103 ++-------------- .../ServiceCollectionExtensions.cs | 45 ++++++- .../JiShe.CollectBus.Host.csproj | 12 +- .../JiSheCollectBusHostModule.cs | 26 ++++ JiShe.CollectBus.Host/Program.cs | 19 ++- JiShe.CollectBus.Host/Startup.cs | 47 ++++--- JiShe.CollectBus.Host/appsettings.json | 4 +- .../JiShe.CollectBus.MongoDB.csproj | 2 + .../JiSheCollectBusMongoDBModule.cs | 16 ++- .../MongoBaseRepository.cs | 11 +- .../Abstracts/BaseProtocolPlugin.cs | 2 - .../StandardFixedHeaderDataHandlingAdapter.cs | 2 +- .../{Models => Interfaces}/IProtocolInfo.cs | 2 +- .../Interfaces/IProtocolPlugin.cs | 1 + ...JiShe.CollectBus.Protocol.Contracts.csproj | 1 - .../CustomFixedHeaderRequestInfo.cs | 2 +- .../Models/ProtocolInfo.cs | 4 +- .../TestProtocolPlugin.cs | 3 +- .../JiShe.CollectBus.Protocol.csproj | 2 +- .../JiSheCollectBusProtocolModule.cs | 5 +- .../StandardProtocolPlugin.cs | 5 +- .../MessageReceivedHeartbeatConsumer.cs | 36 ------ .../Consumers/MessageReceivedLoginConsumer.cs | 35 ------ .../{Senders => }/INSender.cs | 2 +- ...proj => JiShe.CollectBus.MQ.Sender.csproj} | 2 - .../JiSheCollectBusMQSenderModule.cs | 17 +++ .../{Senders => }/NSender.cs | 15 ++- .../JiShe.CollectBus.MQ.Consumer.csproj | 20 +++ .../JiSheCollectBusMQConsumerModule.cs | 7 +- .../MessageIssuedConsumer.cs | 4 +- .../MessageIssuedFaultConsumer.cs | 9 +- .../MessageReceivedConsumer.cs | 10 +- .../MessageReceivedFaultConsumer.cs | 9 +- .../MessageReceivedHeartbeatConsumer.cs | 29 +++++ .../MessageReceivedLoginConsumer.cs | 29 +++++ JiShe.CollectBus.Test/BusUnitTest.cs | 3 +- .../JiShe.CollectBus.Test.csproj | 2 +- JiShe.CollectBus.sln | 18 ++- 61 files changed, 521 insertions(+), 495 deletions(-) create mode 100644 JiShe.CollectBus.Application.Contracts/ICommandService.cs create mode 100644 JiShe.CollectBus.Application.Contracts/JiShe.CollectBus.Application.Contracts.csproj create mode 100644 JiShe.CollectBus.Application/CommandService.cs delete mode 100644 JiShe.CollectBus.Common/Extensions/DependencyInjections/DependencyInjectionExtensions.cs delete mode 100644 JiShe.CollectBus.Common/Extensions/DependencyInjections/IScopedDependency.cs delete mode 100644 JiShe.CollectBus.Common/Extensions/DependencyInjections/ISingletonDependency.cs delete mode 100644 JiShe.CollectBus.Common/Extensions/DependencyInjections/ITransientDependency.cs create mode 100644 JiShe.CollectBus.Common/Interfaces/IReceived.cs rename {JiShe.CollectBus.Protocol.Contracts => JiShe.CollectBus.Common}/Models/MessageIssuedEvent.cs (85%) rename {JiShe.CollectBus.Protocol.Contracts => JiShe.CollectBus.Common}/Models/MessageReceivedEvent.cs (85%) rename JiShe.CollectBus.Core/{JiShe.CollectBus.Core.csproj => JiShe.CollectBus.Network.csproj} (70%) rename JiShe.CollectBus.Core/{JiSheCollectBusCoreModule.cs => JiSheCollectBusNetworkModule.cs} (66%) rename JiShe.CollectBus.Core/Plugins/{ClosePlugin.cs => CloseMonitor.cs} (77%) rename JiShe.CollectBus.Core/{Services/BusService.cs => Plugins/ServerMonitor.cs} (84%) rename JiShe.CollectBus.Core/Plugins/{TcpServicePlugin.cs => TcpMonitor.cs} (53%) rename JiShe.CollectBus.Core/Plugins/{UdpServicePlugin.cs => UdpMonitor.cs} (83%) create mode 100644 JiShe.CollectBus.Host/JiSheCollectBusHostModule.cs rename JiShe.CollectBus.Protocol.Contracts/{Models => Interfaces}/IProtocolInfo.cs (91%) rename JiShe.CollectBus.Protocol.Contracts/{Interfaces => Models}/CustomFixedHeaderRequestInfo.cs (95%) delete mode 100644 JiShe.CollectBus.RabbitMQ/Consumers/MessageReceivedHeartbeatConsumer.cs delete mode 100644 JiShe.CollectBus.RabbitMQ/Consumers/MessageReceivedLoginConsumer.cs rename JiShe.CollectBus.RabbitMQ/{Senders => }/INSender.cs (96%) rename JiShe.CollectBus.RabbitMQ/{JiShe.CollectBus.RabbitMQ.csproj => JiShe.CollectBus.MQ.Sender.csproj} (74%) create mode 100644 JiShe.CollectBus.RabbitMQ/JiSheCollectBusMQSenderModule.cs rename JiShe.CollectBus.RabbitMQ/{Senders => }/NSender.cs (79%) create mode 100644 JiShe.CollectBus.Service/JiShe.CollectBus.MQ.Consumer.csproj rename JiShe.CollectBus.RabbitMQ/JiSheCollectBusRabbitMqModule.cs => JiShe.CollectBus.Service/JiSheCollectBusMQConsumerModule.cs (95%) rename {JiShe.CollectBus.RabbitMQ/Consumers => JiShe.CollectBus.Service}/MessageIssuedConsumer.cs (93%) rename {JiShe.CollectBus.RabbitMQ/Consumers => JiShe.CollectBus.Service}/MessageIssuedFaultConsumer.cs (55%) rename {JiShe.CollectBus.RabbitMQ/Consumers => JiShe.CollectBus.Service}/MessageReceivedConsumer.cs (85%) rename {JiShe.CollectBus.RabbitMQ/Consumers => JiShe.CollectBus.Service}/MessageReceivedFaultConsumer.cs (57%) create mode 100644 JiShe.CollectBus.Service/MessageReceivedHeartbeatConsumer.cs create mode 100644 JiShe.CollectBus.Service/MessageReceivedLoginConsumer.cs diff --git a/JiShe.CollectBus.Application.Contracts/ICommandService.cs b/JiShe.CollectBus.Application.Contracts/ICommandService.cs new file mode 100644 index 0000000..bb92045 --- /dev/null +++ b/JiShe.CollectBus.Application.Contracts/ICommandService.cs @@ -0,0 +1,9 @@ +namespace JiShe.CollectBus.Application.Contracts +{ + public interface ICommandService + { + Task AmmeterParameterSendAsync(); + bool AmmeterParameterReading(); + bool ActivePowerIndicationReading(); + } +} diff --git a/JiShe.CollectBus.Application.Contracts/JiShe.CollectBus.Application.Contracts.csproj b/JiShe.CollectBus.Application.Contracts/JiShe.CollectBus.Application.Contracts.csproj new file mode 100644 index 0000000..fa71b7a --- /dev/null +++ b/JiShe.CollectBus.Application.Contracts/JiShe.CollectBus.Application.Contracts.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/JiShe.CollectBus.Application/CommandService.cs b/JiShe.CollectBus.Application/CommandService.cs new file mode 100644 index 0000000..e60b893 --- /dev/null +++ b/JiShe.CollectBus.Application/CommandService.cs @@ -0,0 +1,116 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using JiShe.CollectBus.Application.Contracts; +using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Extensions; +using JiShe.CollectBus.Common.Models; +using JiShe.CollectBus.MQ.Sender; +using Microsoft.Extensions.Logging; +using Volo.Abp.DependencyInjection; + +namespace JiShe.CollectBus.Application +{ + public class CommandService: ICommandService,ISingletonDependency + { + private readonly ILogger _logger; + private readonly INSender _nSender; + + public async Task AmmeterParameterSendAsync() + { + + var listMeter = new List() + { + new AmmeterParameter() + { + Pn = 1, + BaudRate = 3, + Port = 2, + ProtocolType = CommunicationProtocolType.DLT6452007, + Address = "312408006642", + Password = "000000", + RateNumber = 4, + IntegerBitNumber = 4, + DecimalBitNumber = 4, + CollectorAddress = "000000000000", + UserCategoryNumber = 0, + UserSubclassNumber = 0 + } + }; + var bytes = HexStringExtensions.BuildAmmeterParameterSetSendCmd(new ReqParameter2() + { + AFN = AFN.设置参数, + FunCode = (int)CMasterStationFunCode.请求1级数据, + A = "322009872", + Seq = new Seq() + { + TpV = TpV.附加信息域中无时间标签, + FIRFIN = FIRFIN.单帧, + CON = CON.需要对该帧进行确认, + PRSEQ = 10, + }, + MSA = 13, + Pn = 0, + Fn = 10 + }, listMeter); + + await _nSender.SendToIssuedAsync(new MessageIssuedEvent { DeviceNo = "322009872", Message = bytes, Type = IssuedEventType.Data, MessageId = Guid.NewGuid().ToString() }); + return true; + } + + public bool AmmeterParameterReading() + { + HexStringExtensions.BuildAmmeterParameterReadingSendCmd(new ReqParameter2() + { + AFN = AFN.查询参数, + FunCode = (int)CMasterStationFunCode.请求2级数据, + A = "322009872", + Seq = new Seq() + { + TpV = TpV.附加信息域中无时间标签, + FIRFIN = FIRFIN.单帧, + CON = CON.不需要对该帧进行确认, + PRSEQ = 2, + }, + MSA = 13, + Pn = 0, + Fn = 10 + }, new List() { 1, 2 }); + + return true; + } + + public bool ActivePowerIndicationReading() + { + + //var str = "68A600A6006888203290261A0A6200000201010001000100621E426622082431000000000000040300000000000000CA16"; + //var cmdResult = new BuildCommand().AnalysisCmd(str); + //if(cmdResult != null) + //{ + // var list = new BuildCommand().AnalysisAFN04F10DataUnit(cmdResult.HexDatas); + //} + HexStringExtensions.BuildSendCommandBytes(new ReqParameter2() + { + AFN = AFN.请求实时数据, + FunCode = (int)CMasterStationFunCode.请求2级数据, + A = "322009872", + Seq = new Seq() + { + TpV = TpV.附加信息域中无时间标签, + FIRFIN = FIRFIN.单帧, + CON = CON.不需要对该帧进行确认, + PRSEQ = 2, + }, + MSA = 13, + Pn = 1, + Fn = 129 + }); + + //HexStringExtensions.AmmeterValveControl("312408006642", "", "000000", true); + + return true; + } + } +} diff --git a/JiShe.CollectBus.Application/JiShe.CollectBus.Application.csproj b/JiShe.CollectBus.Application/JiShe.CollectBus.Application.csproj index c4b0c04..f40c0e1 100644 --- a/JiShe.CollectBus.Application/JiShe.CollectBus.Application.csproj +++ b/JiShe.CollectBus.Application/JiShe.CollectBus.Application.csproj @@ -11,7 +11,9 @@ + + diff --git a/JiShe.CollectBus.Application/JiSheCollectBusApplicationModule.cs b/JiShe.CollectBus.Application/JiSheCollectBusApplicationModule.cs index 9435dca..4ff24bc 100644 --- a/JiShe.CollectBus.Application/JiSheCollectBusApplicationModule.cs +++ b/JiShe.CollectBus.Application/JiSheCollectBusApplicationModule.cs @@ -1,16 +1,23 @@ -using System.Reflection; +using System.Collections.Generic; +using System.Reflection; using Hangfire; using JiShe.CollectBus.Common.Jobs; +using JiShe.CollectBus.MQ.Sender; +using MassTransit; using Microsoft.Extensions.DependencyInjection; using Volo.Abp; using Volo.Abp.Modularity; namespace JiShe.CollectBus.Application { + [DependsOn(typeof(JiSheCollectBusMqSenderModule))] public class JiSheCollectBusApplicationModule: AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) { + + context.Services.AddSingleton(); + //var configuration = context.Services.GetConfiguration(); //context.Services.AddJobs(configuration); } diff --git a/JiShe.CollectBus.Common/Extensions/DependencyInjections/DependencyInjectionExtensions.cs b/JiShe.CollectBus.Common/Extensions/DependencyInjections/DependencyInjectionExtensions.cs deleted file mode 100644 index c8197ea..0000000 --- a/JiShe.CollectBus.Common/Extensions/DependencyInjections/DependencyInjectionExtensions.cs +++ /dev/null @@ -1,104 +0,0 @@ -//using JiShe.CollectBus.Common.Extensions.DependencyInjections; -//using System.Reflection; -//using JiShe.CollectBus.Common.Abstractions; -//using Microsoft.Extensions.Hosting; -//using System; -//using Microsoft.Extensions.Configuration; -//using Serilog; - -//// ReSharper disable once CheckNamespace -//namespace Microsoft.Extensions.DependencyInjection -//{ -// public static class DependencyInjectionExtensions -// { -// public static IServiceCollection ModuleRegister(this IServiceCollection services, IConfiguration configuration) -// { -// var assemblies = GetBinAssemblies(); - -// foreach (var assembly in assemblies) -// { -// var allTypes = assembly.GetTypes(); -// foreach (var type in allTypes) -// { -// if (typeof(IJiSheModule).IsAssignableFrom(type) && type is { IsClass: true, IsAbstract: false }) -// { -// Log.Logger.Information($"正在加载模块{type.Name}..."); -// var instance = Activator.CreateInstance(type); -// _ = (type.GetMethod("ConfigureServices")?.Invoke(instance, [services, configuration])); -// } -// } -// } - -// return services; -// } - -// public static IServiceCollection ServiceRegister(this IServiceCollection services) -// { -// var assemblies = GetBinAssemblies(); - -// foreach (var assembly in assemblies) -// { -// var allTypes = assembly.GetTypes(); -// foreach (var type in allTypes) -// { -// if (type is not { IsClass: true, IsAbstract: false }) continue; -// if (typeof(ISingletonDependency).IsAssignableFrom(type)) -// { -// var interfaceTypes = type.GetInterfaces().Where(p => p.FullName != null && !p.FullName.Contains("ISingletonDependency") && !p.FullName.Contains("IDisposable")); -// foreach (var interfaceType in interfaceTypes) -// { -// Log.Logger.Information($"正在IOC注入ISingletonDependency {type.Name}..."); -// services.AddSingleton(interfaceType, type); -// } -// } - -// if (typeof(ITransientDependency).IsAssignableFrom(type)) -// { -// var interfaceTypes = type.GetInterfaces().Where(p => p.FullName != null && !p.FullName.Contains("ITransientDependency") && !p.FullName.Contains("IDisposable")); -// foreach (var interfaceType in interfaceTypes) -// { -// Log.Logger.Information($"正在IOC注入ITransientDependency {type.Name}..."); -// services.AddTransient(interfaceType, type); -// } -// } - -// if (typeof(IScopedDependency).IsAssignableFrom(type)) -// { -// var interfaceTypes = type.GetInterfaces().Where(p => p.FullName != null && !p.FullName.Contains("IScopedDependency") && !p.FullName.Contains("IDisposable")); -// foreach (var interfaceType in interfaceTypes) -// { -// Log.Logger.Information($"正在IOC注入IScopedDependency {type.Name}..."); -// services.AddScoped(interfaceType, type); -// } -// } -// } -// } - -// return services; -// } - -// private static IEnumerable GetBinAssemblies() -// { -// var directory = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory); -// if (!directory.Exists) return []; - -// var files = directory.GetFiles("JiShe.CollectBus.*.dll"); - -// var assemblies = new List(); -// foreach (var file in files) -// { -// try -// { -// var assembly = Assembly.LoadFrom(file.FullName); -// assemblies.Add(assembly); -// } -// catch (Exception ex) -// { -// Console.WriteLine($"Error loading assembly from {file.FullName}: {ex.Message}"); -// } -// } - -// return assemblies; -// } -// } -//} diff --git a/JiShe.CollectBus.Common/Extensions/DependencyInjections/IScopedDependency.cs b/JiShe.CollectBus.Common/Extensions/DependencyInjections/IScopedDependency.cs deleted file mode 100644 index 349cbf8..0000000 --- a/JiShe.CollectBus.Common/Extensions/DependencyInjections/IScopedDependency.cs +++ /dev/null @@ -1,6 +0,0 @@ -//namespace JiShe.CollectBus.Common.Extensions.DependencyInjections -//{ -// public interface IScopedDependency -// { -// } -//} diff --git a/JiShe.CollectBus.Common/Extensions/DependencyInjections/ISingletonDependency.cs b/JiShe.CollectBus.Common/Extensions/DependencyInjections/ISingletonDependency.cs deleted file mode 100644 index 83bbdb8..0000000 --- a/JiShe.CollectBus.Common/Extensions/DependencyInjections/ISingletonDependency.cs +++ /dev/null @@ -1,6 +0,0 @@ -//namespace JiShe.CollectBus.Common.Extensions.DependencyInjections -//{ -// public interface ISingletonDependency -// { -// } -//} diff --git a/JiShe.CollectBus.Common/Extensions/DependencyInjections/ITransientDependency.cs b/JiShe.CollectBus.Common/Extensions/DependencyInjections/ITransientDependency.cs deleted file mode 100644 index ea2d48d..0000000 --- a/JiShe.CollectBus.Common/Extensions/DependencyInjections/ITransientDependency.cs +++ /dev/null @@ -1,6 +0,0 @@ -//namespace JiShe.CollectBus.Common.Extensions.DependencyInjections -//{ -// public interface ITransientDependency -// { -// } -//} diff --git a/JiShe.CollectBus.Common/Interfaces/IReceived.cs b/JiShe.CollectBus.Common/Interfaces/IReceived.cs new file mode 100644 index 0000000..3650fde --- /dev/null +++ b/JiShe.CollectBus.Common/Interfaces/IReceived.cs @@ -0,0 +1,7 @@ +namespace JiShe.CollectBus.Common.Interfaces +{ + public interface IReceived + { + string ReceivedTime { get; set; } + } +} diff --git a/JiShe.CollectBus.Common/JiShe.CollectBus.Common.csproj b/JiShe.CollectBus.Common/JiShe.CollectBus.Common.csproj index 5722609..4e5a504 100644 --- a/JiShe.CollectBus.Common/JiShe.CollectBus.Common.csproj +++ b/JiShe.CollectBus.Common/JiShe.CollectBus.Common.csproj @@ -6,6 +6,12 @@ enable + + + + + + @@ -16,8 +22,4 @@ - - - - diff --git a/JiShe.CollectBus.Protocol.Contracts/Models/MessageIssuedEvent.cs b/JiShe.CollectBus.Common/Models/MessageIssuedEvent.cs similarity index 85% rename from JiShe.CollectBus.Protocol.Contracts/Models/MessageIssuedEvent.cs rename to JiShe.CollectBus.Common/Models/MessageIssuedEvent.cs index 58d4df7..bc182d1 100644 --- a/JiShe.CollectBus.Protocol.Contracts/Models/MessageIssuedEvent.cs +++ b/JiShe.CollectBus.Common/Models/MessageIssuedEvent.cs @@ -1,6 +1,6 @@ using JiShe.CollectBus.Common.Enums; -namespace JiShe.CollectBus.Protocol.Contracts.Models +namespace JiShe.CollectBus.Common.Models { public class MessageIssuedEvent { diff --git a/JiShe.CollectBus.Protocol.Contracts/Models/MessageReceivedEvent.cs b/JiShe.CollectBus.Common/Models/MessageReceivedEvent.cs similarity index 85% rename from JiShe.CollectBus.Protocol.Contracts/Models/MessageReceivedEvent.cs rename to JiShe.CollectBus.Common/Models/MessageReceivedEvent.cs index f222b3b..4cbe5a7 100644 --- a/JiShe.CollectBus.Protocol.Contracts/Models/MessageReceivedEvent.cs +++ b/JiShe.CollectBus.Common/Models/MessageReceivedEvent.cs @@ -1,8 +1,8 @@ -using JetBrains.Annotations; +using JiShe.CollectBus.Common.Interfaces; -namespace JiShe.CollectBus.Protocol.Contracts.Models +namespace JiShe.CollectBus.Common.Models { - public class MessageReceivedEvent + public class MessageReceivedEvent:IReceived { public string MessageId { get; set; } = string.Empty; /// @@ -33,7 +33,7 @@ namespace JiShe.CollectBus.Protocol.Contracts.Models /// /// 接收指令时间 /// - public DateTime ReceivedTime { get; set; } + public string ReceivedTime { get; set; } = string.Empty; } public class MessageReceivedLoginEvent: MessageReceivedEvent diff --git a/JiShe.CollectBus.Console/Extensions/ServiceCollections/ServiceCollectionExtensions.cs b/JiShe.CollectBus.Console/Extensions/ServiceCollections/ServiceCollectionExtensions.cs index dcab11f..9351c45 100644 --- a/JiShe.CollectBus.Console/Extensions/ServiceCollections/ServiceCollectionExtensions.cs +++ b/JiShe.CollectBus.Console/Extensions/ServiceCollections/ServiceCollectionExtensions.cs @@ -1,11 +1,4 @@ using System.Reflection; -using JiShe.CollectBus.Common.Extensions; -using JiShe.CollectBus.Core.Plugins; -using JiShe.CollectBus.Core.Services; -using JiShe.CollectBus.Protocol.Contracts.Adapters; -using Microsoft.Extensions.Configuration; -using TouchSocket.Core; -using TouchSocket.Sockets; using Volo.Abp.Modularity; // ReSharper disable once CheckNamespace diff --git a/JiShe.CollectBus.Console/JiShe.CollectBus.Console.csproj b/JiShe.CollectBus.Console/JiShe.CollectBus.Console.csproj index 50e667f..fa6fdd3 100644 --- a/JiShe.CollectBus.Console/JiShe.CollectBus.Console.csproj +++ b/JiShe.CollectBus.Console/JiShe.CollectBus.Console.csproj @@ -41,10 +41,11 @@ - + - + + diff --git a/JiShe.CollectBus.Console/Program.cs b/JiShe.CollectBus.Console/Program.cs index aa194fa..362f62d 100644 --- a/JiShe.CollectBus.Console/Program.cs +++ b/JiShe.CollectBus.Console/Program.cs @@ -1,4 +1,5 @@ -using JiShe.CollectBus.Core; +using JiShe.CollectBus.MQ.Consumer; +using JiShe.CollectBus.Network; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -55,17 +56,16 @@ namespace JiShe.CollectBus.Console lc.ReadFrom.Configuration(configuration) .ReadFrom.Services(context); }); - services.AddApplication(); + services.AddApplication(); + + services.AddApplication(); + services.AddPluginApplications(); services.AddStackExchangeRedisCache(options => { options.Configuration = configuration["RedisCache:ConnectionString"]; options.InstanceName = configuration["RedisCache:InstanceName"]; }); - - //var app = AbpApplicationFactory.Create(); - //app.Initialize(); - } } } diff --git a/JiShe.CollectBus.Core/Exceptions/CloseException.cs b/JiShe.CollectBus.Core/Exceptions/CloseException.cs index e1f6260..00a9ec1 100644 --- a/JiShe.CollectBus.Core/Exceptions/CloseException.cs +++ b/JiShe.CollectBus.Core/Exceptions/CloseException.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace JiShe.CollectBus.Core.Exceptions +namespace JiShe.CollectBus.Network.Exceptions { public class CloseException(string msg) : Exception(msg); } diff --git a/JiShe.CollectBus.Core/JiShe.CollectBus.Core.csproj b/JiShe.CollectBus.Core/JiShe.CollectBus.Network.csproj similarity index 70% rename from JiShe.CollectBus.Core/JiShe.CollectBus.Core.csproj rename to JiShe.CollectBus.Core/JiShe.CollectBus.Network.csproj index a893ed6..fc52e4a 100644 --- a/JiShe.CollectBus.Core/JiShe.CollectBus.Core.csproj +++ b/JiShe.CollectBus.Core/JiShe.CollectBus.Network.csproj @@ -20,9 +20,8 @@ - - - + + diff --git a/JiShe.CollectBus.Core/JiSheCollectBusCoreModule.cs b/JiShe.CollectBus.Core/JiSheCollectBusNetworkModule.cs similarity index 66% rename from JiShe.CollectBus.Core/JiSheCollectBusCoreModule.cs rename to JiShe.CollectBus.Core/JiSheCollectBusNetworkModule.cs index 6aa60ea..d2233b7 100644 --- a/JiShe.CollectBus.Core/JiSheCollectBusCoreModule.cs +++ b/JiShe.CollectBus.Core/JiSheCollectBusNetworkModule.cs @@ -1,18 +1,18 @@ -using JiShe.CollectBus.Core.Plugins; -using JiShe.CollectBus.Core.Services; -using JiShe.CollectBus.EntityFrameworkCore; -using JiShe.CollectBus.RabbitMQ; +using JiShe.CollectBus.MongoDB; +using JiShe.CollectBus.MQ.Sender; +using JiShe.CollectBus.Network.Plugins; using Microsoft.Extensions.DependencyInjection; using TouchSocket.Core; using TouchSocket.Sockets; using Volo.Abp; using Volo.Abp.Modularity; +using ServerMonitor = JiShe.CollectBus.Network.Plugins.ServerMonitor; -namespace JiShe.CollectBus.Core +namespace JiShe.CollectBus.Network { - [DependsOn(typeof(JiSheCollectBusEntityFrameworkCoreModule), - typeof(JiSheCollectBusRabbitMqModule))] - public class JiSheCollectBusCoreModule : AbpModule + [DependsOn(typeof(JiSheCollectBusMongoDbModule), + typeof(JiSheCollectBusMqSenderModule))] + public class JiSheCollectBusNetworkModule : AbpModule { public override async void ConfigureServices(ServiceConfigurationContext context) { @@ -23,9 +23,9 @@ namespace JiShe.CollectBus.Core //.SetTcpDataHandlingAdapter(()=>new StandardFixedHeaderDataHandlingAdapter()) .ConfigurePlugins(a => { - a.Add(); - a.Add(); - a.Add(); + a.Add(); + a.Add(); + a.Add(); }); }); @@ -34,8 +34,8 @@ namespace JiShe.CollectBus.Core config.SetBindIPHost(int.Parse(configuration["UDP:ClientPort"] ?? "10500")) .ConfigurePlugins(a => { - a.Add(); - a.Add(); + a.Add(); + a.Add(); }) .UseBroadcast() .SetUdpDataHandlingAdapter(() => new NormalUdpDataHandlingAdapter()); diff --git a/JiShe.CollectBus.Core/Plugins/ClosePlugin.cs b/JiShe.CollectBus.Core/Plugins/CloseMonitor.cs similarity index 77% rename from JiShe.CollectBus.Core/Plugins/ClosePlugin.cs rename to JiShe.CollectBus.Core/Plugins/CloseMonitor.cs index b0c0531..bc65ea3 100644 --- a/JiShe.CollectBus.Core/Plugins/ClosePlugin.cs +++ b/JiShe.CollectBus.Core/Plugins/CloseMonitor.cs @@ -1,11 +1,11 @@ -using JiShe.CollectBus.Core.Exceptions; +using JiShe.CollectBus.Network.Exceptions; using Microsoft.Extensions.Logging; using TouchSocket.Core; using TouchSocket.Sockets; -namespace JiShe.CollectBus.Core.Plugins +namespace JiShe.CollectBus.Network.Plugins { - public partial class TcpClosePlugin(ILogger logger) : PluginBase + public partial class TcpCloseMonitor(ILogger logger) : PluginBase { [GeneratorPlugin(typeof(ITcpReceivedPlugin))] public async Task OnTcpReceived(ITcpSessionClient client, ReceivedDataEventArgs e) @@ -29,7 +29,7 @@ namespace JiShe.CollectBus.Core.Plugins } } - public partial class UdpClosePlugin(ILog logger) : PluginBase + public partial class UdpCloseMonitor(ILogger logger) : PluginBase { [GeneratorPlugin(typeof(IUdpReceivedPlugin))] public Task OnUdpReceived(IUdpSessionBase client, UdpReceivedDataEventArgs e) diff --git a/JiShe.CollectBus.Core/Services/BusService.cs b/JiShe.CollectBus.Core/Plugins/ServerMonitor.cs similarity index 84% rename from JiShe.CollectBus.Core/Services/BusService.cs rename to JiShe.CollectBus.Core/Plugins/ServerMonitor.cs index f8419a2..997cd31 100644 --- a/JiShe.CollectBus.Core/Services/BusService.cs +++ b/JiShe.CollectBus.Core/Plugins/ServerMonitor.cs @@ -1,15 +1,10 @@ using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using TouchSocket.Core; using TouchSocket.Sockets; -namespace JiShe.CollectBus.Core.Services +namespace JiShe.CollectBus.Network.Plugins { - public partial class BusService(ILogger logger) : PluginBase + public partial class ServerMonitor(ILogger logger) : PluginBase { [GeneratorPlugin(typeof(IServerStartedPlugin))] public Task OnServerStarted(IServiceBase sender, ServiceStateEventArgs e) diff --git a/JiShe.CollectBus.Core/Plugins/TcpServicePlugin.cs b/JiShe.CollectBus.Core/Plugins/TcpMonitor.cs similarity index 53% rename from JiShe.CollectBus.Core/Plugins/TcpServicePlugin.cs rename to JiShe.CollectBus.Core/Plugins/TcpMonitor.cs index 1e6133d..006af86 100644 --- a/JiShe.CollectBus.Core/Plugins/TcpServicePlugin.cs +++ b/JiShe.CollectBus.Core/Plugins/TcpMonitor.cs @@ -1,34 +1,22 @@ using JiShe.CollectBus.Common.Enums; using JiShe.CollectBus.Common.Extensions; -using JiShe.CollectBus.Protocol.Contracts.Models; +using JiShe.CollectBus.Common.Models; +using JiShe.CollectBus.MongoDB; +using JiShe.CollectBus.MQ.Sender; +using MassTransit; +using Microsoft.Extensions.Logging; using TouchSocket.Core; using TouchSocket.Sockets; -using JiShe.CollectBus.RabbitMQ.Senders; -using Microsoft.Extensions.Logging; -using JiShe.CollectBus.MongoDB; -using MassTransit; -namespace JiShe.CollectBus.Core.Plugins +namespace JiShe.CollectBus.Network.Plugins { - public partial class TcpServicePlugin : PluginBase + public partial class TcpMonitor( + INSender nSender, + ILogger logger, + IMongoRepository mongoHeartbeatRepository, + IMongoRepository mongoLoginRepository) + : PluginBase { - private readonly INSender _nSender; - private readonly ILogger _logger; - public readonly IMongoRepository _mongoHeartbeatRepository; - public readonly IMongoRepository _mongoLoginRepository; - public readonly IServiceProvider _serviceProvider; - - - public TcpServicePlugin(INSender nSender, ILogger logger,IMongoRepository mongoHeartbeatRepository, IMongoRepository mongoLoginRepository, IServiceProvider serviceProvider) - { - _nSender = nSender; - _logger = logger; - _mongoHeartbeatRepository = mongoHeartbeatRepository; - _mongoLoginRepository = mongoLoginRepository; - _serviceProvider = serviceProvider; - } - - [GeneratorPlugin(typeof(ITcpReceivedPlugin))] public async Task OnTcpReceived(ITcpSessionClient client, ReceivedDataEventArgs e) { @@ -52,26 +40,11 @@ namespace JiShe.CollectBus.Core.Plugins ClientIp = client.IP, ClientPort = client.Port, MessageHexString = messageHexString, - ReceivedTime = DateTime.Now, DeviceNo = aTuple.Item1, MessageId = NewId.NextGuid().ToString() }; - await _mongoLoginRepository.AddAsync(messageReceivedLoginEvent); - await _nSender.SendToReceivedLoginAsync(messageReceivedLoginEvent); - break; - case 2://退出登录 - var messageReceivedExitLoginEvent = new MessageReceivedLoginEvent - { - ClientId = client.Id, - ClientIp = client.IP, - ClientPort = client.Port, - MessageHexString = messageHexString, - ReceivedTime = DateTime.Now, - DeviceNo = aTuple.Item1, - MessageId = NewId.NextGuid().ToString() - }; - await _mongoLoginRepository.AddAsync(messageReceivedExitLoginEvent); - await _nSender.SendToReceivedLoginAsync(messageReceivedExitLoginEvent); + await mongoLoginRepository.AddAsync(messageReceivedLoginEvent); + await nSender.SendToReceivedLoginAsync(messageReceivedLoginEvent); break; case 3://心跳 var messageReceivedHeartbeatEvent = new MessageReceivedHeartbeatEvent @@ -80,18 +53,20 @@ namespace JiShe.CollectBus.Core.Plugins ClientIp = client.IP, ClientPort = client.Port, MessageHexString = messageHexString, - ReceivedTime = DateTime.Now, DeviceNo = aTuple.Item1, MessageId = NewId.NextGuid().ToString() }; - await _mongoHeartbeatRepository.AddAsync(messageReceivedHeartbeatEvent); - await _nSender.SendToReceivedHeartbeatAsync(messageReceivedHeartbeatEvent); + await mongoHeartbeatRepository.AddAsync(messageReceivedHeartbeatEvent); + await nSender.SendToReceivedHeartbeatAsync(messageReceivedHeartbeatEvent); + break; + default: + logger.LogError($"指令初步解析失败,指令内容:{messageHexString}"); break; } } else { - await _nSender.SendToReceivedAsync(new MessageReceivedEvent + await nSender.SendToReceivedAsync(new MessageReceivedEvent { ClientId = client.Id, ClientIp = client.IP, @@ -104,7 +79,7 @@ namespace JiShe.CollectBus.Core.Plugins } else { - _logger.LogError($"指令初步解析失败,指令内容:{messageHexString}"); + logger.LogError($"指令初步解析失败,指令内容:{messageHexString}"); } await e.InvokeNext(); @@ -113,25 +88,21 @@ namespace JiShe.CollectBus.Core.Plugins [GeneratorPlugin(typeof(ITcpConnectingPlugin))] public async Task OnTcpConnecting(ITcpSessionClient client,ConnectingEventArgs e) { - _logger.LogInformation($"[TCP] ID:{client.Id} IP:{client.GetIPPort()}正在连接中..."); - + logger.LogInformation($"[TCP] ID:{client.Id} IP:{client.GetIPPort()}正在连接中..."); await e.InvokeNext(); - } [GeneratorPlugin(typeof(ITcpConnectedPlugin))] public async Task OnTcpConnected(ITcpSessionClient client,ConnectedEventArgs e) { - _logger.LogInformation($"[TCP] ID:{client.Id} IP:{client.GetIPPort()}已连接"); - + logger.LogInformation($"[TCP] ID:{client.Id} IP:{client.GetIPPort()}已连接"); await e.InvokeNext(); } [GeneratorPlugin(typeof(ITcpClosedPlugin))] public async Task OnTcpClosed(ITcpSessionClient client, ClosedEventArgs e) { - _logger.LogInformation($"[TCP] ID:{client.Id} IP:{client.GetIPPort()}已关闭连接"); - + logger.LogInformation($"[TCP] ID:{client.Id} IP:{client.GetIPPort()}已关闭连接"); await e.InvokeNext(); } } diff --git a/JiShe.CollectBus.Core/Plugins/UdpServicePlugin.cs b/JiShe.CollectBus.Core/Plugins/UdpMonitor.cs similarity index 83% rename from JiShe.CollectBus.Core/Plugins/UdpServicePlugin.cs rename to JiShe.CollectBus.Core/Plugins/UdpMonitor.cs index 8004d5e..976ce7a 100644 --- a/JiShe.CollectBus.Core/Plugins/UdpServicePlugin.cs +++ b/JiShe.CollectBus.Core/Plugins/UdpMonitor.cs @@ -2,9 +2,9 @@ using TouchSocket.Core; using TouchSocket.Sockets; -namespace JiShe.CollectBus.Core.Plugins +namespace JiShe.CollectBus.Network.Plugins { - public partial class UdpServicePlugin : PluginBase + public partial class UdpMonitor : PluginBase { [GeneratorPlugin(typeof(IUdpReceivedPlugin))] public async Task OnUdpReceived(IUdpSessionBase client, UdpReceivedDataEventArgs e) diff --git a/JiShe.CollectBus.Host/Controllers/CommandController.cs b/JiShe.CollectBus.Host/Controllers/CommandController.cs index 12f52c6..4fce45b 100644 --- a/JiShe.CollectBus.Host/Controllers/CommandController.cs +++ b/JiShe.CollectBus.Host/Controllers/CommandController.cs @@ -1,120 +1,35 @@ -using JiShe.CollectBus.Common.Enums; -using JiShe.CollectBus.Common.Extensions; -using JiShe.CollectBus.Common.Models; -using JiShe.CollectBus.RabbitMQ.Senders; -using Microsoft.AspNetCore.Mvc; +using JiShe.CollectBus.Application.Contracts; +using Volo.Abp.AspNetCore.Mvc; namespace JiShe.CollectBus.Host.Controllers { - [ApiController] - [Route("[controller]/[action]")] - public class CommandController : ControllerBase + public class CommandController : AbpController { private readonly ILogger _logger; - private readonly INSender _nSender; + private readonly ICommandService _commandService; - public CommandController(INSender nSender, ILogger logger) + public CommandController(ILogger logger, ICommandService commandService) { - _nSender = nSender; _logger = logger; + _commandService = commandService; } - [HttpGet(Name = "AmmeterParameterSend")] public async Task AmmeterParameterSendAsync() { - var listMeter = new List() - { - new AmmeterParameter() - { - Pn = 1, - BaudRate = 3, - Port = 2, - ProtocolType = CommunicationProtocolType.DLT6452007, - Address = "312408006642", - Password = "000000", - RateNumber = 4, - IntegerBitNumber = 4, - DecimalBitNumber = 4, - CollectorAddress = "000000000000", - UserCategoryNumber = 0, - UserSubclassNumber = 0 - } - }; - var bytes = HexStringExtensions.BuildAmmeterParameterSetSendCmd(new ReqParameter2() - { - AFN = AFN.设置参数, - FunCode = (int)CMasterStationFunCode.请求1级数据, - A = "322009872", - Seq = new Seq() - { - TpV = TpV.附加信息域中无时间标签, - FIRFIN = FIRFIN.单帧, - CON = CON.需要对该帧进行确认, - PRSEQ = 10, - }, - MSA = 13, - Pn = 0, - Fn = 10 - }, listMeter); - - // await _nSender.SendToIssuedAsync(new MessageIssuedEvent { DeviceNo = "322009872", Message = bytes, Type = IssuedEventType.Data,MessageId = Guid.NewGuid().ToString() }); - return true; + return await _commandService.AmmeterParameterSendAsync(); } - [HttpGet(Name = "AmmeterParameterReading")] public bool AmmeterParameterReading() { - HexStringExtensions.BuildAmmeterParameterReadingSendCmd(new ReqParameter2() - { - AFN = AFN.查询参数, - FunCode = (int)CMasterStationFunCode.请求2级数据, - A = "322009872", - Seq = new Seq() - { - TpV = TpV.附加信息域中无时间标签, - FIRFIN = FIRFIN.单帧, - CON = CON.不需要对该帧进行确认, - PRSEQ = 2, - }, - MSA = 13, - Pn = 0, - Fn = 10 - }, new List() { 1, 2 }); - - return true; + return _commandService.AmmeterParameterReading(); } - [HttpGet(Name = "ActivePowerIndicationReading")] public bool ActivePowerIndicationReading() { - //var str = "68A600A6006888203290261A0A6200000201010001000100621E426622082431000000000000040300000000000000CA16"; - //var cmdResult = new BuildCommand().AnalysisCmd(str); - //if(cmdResult != null) - //{ - // var list = new BuildCommand().AnalysisAFN04F10DataUnit(cmdResult.HexDatas); - //} - HexStringExtensions.BuildSendCommandBytes(new ReqParameter2() - { - AFN = AFN.请求实时数据, - FunCode = (int)CMasterStationFunCode.请求2级数据, - A = "322009872", - Seq = new Seq() - { - TpV = TpV.附加信息域中无时间标签, - FIRFIN = FIRFIN.单帧, - CON = CON.不需要对该帧进行确认, - PRSEQ = 2, - }, - MSA = 13, - Pn = 1, - Fn = 129 - }); + return _commandService.ActivePowerIndicationReading(); - //HexStringExtensions.AmmeterValveControl("312408006642", "", "000000", true); - - return true; } } diff --git a/JiShe.CollectBus.Host/Extensions/ServiceCollections/ServiceCollectionExtensions.cs b/JiShe.CollectBus.Host/Extensions/ServiceCollections/ServiceCollectionExtensions.cs index 486c5c8..dab9401 100644 --- a/JiShe.CollectBus.Host/Extensions/ServiceCollections/ServiceCollectionExtensions.cs +++ b/JiShe.CollectBus.Host/Extensions/ServiceCollections/ServiceCollectionExtensions.cs @@ -1,16 +1,49 @@ using System.Reflection; -using Hangfire; -using JiShe.CollectBus.Protocol.Contracts.Adapters; -using Microsoft.Extensions.Configuration; -using TouchSocket.Core; -using TouchSocket.Sockets; +using Volo.Abp.Modularity; // ReSharper disable once CheckNamespace namespace Microsoft.Extensions.DependencyInjection { public static class ServiceCollectionExtensions { + public static void AddPluginApplications(this IServiceCollection services, string pluginPath = "") + { + if (string.IsNullOrWhiteSpace(pluginPath)) + { + pluginPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins"); + } + var assemblies = GetAssembliesFromFolder(pluginPath); + foreach (var assembly in assemblies) + { + var applicationServiceType = assembly.GetTypes() + .FirstOrDefault(a => a.IsClass && !a.IsAbstract && typeof(AbpModule).IsAssignableFrom(a)); + services.AddApplication(applicationServiceType); + } + } + private static IEnumerable GetAssembliesFromFolder(string folderPath) + { + var directory = new DirectoryInfo(folderPath); + if (!directory.Exists) return []; + + var files = directory.GetFiles("*.dll"); + + var assemblies = new List(); + foreach (var file in files) + { + try + { + var assembly = Assembly.LoadFrom(file.FullName); + assemblies.Add(assembly); + } + catch (Exception ex) + { + Console.WriteLine($"Error loading assembly from {file.FullName}: {ex.Message}"); + } + } + + return assemblies; + } } -} +} \ No newline at end of file diff --git a/JiShe.CollectBus.Host/JiShe.CollectBus.Host.csproj b/JiShe.CollectBus.Host/JiShe.CollectBus.Host.csproj index 7ebd36a..a5ac8e9 100644 --- a/JiShe.CollectBus.Host/JiShe.CollectBus.Host.csproj +++ b/JiShe.CollectBus.Host/JiShe.CollectBus.Host.csproj @@ -7,6 +7,7 @@ + @@ -20,16 +21,15 @@ + + + - - - - - - + + diff --git a/JiShe.CollectBus.Host/JiSheCollectBusHostModule.cs b/JiShe.CollectBus.Host/JiSheCollectBusHostModule.cs new file mode 100644 index 0000000..7b78fed --- /dev/null +++ b/JiShe.CollectBus.Host/JiSheCollectBusHostModule.cs @@ -0,0 +1,26 @@ +using Abp.Dependency; +using DeviceDetectorNET.Parser.Device; +using Serilog; +using Volo.Abp.Modularity; + +namespace JiShe.CollectBus.Host +{ + public class JiSheCollectBusHostModule : AbpModule + { + public override void ConfigureServices(ServiceConfigurationContext context) + { + var services = context.Services; + var configuration = IocManager.Instance.Resolve(); + //services.AddApplication(); + + //services.AddApplication(); + + services.AddPluginApplications(); + services.AddStackExchangeRedisCache(options => + { + options.Configuration = configuration["RedisCache:ConnectionString"]; + options.InstanceName = configuration["RedisCache:InstanceName"]; + }); + } + } +} diff --git a/JiShe.CollectBus.Host/Program.cs b/JiShe.CollectBus.Host/Program.cs index 6579f81..9f3a6da 100644 --- a/JiShe.CollectBus.Host/Program.cs +++ b/JiShe.CollectBus.Host/Program.cs @@ -5,7 +5,24 @@ public class Program { public static void Main(string[] args) { - CreateHostBuilder(args).Build().Run(); + try + { + Log.Logger = new LoggerConfiguration() + .WriteTo.Console() + .CreateLogger(); + + + CreateHostBuilder(args).Build().Run(); + + } + catch (Exception ex) + { + Log.Fatal(ex, "Application terminated unexpectedly"); + } + finally + { + Log.CloseAndFlush(); + } } diff --git a/JiShe.CollectBus.Host/Startup.cs b/JiShe.CollectBus.Host/Startup.cs index af72189..e28c135 100644 --- a/JiShe.CollectBus.Host/Startup.cs +++ b/JiShe.CollectBus.Host/Startup.cs @@ -3,7 +3,6 @@ using Hangfire.Dashboard.BasicAuthorization; using Hangfire.HttpJob; using Hangfire.MySql; using JiShe.CollectBus.Application; -using JiShe.CollectBus.Core; namespace JiShe.CollectBus.Host { @@ -12,6 +11,7 @@ namespace JiShe.CollectBus.Host public void ConfigureServices(IServiceCollection services) { services.AddControllers(); + services.AddApplication(); services.AddEndpointsApiExplorer(); services.AddSwaggerGen(); services.AddHangfire(config => @@ -35,12 +35,11 @@ namespace JiShe.CollectBus.Host config.UseHangfireHttpJob(); }); services.AddHangfireServer(); - services.AddApplication(); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { - app.InitializeApplication(); + if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); @@ -58,35 +57,33 @@ namespace JiShe.CollectBus.Host var dashboardOptions = new DashboardOptions(); if (env.IsProduction()) - { dashboardOptions = new DashboardOptions { Authorization = new[] { - new BasicAuthAuthorizationFilter(new BasicAuthAuthorizationFilterOptions - { - SslRedirect = false, - RequireSsl = false, - LoginCaseSensitive = false, - Users = - [ - new BasicAuthAuthorizationUser - { - Login = "admin", - PasswordClear = "lixiao1980" - } - ] - }) - }, + new BasicAuthAuthorizationFilter(new BasicAuthAuthorizationFilterOptions + { + SslRedirect = false, + RequireSsl = false, + LoginCaseSensitive = false, + Users = + [ + new BasicAuthAuthorizationUser + { + Login = "admin", + PasswordClear = "lixiao1980" + } + ] + }) + } }; - } app.UseHangfireDashboard("/hangfire", dashboardOptions); - app.UseEndpoints(endpoint => - { - endpoint.MapControllers(); - }); - + //app.UseEndpoints(endpoints => + //{ + // endpoints.MapRazorPages(); + //}); + app.UseConfiguredEndpoints(); } } diff --git a/JiShe.CollectBus.Host/appsettings.json b/JiShe.CollectBus.Host/appsettings.json index e9caf9e..f2183ed 100644 --- a/JiShe.CollectBus.Host/appsettings.json +++ b/JiShe.CollectBus.Host/appsettings.json @@ -27,8 +27,8 @@ }, "ConnectionStrings": { - //"Default": "Data Source=192.168.111.248;Port=3306;Database=JiSheCollectBus;uid=root;pwd=123456abcD;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true", - "Default": "Data Source=localhost;Port=3306;Database=JiSheCollectBus;uid=root;pwd=123456abcD;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true" + "Default": "Data Source=192.168.111.248;Port=3306;Database=JiSheCollectBus;uid=root;pwd=123456abcD;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true", + //"Default": "Data Source=localhost;Port=3306;Database=JiSheCollectBus;uid=root;pwd=123456abcD;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true" }, "MongoSettings": { "Connection": "mongodb://backups_admin:jishe_mongodb_backups@118.190.144.92:27037", diff --git a/JiShe.CollectBus.MongoDB/JiShe.CollectBus.MongoDB.csproj b/JiShe.CollectBus.MongoDB/JiShe.CollectBus.MongoDB.csproj index 51b3d9c..c144b6f 100644 --- a/JiShe.CollectBus.MongoDB/JiShe.CollectBus.MongoDB.csproj +++ b/JiShe.CollectBus.MongoDB/JiShe.CollectBus.MongoDB.csproj @@ -9,10 +9,12 @@ + + diff --git a/JiShe.CollectBus.MongoDB/JiSheCollectBusMongoDBModule.cs b/JiShe.CollectBus.MongoDB/JiSheCollectBusMongoDBModule.cs index 70cfde5..cd8998c 100644 --- a/JiShe.CollectBus.MongoDB/JiSheCollectBusMongoDBModule.cs +++ b/JiShe.CollectBus.MongoDB/JiSheCollectBusMongoDBModule.cs @@ -1,15 +1,29 @@ -using Microsoft.Extensions.DependencyInjection; +using JiShe.CollectBus.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Modularity; +using Volo.Abp.Timing; namespace JiShe.CollectBus.MongoDB { + [DependsOn(typeof(AbpTimingModule), + typeof(JiSheCollectBusEntityFrameworkCoreModule))] public class JiSheCollectBusMongoDbModule: AbpModule { + public override void PreConfigureServices(ServiceConfigurationContext context) + { + + } + public override void ConfigureServices(ServiceConfigurationContext context) { context.Services.AddSingleton(); context.Services.AddSingleton(); context.Services.AddSingleton(typeof(IMongoRepository<>), typeof(MongoBaseRepository<>)); + + Configure(options => + { + options.Kind = DateTimeKind.Local; + }); } } } diff --git a/JiShe.CollectBus.MongoDB/MongoBaseRepository.cs b/JiShe.CollectBus.MongoDB/MongoBaseRepository.cs index 740c10b..5df6aea 100644 --- a/JiShe.CollectBus.MongoDB/MongoBaseRepository.cs +++ b/JiShe.CollectBus.MongoDB/MongoBaseRepository.cs @@ -8,6 +8,9 @@ using System.Linq.Expressions; using System.Reflection; using System.Text; using System.Threading.Tasks; +using JiShe.CollectBus.Common.Interfaces; +using JiShe.CollectBus.EntityFrameworkCore; +using Volo.Abp.Timing; namespace JiShe.CollectBus.MongoDB { @@ -15,10 +18,12 @@ namespace JiShe.CollectBus.MongoDB { private readonly IMongoContext _context; private readonly IMongoCollection _dbSet; + private readonly IClock _clock; - public MongoBaseRepository(IMongoContext context) + public MongoBaseRepository(IMongoContext context, IClock clock) { _context = context; + _clock = clock; var collectionName = typeof(T).GetCustomAttribute()?.Name ?? typeof(T).Name; _dbSet = _context.GetCollection(collectionName); } @@ -70,6 +75,10 @@ namespace JiShe.CollectBus.MongoDB /// public async Task AddAsync(T objData) { + if (typeof(IReceived).IsAssignableFrom(typeof(T))) + { + (objData as IReceived)!.ReceivedTime = $"{_clock.Now:yyyy-MM-dd HH:mm:ss}"; + } await _dbSet.InsertOneAsync(objData); } diff --git a/JiShe.CollectBus.Protocol.Contracts/Abstracts/BaseProtocolPlugin.cs b/JiShe.CollectBus.Protocol.Contracts/Abstracts/BaseProtocolPlugin.cs index 09ae408..ea61aec 100644 --- a/JiShe.CollectBus.Protocol.Contracts/Abstracts/BaseProtocolPlugin.cs +++ b/JiShe.CollectBus.Protocol.Contracts/Abstracts/BaseProtocolPlugin.cs @@ -4,8 +4,6 @@ using JiShe.CollectBus.Common.Models; using JiShe.CollectBus.Protocol.Contracts.Interfaces; using JiShe.CollectBus.Protocol.Contracts.Models; using Microsoft.Extensions.Logging; -using System.Net.Sockets; -using static System.Runtime.InteropServices.JavaScript.JSType; namespace JiShe.CollectBus.Protocol.Contracts.Abstracts { diff --git a/JiShe.CollectBus.Protocol.Contracts/Adapters/StandardFixedHeaderDataHandlingAdapter.cs b/JiShe.CollectBus.Protocol.Contracts/Adapters/StandardFixedHeaderDataHandlingAdapter.cs index 3aacf09..0984a8f 100644 --- a/JiShe.CollectBus.Protocol.Contracts/Adapters/StandardFixedHeaderDataHandlingAdapter.cs +++ b/JiShe.CollectBus.Protocol.Contracts/Adapters/StandardFixedHeaderDataHandlingAdapter.cs @@ -1,4 +1,4 @@ -using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using JiShe.CollectBus.Protocol.Contracts.Models; using System; using System.Collections.Generic; using System.Linq; diff --git a/JiShe.CollectBus.Protocol.Contracts/Models/IProtocolInfo.cs b/JiShe.CollectBus.Protocol.Contracts/Interfaces/IProtocolInfo.cs similarity index 91% rename from JiShe.CollectBus.Protocol.Contracts/Models/IProtocolInfo.cs rename to JiShe.CollectBus.Protocol.Contracts/Interfaces/IProtocolInfo.cs index 01961ab..35b7998 100644 --- a/JiShe.CollectBus.Protocol.Contracts/Models/IProtocolInfo.cs +++ b/JiShe.CollectBus.Protocol.Contracts/Interfaces/IProtocolInfo.cs @@ -1,4 +1,4 @@ -namespace JiShe.CollectBus.Protocol.Contracts.Models +namespace JiShe.CollectBus.Protocol.Contracts.Interfaces { public interface IProtocolInfo { diff --git a/JiShe.CollectBus.Protocol.Contracts/Interfaces/IProtocolPlugin.cs b/JiShe.CollectBus.Protocol.Contracts/Interfaces/IProtocolPlugin.cs index 66105cc..52330e9 100644 --- a/JiShe.CollectBus.Protocol.Contracts/Interfaces/IProtocolPlugin.cs +++ b/JiShe.CollectBus.Protocol.Contracts/Interfaces/IProtocolPlugin.cs @@ -1,5 +1,6 @@ using System; using System.Threading.Tasks; +using JiShe.CollectBus.Common.Models; using JiShe.CollectBus.Protocol.Contracts.Models; using TouchSocket.Sockets; diff --git a/JiShe.CollectBus.Protocol.Contracts/JiShe.CollectBus.Protocol.Contracts.csproj b/JiShe.CollectBus.Protocol.Contracts/JiShe.CollectBus.Protocol.Contracts.csproj index 2b18de3..13fd7d4 100644 --- a/JiShe.CollectBus.Protocol.Contracts/JiShe.CollectBus.Protocol.Contracts.csproj +++ b/JiShe.CollectBus.Protocol.Contracts/JiShe.CollectBus.Protocol.Contracts.csproj @@ -14,7 +14,6 @@ - diff --git a/JiShe.CollectBus.Protocol.Contracts/Interfaces/CustomFixedHeaderRequestInfo.cs b/JiShe.CollectBus.Protocol.Contracts/Models/CustomFixedHeaderRequestInfo.cs similarity index 95% rename from JiShe.CollectBus.Protocol.Contracts/Interfaces/CustomFixedHeaderRequestInfo.cs rename to JiShe.CollectBus.Protocol.Contracts/Models/CustomFixedHeaderRequestInfo.cs index 14e38e5..61ea887 100644 --- a/JiShe.CollectBus.Protocol.Contracts/Interfaces/CustomFixedHeaderRequestInfo.cs +++ b/JiShe.CollectBus.Protocol.Contracts/Models/CustomFixedHeaderRequestInfo.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; using TouchSocket.Core; -namespace JiShe.CollectBus.Protocol.Contracts.Interfaces +namespace JiShe.CollectBus.Protocol.Contracts.Models { public class CustomFixedHeaderRequestInfo : IFixedHeaderRequestInfo { diff --git a/JiShe.CollectBus.Protocol.Contracts/Models/ProtocolInfo.cs b/JiShe.CollectBus.Protocol.Contracts/Models/ProtocolInfo.cs index 64473bd..ff09e2d 100644 --- a/JiShe.CollectBus.Protocol.Contracts/Models/ProtocolInfo.cs +++ b/JiShe.CollectBus.Protocol.Contracts/Models/ProtocolInfo.cs @@ -1,4 +1,6 @@ -namespace JiShe.CollectBus.Protocol.Contracts.Models +using JiShe.CollectBus.Protocol.Contracts.Interfaces; + +namespace JiShe.CollectBus.Protocol.Contracts.Models { public class ProtocolInfo : IProtocolInfo { diff --git a/JiShe.CollectBus.Protocol.Test/TestProtocolPlugin.cs b/JiShe.CollectBus.Protocol.Test/TestProtocolPlugin.cs index 2addc56..5f53960 100644 --- a/JiShe.CollectBus.Protocol.Test/TestProtocolPlugin.cs +++ b/JiShe.CollectBus.Protocol.Test/TestProtocolPlugin.cs @@ -1,4 +1,5 @@ -using JiShe.CollectBus.Protocol.Contracts.Abstracts; +using JiShe.CollectBus.Common.Models; +using JiShe.CollectBus.Protocol.Contracts.Abstracts; using JiShe.CollectBus.Protocol.Contracts.Attributes; using JiShe.CollectBus.Protocol.Contracts.Models; using Microsoft.Extensions.Logging; diff --git a/JiShe.CollectBus.Protocol/JiShe.CollectBus.Protocol.csproj b/JiShe.CollectBus.Protocol/JiShe.CollectBus.Protocol.csproj index b54c79a..fd92cd0 100644 --- a/JiShe.CollectBus.Protocol/JiShe.CollectBus.Protocol.csproj +++ b/JiShe.CollectBus.Protocol/JiShe.CollectBus.Protocol.csproj @@ -16,7 +16,7 @@ - + diff --git a/JiShe.CollectBus.Protocol/JiSheCollectBusProtocolModule.cs b/JiShe.CollectBus.Protocol/JiSheCollectBusProtocolModule.cs index 3c89027..b3549ba 100644 --- a/JiShe.CollectBus.Protocol/JiSheCollectBusProtocolModule.cs +++ b/JiShe.CollectBus.Protocol/JiSheCollectBusProtocolModule.cs @@ -1,11 +1,12 @@ -using JiShe.CollectBus.Protocol.Contracts.Interfaces; -using JiShe.CollectBus.RabbitMQ; +using JiShe.CollectBus.MQ.Sender; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; using Microsoft.Extensions.DependencyInjection; using Volo.Abp; using Volo.Abp.Modularity; namespace JiShe.CollectBus.Protocol { + [DependsOn(typeof(JiSheCollectBusMqSenderModule))] public class JiSheCollectBusProtocolModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) diff --git a/JiShe.CollectBus.Protocol/StandardProtocolPlugin.cs b/JiShe.CollectBus.Protocol/StandardProtocolPlugin.cs index 9113ffe..25633c8 100644 --- a/JiShe.CollectBus.Protocol/StandardProtocolPlugin.cs +++ b/JiShe.CollectBus.Protocol/StandardProtocolPlugin.cs @@ -1,17 +1,16 @@ using JiShe.CollectBus.Common.Enums; using JiShe.CollectBus.Common.Extensions; using JiShe.CollectBus.Common.Models; +using JiShe.CollectBus.MQ.Sender; using JiShe.CollectBus.Protocol.Contracts.Abstracts; using JiShe.CollectBus.Protocol.Contracts.Attributes; using JiShe.CollectBus.Protocol.Contracts.Models; -using JiShe.CollectBus.RabbitMQ.Senders; using Microsoft.Extensions.Logging; using Volo.Abp.DependencyInjection; namespace JiShe.CollectBus.Protocol { - [ProtocolName("StandardProtocol")] - public class StandardProtocolPlugin(INSender nSender, ILogger logger) : BaseProtocolPlugin(logger) + public class StandardProtocolPlugin(INSender nSender, ILogger logger) : BaseProtocolPlugin(logger), ISingletonDependency { public override async Task GetAsync() { diff --git a/JiShe.CollectBus.RabbitMQ/Consumers/MessageReceivedHeartbeatConsumer.cs b/JiShe.CollectBus.RabbitMQ/Consumers/MessageReceivedHeartbeatConsumer.cs deleted file mode 100644 index 50c35e5..0000000 --- a/JiShe.CollectBus.RabbitMQ/Consumers/MessageReceivedHeartbeatConsumer.cs +++ /dev/null @@ -1,36 +0,0 @@ -using JiShe.CollectBus.MongoDB; -using JiShe.CollectBus.Protocol.Contracts.Interfaces; -using JiShe.CollectBus.Protocol.Contracts.Models; -using MassTransit; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; - -namespace JiShe.CollectBus.RabbitMQ.Consumers -{ - public class MessageReceivedHeartbeatConsumer : IConsumer - { - private readonly ILogger _logger; - private readonly IServiceProvider _serviceProvider; - - public MessageReceivedHeartbeatConsumer(ILogger logger, IServiceProvider serviceProvider) - { - _logger = logger; - _serviceProvider = serviceProvider; - } - - public async Task Consume(ConsumeContext context) - { - _logger.LogInformation("心跳消费队列开始处理"); - var protocolPlugin = _serviceProvider.GetKeyedService("StandardProtocol"); - if (protocolPlugin == null) - { - _logger.LogError("【心跳消费队列开始处理】协议不存在!"); - } - else - { - await protocolPlugin.HeartbeatAsync(context.Message); - _logger.LogInformation("心跳消费队列完成处理"); - } - } - } -} diff --git a/JiShe.CollectBus.RabbitMQ/Consumers/MessageReceivedLoginConsumer.cs b/JiShe.CollectBus.RabbitMQ/Consumers/MessageReceivedLoginConsumer.cs deleted file mode 100644 index 0132baa..0000000 --- a/JiShe.CollectBus.RabbitMQ/Consumers/MessageReceivedLoginConsumer.cs +++ /dev/null @@ -1,35 +0,0 @@ -using JiShe.CollectBus.Protocol.Contracts.Interfaces; -using JiShe.CollectBus.Protocol.Contracts.Models; -using MassTransit; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; - -namespace JiShe.CollectBus.RabbitMQ.Consumers -{ - public class MessageReceivedLoginConsumer : IConsumer - { - private readonly ILogger _logger; - private readonly IServiceProvider _serviceProvider; - - public MessageReceivedLoginConsumer(ILogger logger, IServiceProvider serviceProvider) - { - _logger = logger; - _serviceProvider = serviceProvider; - } - - public async Task Consume(ConsumeContext context) - { - _logger.LogInformation("登录消费队列开始处理"); - var protocolPlugin = _serviceProvider.GetKeyedService("StandardProtocol"); - if (protocolPlugin == null) - { - _logger.LogError("【登录消费队列开始处理】协议不存在!"); - } - else - { - await protocolPlugin.LoginAsync(context.Message); - _logger.LogInformation("登录消费队列完成处理"); - } - } - } -} diff --git a/JiShe.CollectBus.RabbitMQ/Senders/INSender.cs b/JiShe.CollectBus.RabbitMQ/INSender.cs similarity index 96% rename from JiShe.CollectBus.RabbitMQ/Senders/INSender.cs rename to JiShe.CollectBus.RabbitMQ/INSender.cs index 52e5a87..24b520d 100644 --- a/JiShe.CollectBus.RabbitMQ/Senders/INSender.cs +++ b/JiShe.CollectBus.RabbitMQ/INSender.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace JiShe.CollectBus.RabbitMQ.Senders +namespace JiShe.CollectBus.MQ.Sender { public interface INSender { diff --git a/JiShe.CollectBus.RabbitMQ/JiShe.CollectBus.RabbitMQ.csproj b/JiShe.CollectBus.RabbitMQ/JiShe.CollectBus.MQ.Sender.csproj similarity index 74% rename from JiShe.CollectBus.RabbitMQ/JiShe.CollectBus.RabbitMQ.csproj rename to JiShe.CollectBus.RabbitMQ/JiShe.CollectBus.MQ.Sender.csproj index b2287a5..f676e4e 100644 --- a/JiShe.CollectBus.RabbitMQ/JiShe.CollectBus.RabbitMQ.csproj +++ b/JiShe.CollectBus.RabbitMQ/JiShe.CollectBus.MQ.Sender.csproj @@ -15,8 +15,6 @@ - - diff --git a/JiShe.CollectBus.RabbitMQ/JiSheCollectBusMQSenderModule.cs b/JiShe.CollectBus.RabbitMQ/JiSheCollectBusMQSenderModule.cs new file mode 100644 index 0000000..a050078 --- /dev/null +++ b/JiShe.CollectBus.RabbitMQ/JiSheCollectBusMQSenderModule.cs @@ -0,0 +1,17 @@ +using Volo.Abp; +using Volo.Abp.Modularity; + +namespace JiShe.CollectBus.MQ.Sender +{ + public class JiSheCollectBusMqSenderModule: AbpModule + { + public override void ConfigureServices(ServiceConfigurationContext context) + { + + } + + public override void OnApplicationInitialization(ApplicationInitializationContext context) + { + } + } +} diff --git a/JiShe.CollectBus.RabbitMQ/Senders/NSender.cs b/JiShe.CollectBus.RabbitMQ/NSender.cs similarity index 79% rename from JiShe.CollectBus.RabbitMQ/Senders/NSender.cs rename to JiShe.CollectBus.RabbitMQ/NSender.cs index 9c062ad..58f2237 100644 --- a/JiShe.CollectBus.RabbitMQ/Senders/NSender.cs +++ b/JiShe.CollectBus.RabbitMQ/NSender.cs @@ -1,19 +1,20 @@ using MassTransit; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; using Volo.Abp.DependencyInjection; -namespace JiShe.CollectBus.RabbitMQ.Senders +namespace JiShe.CollectBus.MQ.Sender { - public class NSender:INSender,ISingletonDependency + public class NSender : INSender, ISingletonDependency { - private readonly ISendEndpointProvider _sendEndpointProvider; + private readonly ServiceProvider _serviceProvider; private readonly string _issuedKey; private readonly string _receivedKey; - public NSender(ISendEndpointProvider sendEndpointProvider, IConfiguration configuration) + public NSender(IConfiguration configuration, ServiceProvider serviceProvider) { - _sendEndpointProvider = sendEndpointProvider; + _serviceProvider = serviceProvider; _issuedKey = configuration["MQ:Queue:Issued"]!; _receivedKey = configuration["MQ:Queue:Received"]!; } @@ -61,7 +62,9 @@ namespace JiShe.CollectBus.RabbitMQ.Senders public async Task SendAsync(string queueKey, object message, CancellationToken cancellationToken = default) { - var endpoint = await _sendEndpointProvider.GetSendEndpoint(new Uri($"queue:{queueKey}")); + using var scope = _serviceProvider.CreateScope(); + var scopedService = scope.ServiceProvider.GetRequiredService(); + var endpoint = await scopedService.GetSendEndpoint(new Uri($"queue:{queueKey}")); await endpoint.Send(message, cancellationToken); } } diff --git a/JiShe.CollectBus.Service/JiShe.CollectBus.MQ.Consumer.csproj b/JiShe.CollectBus.Service/JiShe.CollectBus.MQ.Consumer.csproj new file mode 100644 index 0000000..8ffd136 --- /dev/null +++ b/JiShe.CollectBus.Service/JiShe.CollectBus.MQ.Consumer.csproj @@ -0,0 +1,20 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + + + + diff --git a/JiShe.CollectBus.RabbitMQ/JiSheCollectBusRabbitMqModule.cs b/JiShe.CollectBus.Service/JiSheCollectBusMQConsumerModule.cs similarity index 95% rename from JiShe.CollectBus.RabbitMQ/JiSheCollectBusRabbitMqModule.cs rename to JiShe.CollectBus.Service/JiSheCollectBusMQConsumerModule.cs index 30061e6..e28ee9f 100644 --- a/JiShe.CollectBus.RabbitMQ/JiSheCollectBusRabbitMqModule.cs +++ b/JiShe.CollectBus.Service/JiSheCollectBusMQConsumerModule.cs @@ -1,12 +1,13 @@ -using JiShe.CollectBus.RabbitMQ.Consumers; +using JiShe.CollectBus.Network; using MassTransit; using Microsoft.Extensions.DependencyInjection; using Volo.Abp; using Volo.Abp.Modularity; -namespace JiShe.CollectBus.RabbitMQ +namespace JiShe.CollectBus.MQ.Consumer { - public class JiSheCollectBusRabbitMqModule: AbpModule + [DependsOn(typeof(JiSheCollectBusNetworkModule))] + public class JiSheCollectBusMqConsumerModule: AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) { diff --git a/JiShe.CollectBus.RabbitMQ/Consumers/MessageIssuedConsumer.cs b/JiShe.CollectBus.Service/MessageIssuedConsumer.cs similarity index 93% rename from JiShe.CollectBus.RabbitMQ/Consumers/MessageIssuedConsumer.cs rename to JiShe.CollectBus.Service/MessageIssuedConsumer.cs index e66c3ad..e2a5921 100644 --- a/JiShe.CollectBus.RabbitMQ/Consumers/MessageIssuedConsumer.cs +++ b/JiShe.CollectBus.Service/MessageIssuedConsumer.cs @@ -1,11 +1,11 @@ using JiShe.CollectBus.Common.Enums; +using JiShe.CollectBus.Common.Models; using JiShe.CollectBus.MongoDB; -using JiShe.CollectBus.Protocol.Contracts.Models; using MassTransit; using Microsoft.Extensions.Logging; using TouchSocket.Sockets; -namespace JiShe.CollectBus.RabbitMQ.Consumers +namespace JiShe.CollectBus.MQ.Consumer { public class MessageIssuedConsumer( ILogger logger, diff --git a/JiShe.CollectBus.RabbitMQ/Consumers/MessageIssuedFaultConsumer.cs b/JiShe.CollectBus.Service/MessageIssuedFaultConsumer.cs similarity index 55% rename from JiShe.CollectBus.RabbitMQ/Consumers/MessageIssuedFaultConsumer.cs rename to JiShe.CollectBus.Service/MessageIssuedFaultConsumer.cs index 8b4eed9..8c03a44 100644 --- a/JiShe.CollectBus.RabbitMQ/Consumers/MessageIssuedFaultConsumer.cs +++ b/JiShe.CollectBus.Service/MessageIssuedFaultConsumer.cs @@ -1,12 +1,7 @@ -using JiShe.CollectBus.Protocol.Contracts.Models; +using JiShe.CollectBus.Common.Models; using MassTransit; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace JiShe.CollectBus.RabbitMQ.Consumers +namespace JiShe.CollectBus.MQ.Consumer { public class MessageIssuedFaultConsumer : IConsumer> { diff --git a/JiShe.CollectBus.RabbitMQ/Consumers/MessageReceivedConsumer.cs b/JiShe.CollectBus.Service/MessageReceivedConsumer.cs similarity index 85% rename from JiShe.CollectBus.RabbitMQ/Consumers/MessageReceivedConsumer.cs rename to JiShe.CollectBus.Service/MessageReceivedConsumer.cs index a4f8dbe..2e9c511 100644 --- a/JiShe.CollectBus.RabbitMQ/Consumers/MessageReceivedConsumer.cs +++ b/JiShe.CollectBus.Service/MessageReceivedConsumer.cs @@ -1,11 +1,11 @@ -using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using JiShe.CollectBus.Common.Models; +using JiShe.CollectBus.MongoDB; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; using MassTransit; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using JiShe.CollectBus.Protocol.Contracts.Models; -using JiShe.CollectBus.MongoDB; -namespace JiShe.CollectBus.RabbitMQ.Consumers +namespace JiShe.CollectBus.MQ.Consumer { /// /// Batch 一次最多 100 个,最多 10 个并发批次 @@ -18,7 +18,7 @@ namespace JiShe.CollectBus.RabbitMQ.Consumers { public async Task Consume(ConsumeContext> context) { - const string protocolType = "StandardProtocol"; + const string protocolType = "Standard"; var protocolPlugin = serviceProvider.GetKeyedService(protocolType); if (protocolPlugin == null) { diff --git a/JiShe.CollectBus.RabbitMQ/Consumers/MessageReceivedFaultConsumer.cs b/JiShe.CollectBus.Service/MessageReceivedFaultConsumer.cs similarity index 57% rename from JiShe.CollectBus.RabbitMQ/Consumers/MessageReceivedFaultConsumer.cs rename to JiShe.CollectBus.Service/MessageReceivedFaultConsumer.cs index 0352817..5d9c999 100644 --- a/JiShe.CollectBus.RabbitMQ/Consumers/MessageReceivedFaultConsumer.cs +++ b/JiShe.CollectBus.Service/MessageReceivedFaultConsumer.cs @@ -1,12 +1,7 @@ -using JiShe.CollectBus.Protocol.Contracts.Models; +using JiShe.CollectBus.Common.Models; using MassTransit; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace JiShe.CollectBus.RabbitMQ.Consumers +namespace JiShe.CollectBus.MQ.Consumer { public class MessageReceivedFaultConsumer: IConsumer>> { diff --git a/JiShe.CollectBus.Service/MessageReceivedHeartbeatConsumer.cs b/JiShe.CollectBus.Service/MessageReceivedHeartbeatConsumer.cs new file mode 100644 index 0000000..77d27a2 --- /dev/null +++ b/JiShe.CollectBus.Service/MessageReceivedHeartbeatConsumer.cs @@ -0,0 +1,29 @@ +using JiShe.CollectBus.Common.Models; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using MassTransit; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.MQ.Consumer +{ + public class MessageReceivedHeartbeatConsumer( + ILogger logger, + IServiceProvider serviceProvider) + : IConsumer + { + public async Task Consume(ConsumeContext context) + { + logger.LogInformation("心跳消费队列开始处理"); + var protocolPlugin = serviceProvider.GetKeyedService("Standard"); + if (protocolPlugin == null) + { + logger.LogError("【心跳消费队列开始处理】协议不存在!"); + } + else + { + await protocolPlugin.HeartbeatAsync(context.Message); + logger.LogInformation("心跳消费队列完成处理"); + } + } + } +} diff --git a/JiShe.CollectBus.Service/MessageReceivedLoginConsumer.cs b/JiShe.CollectBus.Service/MessageReceivedLoginConsumer.cs new file mode 100644 index 0000000..aacec81 --- /dev/null +++ b/JiShe.CollectBus.Service/MessageReceivedLoginConsumer.cs @@ -0,0 +1,29 @@ +using JiShe.CollectBus.Common.Models; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; +using MassTransit; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace JiShe.CollectBus.MQ.Consumer +{ + public class MessageReceivedLoginConsumer( + ILogger logger, + IServiceProvider serviceProvider) + : IConsumer + { + public async Task Consume(ConsumeContext context) + { + logger.LogInformation("登录消费队列开始处理"); + var protocolPlugin = serviceProvider.GetKeyedService("Standard"); + if (protocolPlugin == null) + { + logger.LogError("【登录消费队列开始处理】协议不存在!"); + } + else + { + await protocolPlugin.LoginAsync(context.Message); + logger.LogInformation("登录消费队列完成处理"); + } + } + } +} diff --git a/JiShe.CollectBus.Test/BusUnitTest.cs b/JiShe.CollectBus.Test/BusUnitTest.cs index d57c0b8..6f1a462 100644 --- a/JiShe.CollectBus.Test/BusUnitTest.cs +++ b/JiShe.CollectBus.Test/BusUnitTest.cs @@ -4,12 +4,11 @@ using System.Data.Common; using System.Linq; using System.Text; using System.Threading.Tasks; -using DnsClient.Internal; using JiShe.CollectBus.Common.Enums; using JiShe.CollectBus.Common.Extensions; using JiShe.CollectBus.Common.Models; +using JiShe.CollectBus.MQ.Sender; using JiShe.CollectBus.Protocol.Contracts.Models; -using JiShe.CollectBus.RabbitMQ.Senders; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Moq; diff --git a/JiShe.CollectBus.Test/JiShe.CollectBus.Test.csproj b/JiShe.CollectBus.Test/JiShe.CollectBus.Test.csproj index 51f7dd2..5c59917 100644 --- a/JiShe.CollectBus.Test/JiShe.CollectBus.Test.csproj +++ b/JiShe.CollectBus.Test/JiShe.CollectBus.Test.csproj @@ -19,7 +19,7 @@ - + diff --git a/JiShe.CollectBus.sln b/JiShe.CollectBus.sln index cebdea4..71613ea 100644 --- a/JiShe.CollectBus.sln +++ b/JiShe.CollectBus.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.9.34728.123 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JiShe.CollectBus.Core", "JiShe.CollectBus.Core\JiShe.CollectBus.Core.csproj", "{F1360C93-5B6B-4E65-9D81-1DA38740F32D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JiShe.CollectBus.Network", "JiShe.CollectBus.Core\JiShe.CollectBus.Network.csproj", "{F1360C93-5B6B-4E65-9D81-1DA38740F32D}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JiShe.CollectBus.Console", "JiShe.CollectBus.Console\JiShe.CollectBus.Console.csproj", "{40C4F834-3080-451B-9510-6FE7BC4F801F}" EndProject @@ -21,7 +21,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JiShe.CollectBus.Protocol.D EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JiShe.CollectBus.EntityFrameworkCore", "JiShe.CollectBus.EntityFrameworkCore\JiShe.CollectBus.EntityFrameworkCore.csproj", "{16D42BCF-EDB8-4153-B37D-0B10FB6DF36C}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JiShe.CollectBus.RabbitMQ", "JiShe.CollectBus.RabbitMQ\JiShe.CollectBus.RabbitMQ.csproj", "{DB46D90E-304D-48B7-9ED6-F4DCC95D3824}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JiShe.CollectBus.MQ.Sender", "JiShe.CollectBus.RabbitMQ\JiShe.CollectBus.MQ.Sender.csproj", "{DB46D90E-304D-48B7-9ED6-F4DCC95D3824}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JiShe.CollectBus.MongoDB", "JiShe.CollectBus.MongoDB\JiShe.CollectBus.MongoDB.csproj", "{223DBDB1-6CD3-4D4E-8795-42550BC0A871}" EndProject @@ -35,6 +35,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JiShe.CollectBus.Test", "Ji EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JiShe.CollectBus.Application", "JiShe.CollectBus.Application\JiShe.CollectBus.Application.csproj", "{2760AC98-D2FA-4074-8396-FAE10BE20A3C}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JiShe.CollectBus.Application.Contracts", "JiShe.CollectBus.Application.Contracts\JiShe.CollectBus.Application.Contracts.csproj", "{47B9A51B-70B5-42ED-A92A-FFEFB864CB14}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JiShe.CollectBus.MQ.Consumer", "JiShe.CollectBus.Service\JiShe.CollectBus.MQ.Consumer.csproj", "{024086CC-49D0-436E-8B84-A67766A30CDE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -89,6 +93,14 @@ Global {2760AC98-D2FA-4074-8396-FAE10BE20A3C}.Debug|Any CPU.Build.0 = Debug|Any CPU {2760AC98-D2FA-4074-8396-FAE10BE20A3C}.Release|Any CPU.ActiveCfg = Release|Any CPU {2760AC98-D2FA-4074-8396-FAE10BE20A3C}.Release|Any CPU.Build.0 = Release|Any CPU + {47B9A51B-70B5-42ED-A92A-FFEFB864CB14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {47B9A51B-70B5-42ED-A92A-FFEFB864CB14}.Debug|Any CPU.Build.0 = Debug|Any CPU + {47B9A51B-70B5-42ED-A92A-FFEFB864CB14}.Release|Any CPU.ActiveCfg = Release|Any CPU + {47B9A51B-70B5-42ED-A92A-FFEFB864CB14}.Release|Any CPU.Build.0 = Release|Any CPU + {024086CC-49D0-436E-8B84-A67766A30CDE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {024086CC-49D0-436E-8B84-A67766A30CDE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {024086CC-49D0-436E-8B84-A67766A30CDE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {024086CC-49D0-436E-8B84-A67766A30CDE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -106,6 +118,8 @@ Global {FFA010F6-F33A-4705-8A42-B0FA3B3D2131} = {B68027BA-BD9D-4110-A383-708B87BC425D} {6ED66F52-B4A0-403E-AE89-8E9A679C0885} = {3A04FB29-EA75-4499-BBF3-AF24C7D46A1D} {2760AC98-D2FA-4074-8396-FAE10BE20A3C} = {C7DEC9FB-3F75-4584-85B0-16EA3CB222E5} + {47B9A51B-70B5-42ED-A92A-FFEFB864CB14} = {C7DEC9FB-3F75-4584-85B0-16EA3CB222E5} + {024086CC-49D0-436E-8B84-A67766A30CDE} = {C7DEC9FB-3F75-4584-85B0-16EA3CB222E5} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {33261859-9CD1-4A43-B181-AB75C247D1CD}