修改代码

This commit is contained in:
cli 2024-11-13 17:50:52 +08:00
parent a304e908aa
commit ded12729d9
61 changed files with 521 additions and 495 deletions

View File

@ -0,0 +1,9 @@
namespace JiShe.CollectBus.Application.Contracts
{
public interface ICommandService
{
Task<bool> AmmeterParameterSendAsync();
bool AmmeterParameterReading();
bool ActivePowerIndicationReading();
}
}

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -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<CommandService> _logger;
private readonly INSender _nSender;
public async Task<bool> AmmeterParameterSendAsync()
{
var listMeter = new List<AmmeterParameter>()
{
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<int>() { 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;
}
}
}

View File

@ -11,7 +11,9 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\JiShe.CollectBus.Application.Contracts\JiShe.CollectBus.Application.Contracts.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.Common\JiShe.CollectBus.Common.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.RabbitMQ\JiShe.CollectBus.MQ.Sender.csproj" />
</ItemGroup>
</Project>

View File

@ -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<ISendEndpointProvider>();
//var configuration = context.Services.GetConfiguration();
//context.Services.AddJobs(configuration);
}

View File

@ -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<Assembly> GetBinAssemblies()
// {
// var directory = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
// if (!directory.Exists) return [];
// var files = directory.GetFiles("JiShe.CollectBus.*.dll");
// var assemblies = new List<Assembly>();
// 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;
// }
// }
//}

View File

@ -1,6 +0,0 @@
//namespace JiShe.CollectBus.Common.Extensions.DependencyInjections
//{
// public interface IScopedDependency
// {
// }
//}

View File

@ -1,6 +0,0 @@
//namespace JiShe.CollectBus.Common.Extensions.DependencyInjections
//{
// public interface ISingletonDependency
// {
// }
//}

View File

@ -1,6 +0,0 @@
//namespace JiShe.CollectBus.Common.Extensions.DependencyInjections
//{
// public interface ITransientDependency
// {
// }
//}

View File

@ -0,0 +1,7 @@
namespace JiShe.CollectBus.Common.Interfaces
{
public interface IReceived
{
string ReceivedTime { get; set; }
}
}

View File

@ -6,6 +6,12 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Abstractions\**" />
<EmbeddedResource Remove="Abstractions\**" />
<None Remove="Abstractions\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2024.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
@ -16,8 +22,4 @@
<PackageReference Include="Volo.Abp.Core" Version="8.3.3" />
</ItemGroup>
<ItemGroup>
<Folder Include="Abstractions\" />
</ItemGroup>
</Project>

View File

@ -1,6 +1,6 @@
using JiShe.CollectBus.Common.Enums;
namespace JiShe.CollectBus.Protocol.Contracts.Models
namespace JiShe.CollectBus.Common.Models
{
public class MessageIssuedEvent
{

View File

@ -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;
/// <summary>
@ -33,7 +33,7 @@ namespace JiShe.CollectBus.Protocol.Contracts.Models
/// <summary>
/// 接收指令时间
/// </summary>
public DateTime ReceivedTime { get; set; }
public string ReceivedTime { get; set; } = string.Empty;
}
public class MessageReceivedLoginEvent: MessageReceivedEvent

View File

@ -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

View File

@ -41,10 +41,11 @@
<ItemGroup>
<ProjectReference Include="..\JiShe.CollectBus.Application\JiShe.CollectBus.Application.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.Common\JiShe.CollectBus.Common.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.Core\JiShe.CollectBus.Core.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.Core\JiShe.CollectBus.Network.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.EntityFrameworkCore\JiShe.CollectBus.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.Protocol.Contracts\JiShe.CollectBus.Protocol.Contracts.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.RabbitMQ\JiShe.CollectBus.RabbitMQ.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.RabbitMQ\JiShe.CollectBus.MQ.Sender.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.Service\JiShe.CollectBus.MQ.Consumer.csproj" />
</ItemGroup>
<ItemGroup>

View File

@ -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<JiSheCollectBusCoreModule>();
services.AddApplication<JiSheCollectBusMqConsumerModule>();
services.AddApplication<JiSheCollectBusNetworkModule>();
services.AddPluginApplications();
services.AddStackExchangeRedisCache(options =>
{
options.Configuration = configuration["RedisCache:ConnectionString"];
options.InstanceName = configuration["RedisCache:InstanceName"];
});
//var app = AbpApplicationFactory.Create<JiSheCollectBusCoreModule>();
//app.Initialize();
}
}
}

