修改代码
This commit is contained in:
parent
16bd93cc11
commit
0b1532d4af
@ -23,8 +23,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||||||
var interfaceTypes = type.GetInterfaces().Where(p => p.FullName != null && !p.FullName.Contains("ISingletonDependency"));
|
var interfaceTypes = type.GetInterfaces().Where(p => p.FullName != null && !p.FullName.Contains("ISingletonDependency"));
|
||||||
foreach (var interfaceType in interfaceTypes)
|
foreach (var interfaceType in interfaceTypes)
|
||||||
{
|
{
|
||||||
var serviceDescriptor = new ServiceDescriptor(interfaceType, interfaceType.Name, type, ServiceLifetime.Singleton);
|
services.AddSingleton(interfaceType, type);
|
||||||
services.Add(serviceDescriptor);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -36,8 +35,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||||||
var interfaceTypes = type.GetInterfaces().Where(p => p.FullName != null && !p.FullName.Contains("ITransientDependency"));
|
var interfaceTypes = type.GetInterfaces().Where(p => p.FullName != null && !p.FullName.Contains("ITransientDependency"));
|
||||||
foreach (var interfaceType in interfaceTypes)
|
foreach (var interfaceType in interfaceTypes)
|
||||||
{
|
{
|
||||||
var serviceDescriptor = new ServiceDescriptor(interfaceType, interfaceType.Name, type, ServiceLifetime.Transient);
|
services.AddTransient(interfaceType, type);
|
||||||
services.Add(serviceDescriptor);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -49,8 +47,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||||||
var interfaceTypes = type.GetInterfaces().Where(p => p.FullName != null && !p.FullName.Contains("IScopedDependency"));
|
var interfaceTypes = type.GetInterfaces().Where(p => p.FullName != null && !p.FullName.Contains("IScopedDependency"));
|
||||||
foreach (var interfaceType in interfaceTypes)
|
foreach (var interfaceType in interfaceTypes)
|
||||||
{
|
{
|
||||||
var serviceDescriptor = new ServiceDescriptor(interfaceType, interfaceType.Name, type, ServiceLifetime.Scoped);
|
services.AddScoped(interfaceType, type);
|
||||||
services.Add(serviceDescriptor);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,8 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<PublishAot>true</PublishAot>
|
<PublishAot>true</PublishAot>
|
||||||
<InvariantGlobalization>true</InvariantGlobalization>
|
<InvariantGlobalization>true</InvariantGlobalization>
|
||||||
|
<JsonSerializerIsReflectionEnabledByDefault>true</JsonSerializerIsReflectionEnabledByDefault>
|
||||||
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -1,12 +1,24 @@
|
|||||||
using JiShe.CollectBus.RabbitMQ.Models;
|
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||||
|
using JiShe.CollectBus.RabbitMQ.Models;
|
||||||
using JiShe.CollectBus.RabbitMQ.Senders;
|
using JiShe.CollectBus.RabbitMQ.Senders;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using System;
|
||||||
using TouchSocket.Core;
|
using TouchSocket.Core;
|
||||||
using TouchSocket.Sockets;
|
using TouchSocket.Sockets;
|
||||||
|
|
||||||
namespace JiShe.CollectBus.Core.Plugins
|
namespace JiShe.CollectBus.Core.Plugins
|
||||||
{
|
{
|
||||||
public partial class TcpServiceReceivedPlugin(IMqSender sender) : PluginBase
|
public partial class TcpServiceReceivedPlugin : PluginBase
|
||||||
{
|
{
|
||||||
|
private readonly IServiceProvider _serviceProvider;
|
||||||
|
private readonly IMqSender _mqSender;
|
||||||
|
|
||||||
|
public TcpServiceReceivedPlugin(IServiceProvider serviceProvider, IMqSender mqSender)
|
||||||
|
{
|
||||||
|
_serviceProvider = serviceProvider;
|
||||||
|
_mqSender = mqSender;
|
||||||
|
}
|
||||||
|
|
||||||
[GeneratorPlugin(typeof(ITcpReceivedPlugin))]
|
[GeneratorPlugin(typeof(ITcpReceivedPlugin))]
|
||||||
public async Task OnTcpReceived(ITcpSessionClient client, ReceivedDataEventArgs e)
|
public async Task OnTcpReceived(ITcpSessionClient client, ReceivedDataEventArgs e)
|
||||||
{
|
{
|
||||||
@ -16,7 +28,7 @@ namespace JiShe.CollectBus.Core.Plugins
|
|||||||
|
|
||||||
//const string protocolType = "StandardProtocol";
|
//const string protocolType = "StandardProtocol";
|
||||||
|
|
||||||
//var protocolPlugin = serviceProvider.GetKeyedService<IProtocolPlugin>(protocolType);
|
//var protocolPlugin = _serviceProvider.GetKeyedService<IProtocolPlugin>(protocolType);
|
||||||
//var protocolPluginInfo = await protocolPlugin.GetAsync();
|
//var protocolPluginInfo = await protocolPlugin.GetAsync();
|
||||||
//client.Logger.Info($"{protocolPluginInfo.Name},{protocolPluginInfo.RegularExpression}");
|
//client.Logger.Info($"{protocolPluginInfo.Name},{protocolPluginInfo.RegularExpression}");
|
||||||
////从客户端收到信息
|
////从客户端收到信息
|
||||||
@ -25,8 +37,7 @@ namespace JiShe.CollectBus.Core.Plugins
|
|||||||
|
|
||||||
//await protocolPlugin.ReceivedAsync(client,e);
|
//await protocolPlugin.ReceivedAsync(client,e);
|
||||||
|
|
||||||
|
await _mqSender.SendToReportAsync(new ReportDto
|
||||||
await sender.SendToReportAsync(new ReportDto
|
|
||||||
{
|
{
|
||||||
ClientIP = client.IP,
|
ClientIP = client.IP,
|
||||||
ClientId = client.Id,
|
ClientId = client.Id,
|
||||||
|
|||||||
@ -3,7 +3,7 @@ using MassTransit;
|
|||||||
|
|
||||||
namespace JiShe.CollectBus.RabbitMQ.Consumers
|
namespace JiShe.CollectBus.RabbitMQ.Consumers
|
||||||
{
|
{
|
||||||
internal class ReportConsumer : IConsumer<ReportDto>
|
public class ReportConsumer : IConsumer<ReportDto>
|
||||||
{
|
{
|
||||||
public async Task Consume(ConsumeContext<ReportDto> context)
|
public async Task Consume(ConsumeContext<ReportDto> context)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -45,6 +45,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||||||
s.ExchangeType = ExchangeType.Direct;
|
s.ExchangeType = ExchangeType.Direct;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
//cfg.UseRawJsonSerializer();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
services.AddMassTransitHostedService();
|
services.AddMassTransitHostedService();
|
||||||
|
|||||||
@ -4,7 +4,8 @@
|
|||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<LangVersion>preview</LangVersion>
|
<LangVersion>preview</LangVersion>
|
||||||
|
<JsonSerializerIsReflectionEnabledByDefault>true</JsonSerializerIsReflectionEnabledByDefault>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace JiShe.CollectBus.RabbitMQ.Models
|
namespace JiShe.CollectBus.RabbitMQ.Models
|
||||||
|
|||||||
@ -7,7 +7,7 @@ using JiShe.CollectBus.Common.Extensions.DependencyInjections;
|
|||||||
|
|
||||||
namespace JiShe.CollectBus.RabbitMQ.Senders
|
namespace JiShe.CollectBus.RabbitMQ.Senders
|
||||||
{
|
{
|
||||||
public interface IMqSender : ISingletonDependency
|
public interface IMqSender
|
||||||
{
|
{
|
||||||
Task SendToPushAsync<T>(T message, CancellationToken cancellationToken = default) where T : class;
|
Task SendToPushAsync<T>(T message, CancellationToken cancellationToken = default) where T : class;
|
||||||
Task SendToPushAsync(object message, CancellationToken cancellationToken = default);
|
Task SendToPushAsync(object message, CancellationToken cancellationToken = default);
|
||||||
|
|||||||
@ -4,7 +4,7 @@ using Microsoft.Extensions.Configuration;
|
|||||||
|
|
||||||
namespace JiShe.CollectBus.RabbitMQ.Senders
|
namespace JiShe.CollectBus.RabbitMQ.Senders
|
||||||
{
|
{
|
||||||
public class MqSender : IMqSender
|
public class MqSender : IMqSender, ISingletonDependency
|
||||||
{
|
{
|
||||||
private readonly ISendEndpointProvider _sendEndpointProvider;
|
private readonly ISendEndpointProvider _sendEndpointProvider;
|
||||||
private readonly IConfiguration _configuration;
|
private readonly IConfiguration _configuration;
|
||||||
@ -17,26 +17,29 @@ namespace JiShe.CollectBus.RabbitMQ.Senders
|
|||||||
|
|
||||||
public async Task SendToPushAsync<T>(T message, CancellationToken cancellationToken = default) where T : class
|
public async Task SendToPushAsync<T>(T message, CancellationToken cancellationToken = default) where T : class
|
||||||
{
|
{
|
||||||
var queueName = _configuration["MQ:Queue:Push"];
|
var queueKey = _configuration["MQ:Queue:Push"];
|
||||||
await SendAsync(queueName, message, cancellationToken);
|
await SendAsync(queueKey, message, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SendToPushAsync(object message, CancellationToken cancellationToken = default)
|
public async Task SendToPushAsync(object message, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var queueName = _configuration["MQ:Queue:Push"];
|
var queueKey = _configuration["MQ:Queue:Push"];
|
||||||
await SendAsync(queueName, message, cancellationToken);
|
await SendAsync(queueKey, message, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SendToReportAsync<T>(T message, CancellationToken cancellationToken = default) where T : class
|
public async Task SendToReportAsync<T>(T message, CancellationToken cancellationToken = default) where T : class
|
||||||
{
|
{
|
||||||
var queueName = _configuration["MQ:Queue:Report"];
|
var queueKey = _configuration["MQ:Queue:Report"];
|
||||||
await SendAsync(queueName, message, cancellationToken);
|
//await SendAsync(queueName, message, cancellationToken);
|
||||||
|
var endpoint = await _sendEndpointProvider.GetSendEndpoint(new Uri($"queue:{queueKey}"));
|
||||||
|
await endpoint.Send(message,typeof(T),cancellationToken);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SendToReportAsync(object message, CancellationToken cancellationToken = default)
|
public async Task SendToReportAsync(object message, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var queueName = _configuration["MQ:Queue:Report"];
|
var queueKey = _configuration["MQ:Queue:Report"];
|
||||||
await SendAsync(queueName, message, cancellationToken);
|
await SendAsync(queueKey, message, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user