View File

@ -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);
}

View File

@ -20,9 +20,8 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\JiShe.CollectBus.EntityFrameworkCore\JiShe.CollectBus.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.Protocol.Contracts\JiShe.CollectBus.Protocol.Contracts.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.RabbitMQ\JiShe.CollectBus.RabbitMQ.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.MongoDB\JiShe.CollectBus.MongoDB.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.RabbitMQ\JiShe.CollectBus.MQ.Sender.csproj" />
</ItemGroup>
</Project>

View File

@ -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<TcpClosePlugin>();
a.Add<TcpServicePlugin>();
a.Add<BusService>();
a.Add<TcpCloseMonitor>();
a.Add<TcpMonitor>();
a.Add<ServerMonitor>();
});
});
@ -34,8 +34,8 @@ namespace JiShe.CollectBus.Core
config.SetBindIPHost(int.Parse(configuration["UDP:ClientPort"] ?? "10500"))
.ConfigurePlugins(a =>
{
a.Add<UdpServicePlugin>();
a.Add<BusService>();
a.Add<UdpMonitor>();
a.Add<ServerMonitor>();
})
.UseBroadcast()
.SetUdpDataHandlingAdapter(() => new NormalUdpDataHandlingAdapter());

View File

@ -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<TcpClosePlugin> logger) : PluginBase
public partial class TcpCloseMonitor(ILogger<TcpCloseMonitor> 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<TcpCloseMonitor> logger) : PluginBase
{
[GeneratorPlugin(typeof(IUdpReceivedPlugin))]
public Task OnUdpReceived(IUdpSessionBase client, UdpReceivedDataEventArgs e)

View File

@ -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<BusService> logger) : PluginBase
public partial class ServerMonitor(ILogger<ServerMonitor> logger) : PluginBase
{
[GeneratorPlugin(typeof(IServerStartedPlugin))]
public Task OnServerStarted(IServiceBase sender, ServiceStateEventArgs e)

View File

@ -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<TcpMonitor> logger,
IMongoRepository<MessageReceivedHeartbeatEvent> mongoHeartbeatRepository,
IMongoRepository<MessageReceivedLoginEvent> mongoLoginRepository)
: PluginBase
{
private readonly INSender _nSender;
private readonly ILogger<TcpServicePlugin> _logger;
public readonly IMongoRepository<MessageReceivedHeartbeatEvent> _mongoHeartbeatRepository;
public readonly IMongoRepository<MessageReceivedLoginEvent> _mongoLoginRepository;
public readonly IServiceProvider _serviceProvider;
public TcpServicePlugin(INSender nSender, ILogger<TcpServicePlugin> logger,IMongoRepository<MessageReceivedHeartbeatEvent> mongoHeartbeatRepository, IMongoRepository<MessageReceivedLoginEvent> 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();
}
}

View File

@ -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)

View File

@ -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<CommandController> _logger;
private readonly INSender _nSender;
private readonly ICommandService _commandService;
public CommandController(INSender nSender, ILogger<CommandController> logger)
public CommandController(ILogger<CommandController> logger, ICommandService commandService)
{
_nSender = nSender;
_logger = logger;
_commandService = commandService;
}
[HttpGet(Name = "AmmeterParameterSend")]
public async Task<bool> AmmeterParameterSendAsync()
{
var listMeter = new List<AmmeterParameter>()
{
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<int>() { 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;
}
}

View File

@ -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<Assembly> GetAssembliesFromFolder(string folderPath)
{
var directory = new DirectoryInfo(folderPath);
if (!directory.Exists) return [];
var files = directory.GetFiles("*.dll");
var assemblies = new List<Assembly>();
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;
}
}
}

View File

@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Abp" Version="9.4.2" />
<PackageReference Include="Hangfire" Version="1.8.15" />
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.15" />
<PackageReference Include="Hangfire.Dashboard.BasicAuthorization" Version="1.0.2" />
@ -20,16 +21,15 @@
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Include="Volo.Abp.AspNetCore" Version="8.3.3" />
<PackageReference Include="Volo.Abp.AspNetCore.Mvc" Version="8.3.3" />
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="8.0.10" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\JiShe.CollectBus.Application.Contracts\JiShe.CollectBus.Application.Contracts.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.Application\JiShe.CollectBus.Application.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.Common\JiShe.CollectBus.Common.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.Core\JiShe.CollectBus.Core.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.EntityFrameworkCore\JiShe.CollectBus.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.Protocol.Contracts\JiShe.CollectBus.Protocol.Contracts.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.RabbitMQ\JiShe.CollectBus.RabbitMQ.csproj" />
</ItemGroup>
</Project>

View File

@ -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<IConfiguration>();
//services.AddApplication<JiSheCollectBusMqConsumerModule>();
//services.AddApplication<JiSheCollectBusNetworkModule>();
services.AddPluginApplications();
services.AddStackExchangeRedisCache(options =>
{
options.Configuration = configuration["RedisCache:ConnectionString"];
options.InstanceName = configuration["RedisCache:InstanceName"];
});
}
}
}

View File

@ -5,8 +5,25 @@ public class Program
{
public static void Main(string[] args)
{
try
{
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.CreateLogger();
CreateHostBuilder(args).Build().Run();
}
catch (Exception ex)
{
Log.Fatal(ex, "Application terminated unexpectedly");
}
finally
{
Log.CloseAndFlush();
}
}
private static IHostBuilder CreateHostBuilder(string[] args) =>

View File

@ -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<JiSheCollectBusApplicationModule>();
services.AddEndpointsApiExplorer();
services.AddSwaggerGen();
services.AddHangfire(config =>
@ -35,12 +35,11 @@ namespace JiShe.CollectBus.Host
config.UseHangfireHttpJob();
});
services.AddHangfireServer();
services.AddApplication<JiSheCollectBusApplicationModule>();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.InitializeApplication();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
@ -58,7 +57,6 @@ namespace JiShe.CollectBus.Host
var dashboardOptions = new DashboardOptions();
if (env.IsProduction())
{
dashboardOptions = new DashboardOptions
{
Authorization = new[]
@ -77,16 +75,15 @@ namespace JiShe.CollectBus.Host
}
]
})
},
};
}
};
app.UseHangfireDashboard("/hangfire", dashboardOptions);
app.UseEndpoints(endpoint =>
{
endpoint.MapControllers();
});
//app.UseEndpoints(endpoints =>
//{
// endpoints.MapRazorPages();
//});
app.UseConfiguredEndpoints();
}
}

View File

@ -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",

View File

@ -9,10 +9,12 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageReference Include="MongoDB.Driver" Version="3.0.0" />
<PackageReference Include="Volo.Abp.Timing" Version="8.3.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\JiShe.CollectBus.Common\JiShe.CollectBus.Common.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.EntityFrameworkCore\JiShe.CollectBus.EntityFrameworkCore.csproj" />
</ItemGroup>
</Project>

View File

@ -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<IMongoContext, MongoContext>();
context.Services.AddSingleton<IUnitOfWork, UnitOfWork>();
context.Services.AddSingleton(typeof(IMongoRepository<>), typeof(MongoBaseRepository<>));
Configure<AbpClockOptions>(options =>
{
options.Kind = DateTimeKind.Local;
});
}
}
}

View File

@ -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<T> _dbSet;
private readonly IClock _clock;
public MongoBaseRepository(IMongoContext context)
public MongoBaseRepository(IMongoContext context, IClock clock)
{
_context = context;
_clock = clock;
var collectionName = typeof(T).GetCustomAttribute<TableAttribute>()?.Name ?? typeof(T).Name;
_dbSet = _context.GetCollection<T>(collectionName);
}
@ -70,6 +75,10 @@ namespace JiShe.CollectBus.MongoDB
/// <returns></returns>
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);
}

View File

@ -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
{

View File

@ -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;

View File

@ -1,4 +1,4 @@
namespace JiShe.CollectBus.Protocol.Contracts.Models
namespace JiShe.CollectBus.Protocol.Contracts.Interfaces
{
public interface IProtocolInfo
{

View File

@ -1,5 +1,6 @@
using System;
using System.Threading.Tasks;
using JiShe.CollectBus.Common.Models;
using JiShe.CollectBus.Protocol.Contracts.Models;
using TouchSocket.Sockets;

View File

@ -14,7 +14,6 @@
<ItemGroup>
<ProjectReference Include="..\JiShe.CollectBus.Common\JiShe.CollectBus.Common.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.MongoDB\JiShe.CollectBus.MongoDB.csproj" />
</ItemGroup>
</Project>

View File

@ -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
{

View File

@ -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
{

View File

@ -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;

View File

@ -16,7 +16,7 @@
<ItemGroup>
<ProjectReference Include="..\JiShe.CollectBus.Common\JiShe.CollectBus.Common.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.Protocol.Contracts\JiShe.CollectBus.Protocol.Contracts.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.RabbitMQ\JiShe.CollectBus.RabbitMQ.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.RabbitMQ\JiShe.CollectBus.MQ.Sender.csproj" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">

View File

@ -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)

View File

@ -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<BaseProtocolPlugin> logger) : BaseProtocolPlugin(logger)
public class StandardProtocolPlugin(INSender nSender, ILogger<BaseProtocolPlugin> logger) : BaseProtocolPlugin(logger), ISingletonDependency
{
public override async Task<ProtocolInfo> GetAsync()
{

View File

@ -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<MessageReceivedHeartbeatEvent>
{
private readonly ILogger<MessageReceivedHeartbeatConsumer> _logger;
private readonly IServiceProvider _serviceProvider;
public MessageReceivedHeartbeatConsumer(ILogger<MessageReceivedHeartbeatConsumer> logger, IServiceProvider serviceProvider)
{
_logger = logger;
_serviceProvider = serviceProvider;
}
public async Task Consume(ConsumeContext<MessageReceivedHeartbeatEvent> context)
{
_logger.LogInformation("心跳消费队列开始处理");
var protocolPlugin = _serviceProvider.GetKeyedService<IProtocolPlugin>("StandardProtocol");
if (protocolPlugin == null)
{
_logger.LogError("【心跳消费队列开始处理】协议不存在!");
}
else
{
await protocolPlugin.HeartbeatAsync(context.Message);
_logger.LogInformation("心跳消费队列完成处理");
}
}
}
}

View File

@ -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<MessageReceivedLoginEvent>
{
private readonly ILogger<MessageReceivedLoginConsumer> _logger;
private readonly IServiceProvider _serviceProvider;
public MessageReceivedLoginConsumer(ILogger<MessageReceivedLoginConsumer> logger, IServiceProvider serviceProvider)
{
_logger = logger;
_serviceProvider = serviceProvider;
}
public async Task Consume(ConsumeContext<MessageReceivedLoginEvent> context)
{
_logger.LogInformation("登录消费队列开始处理");
var protocolPlugin = _serviceProvider.GetKeyedService<IProtocolPlugin>("StandardProtocol");
if (protocolPlugin == null)
{
_logger.LogError("【登录消费队列开始处理】协议不存在!");
}
else
{
await protocolPlugin.LoginAsync(context.Message);
_logger.LogInformation("登录消费队列完成处理");
}
}
}
}

View File

@ -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
{

View File

@ -15,8 +15,6 @@
<ItemGroup>
<ProjectReference Include="..\JiShe.CollectBus.Common\JiShe.CollectBus.Common.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.MongoDB\JiShe.CollectBus.MongoDB.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.Protocol.Contracts\JiShe.CollectBus.Protocol.Contracts.csproj" />
</ItemGroup>
</Project>

View File

@ -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)
{
}
}
}

View File

@ -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<ISendEndpointProvider>();
var endpoint = await scopedService.GetSendEndpoint(new Uri($"queue:{queueKey}"));
await endpoint.Send(message, cancellationToken);
}
}

View File

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Volo.Abp.Core" Version="8.3.3" />
<PackageReference Include="MassTransit" Version="8.3.0" />
<PackageReference Include="MassTransit.RabbitMQ" Version="8.3.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\JiShe.CollectBus.Core\JiShe.CollectBus.Network.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.Protocol.Contracts\JiShe.CollectBus.Protocol.Contracts.csproj" />
</ItemGroup>
</Project>

View File

@ -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)
{

View File

@ -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<MessageIssuedEvent> logger,

View File

@ -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<Fault<MessageIssuedEvent>>
{

View File

@ -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
{
/// <summary>
/// Batch 一次最多 100 个,最多 10 个并发批次
@ -18,7 +18,7 @@ namespace JiShe.CollectBus.RabbitMQ.Consumers
{
public async Task Consume(ConsumeContext<Batch<MessageReceivedEvent>> context)
{
const string protocolType = "StandardProtocol";
const string protocolType = "Standard";
var protocolPlugin = serviceProvider.GetKeyedService<IProtocolPlugin>(protocolType);
if (protocolPlugin == null)
{

View File

@ -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<Fault<Batch<MessageReceivedEvent>>>
{

View File

@ -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<MessageReceivedHeartbeatConsumer> logger,
IServiceProvider serviceProvider)
: IConsumer<MessageReceivedHeartbeatEvent>
{
public async Task Consume(ConsumeContext<MessageReceivedHeartbeatEvent> context)
{
logger.LogInformation("心跳消费队列开始处理");
var protocolPlugin = serviceProvider.GetKeyedService<IProtocolPlugin>("Standard");
if (protocolPlugin == null)
{
logger.LogError("【心跳消费队列开始处理】协议不存在!");
}
else
{
await protocolPlugin.HeartbeatAsync(context.Message);
logger.LogInformation("心跳消费队列完成处理");
}
}
}
}

View File

@ -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<MessageReceivedLoginConsumer> logger,
IServiceProvider serviceProvider)
: IConsumer<MessageReceivedLoginEvent>
{
public async Task Consume(ConsumeContext<MessageReceivedLoginEvent> context)
{
logger.LogInformation("登录消费队列开始处理");
var protocolPlugin = serviceProvider.GetKeyedService<IProtocolPlugin>("Standard");
if (protocolPlugin == null)
{
logger.LogError("【登录消费队列开始处理】协议不存在!");
}
else
{
await protocolPlugin.LoginAsync(context.Message);
logger.LogInformation("登录消费队列完成处理");
}
}
}
}

View File

@ -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;

View File

@ -19,7 +19,7 @@
<ItemGroup>
<ProjectReference Include="..\JiShe.CollectBus.Protocol.Contracts\JiShe.CollectBus.Protocol.Contracts.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.RabbitMQ\JiShe.CollectBus.RabbitMQ.csproj" />
<ProjectReference Include="..\JiShe.CollectBus.RabbitMQ\JiShe.CollectBus.MQ.Sender.csproj" />
</ItemGroup>
<ItemGroup>

View File

@ -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}