This commit is contained in:
2023-05-31 10:19:05 +08:00
parent 1b65a7a9e5
commit 9c621c75cd
238 changed files with 9905 additions and 4034 deletions

View File

@@ -0,0 +1,55 @@
using JNPF.ConfigurableOptions;
namespace JNPF.Common.Core;
/// <summary>
/// 事件总线配置.
/// </summary>
public class EventBusOptions : IConfigurableOptions
{
/// <summary>
/// 事件总线类型.
/// </summary>
public EventBusType EventBusType { get; set; }
/// <summary>
/// 服务器地址.
/// </summary>
public string HostName { get; set; }
/// <summary>
/// 账号.
/// </summary>
public string UserName { get; set; }
/// <summary>
/// 密码.
/// </summary>
public string Password { get; set; }
}
/// <summary>
/// 事件总线自定义事件源存储器类型.
/// </summary>
public enum EventBusType
{
/// <summary>
/// 内存.
/// </summary>
Memory,
/// <summary>
/// RabbitMQ.
/// </summary>
RabbitMQ,
/// <summary>
/// Redis.
/// </summary>
Redis,
/// <summary>
/// Kafka.
/// </summary>
Kafka,
}

View File

@@ -42,7 +42,7 @@ public class LogEventSubscriber : IEventSubscriber, ISingleton
_sqlSugarClient.ChangeDatabase(log.ConnectionConfig.ConfigId);
}
await _sqlSugarClient.Insertable(log.Entity).IgnoreColumns(ignoreNullColumn: true).ExecuteCommandAsync();
await _sqlSugarClient.CopyNew().Insertable(log.Entity).IgnoreColumns(ignoreNullColumn: true).ExecuteCommandAsync();
}
/// <summary>
@@ -61,6 +61,6 @@ public class LogEventSubscriber : IEventSubscriber, ISingleton
_sqlSugarClient.ChangeDatabase(log.ConnectionConfig.ConfigId);
}
await _sqlSugarClient.Insertable(log.Entity).IgnoreColumns(ignoreNullColumn: true).ExecuteCommandAsync();
await _sqlSugarClient.CopyNew().Insertable(log.Entity).IgnoreColumns(ignoreNullColumn: true).ExecuteCommandAsync();
}
}

View File

@@ -1,5 +1,5 @@
using JNPF.Systems.Entitys.System;
using JNPF.EventBus;
using JNPF.EventBus;
using JNPF.TaskScheduler.Entitys;
using SqlSugar;
namespace JNPF.EventHandler;

View File

@@ -1,5 +1,5 @@
using JNPF.Systems.Entitys.System;
using JNPF.EventBus;
using JNPF.EventBus;
using JNPF.TaskScheduler.Entitys;
using SqlSugar;
namespace JNPF.EventHandler;

View File

@@ -1,4 +1,5 @@
using JNPF.Common.Security;
using JNPF.Common.Extension;
using JNPF.Common.Security;
using JNPF.EventBus;
using JNPF.Logging;
using RabbitMQ.Client;
@@ -59,8 +60,6 @@ public sealed class RabbitMQEventSourceStorer : IEventSourceStorer, IDisposable
// 创建通道
_model = _connection.CreateModel();
string ExchangeName = "MXK_IDENTITY_MAIN_TOPIC";
/*
* 声明路由队列
* 队列可以重复声明,但是声明所使用的参数必须一致,否则会抛出异常
@@ -77,7 +76,7 @@ public sealed class RabbitMQEventSourceStorer : IEventSourceStorer, IDisposable
_model.QueueDeclare(queue: routeKey, durable: false, exclusive: false, autoDelete: false, arguments: null);
// 将MaxKey 交换机绑定到 路由中
_model.QueueBind(queue: routeKey, exchange: ExchangeName, routingKey: "#");
// _model.QueueBind(queue: routeKey, exchange: "MXK_IDENTITY_MAIN_TOPIC", routingKey: "#");
// 字节限制,一次接收的消息数,全局/
// 据说prefetchSize 和global这两项rabbitmq没有实现暂且不研究
@@ -95,6 +94,9 @@ public sealed class RabbitMQEventSourceStorer : IEventSourceStorer, IDisposable
// 转换为 IEventSource这里可以选择自己喜欢的序列化工具如果自定义了 EventSource注意属性是可读可写
var eventSource = JsonSerializer.Deserialize<ChannelEventSource>(stringEventSource);
// 判断到是单点登录服务端信息
if (eventSource.EventId.IsNullOrEmpty()) eventSource = new ChannelEventSource("User:Maxkey_Identity", stringEventSource);
Log.Information($"- 接收到消息:{eventSource.ToJsonString()}");
// 写入内存管道存储器
@@ -105,7 +107,7 @@ public sealed class RabbitMQEventSourceStorer : IEventSourceStorer, IDisposable
};
// 启动消费者 设置为手动应答消息
_model.BasicConsume(queue: routeKey, autoAck: true, consumer: consumer);
_model.BasicConsume(queue: routeKey, autoAck: false, consumer: consumer);
}
/// <summary>
@@ -122,7 +124,7 @@ public sealed class RabbitMQEventSourceStorer : IEventSourceStorer, IDisposable
throw new ArgumentNullException(nameof(eventSource));
}
// 这里判断是否是 ChannelEventSource 或者 自定义的 EventSouce
// 这里判断是否是 ChannelEventSource 或者 自定义的 EventSource
if (eventSource is ChannelEventSource source)
{
// 序列化,这里可以选择自己喜欢的序列化工具
@@ -146,7 +148,8 @@ public sealed class RabbitMQEventSourceStorer : IEventSourceStorer, IDisposable
public async ValueTask<IEventSource> ReadAsync(CancellationToken cancellationToken)
{
// 读取一条事件源
return await _channel.Reader.ReadAsync(cancellationToken);
var eventSource = await _channel.Reader.ReadAsync(cancellationToken);
return eventSource;
}
/// <summary>

View File

@@ -1,7 +1,7 @@
using JNPF.Common.Configuration;
using JNPF.DependencyInjection;
using JNPF.EventBus;
using JNPF.Systems.Entitys.System;
using JNPF.TaskScheduler.Entitys;
using SqlSugar;
namespace JNPF.EventHandler;
@@ -40,7 +40,7 @@ public class TaskEventSubscriber : IEventSubscriber, ISingleton
_sqlSugarClient.ChangeDatabase(log.ConnectionConfig.ConfigId);
}
await _sqlSugarClient.Updateable<TimeTaskEntity>().SetColumns(x => new TimeTaskEntity()
await _sqlSugarClient.CopyNew().Updateable<TimeTaskEntity>().SetColumns(x => new TimeTaskEntity()
{
RunCount = x.RunCount + 1,
LastRunTime = DateTime.Now,

View File

@@ -1,6 +1,7 @@
using JNPF.Common.Configuration;
using JNPF.DependencyInjection;
using JNPF.EventBus;
using JNPF.Systems.Interfaces.Permission;
using SqlSugar;
namespace JNPF.EventHandler;
@@ -15,12 +16,20 @@ public class UserEventSubscriber : IEventSubscriber, ISingleton
/// </summary>
private static SqlSugarScope? _sqlSugarClient;
/// <summary>
/// 用户服务.
/// </summary>
private readonly IUsersService _usersService;
/// <summary>
/// 构造函数.
/// </summary>
public UserEventSubscriber(ISqlSugarClient context)
public UserEventSubscriber(
ISqlSugarClient context,
IUsersService usersService)
{
_sqlSugarClient = (SqlSugarScope)context;
_usersService = usersService;
}
/// <summary>
@@ -39,7 +48,7 @@ public class UserEventSubscriber : IEventSubscriber, ISingleton
_sqlSugarClient.ChangeDatabase(log.ConnectionConfig.ConfigId);
}
await _sqlSugarClient.Updateable(log.Entity).UpdateColumns(m => new { m.FirstLogIP, m.FirstLogTime, m.PrevLogTime, m.PrevLogIP, m.LastLogTime, m.LastLogIP, m.LogSuccessCount }).ExecuteCommandAsync();
await _sqlSugarClient.CopyNew().Updateable(log.Entity).UpdateColumns(m => new { m.FirstLogIP, m.FirstLogTime, m.PrevLogTime, m.PrevLogIP, m.LastLogTime, m.LastLogIP, m.LogSuccessCount }).ExecuteCommandAsync();
}
/// <summary>
@@ -47,9 +56,10 @@ public class UserEventSubscriber : IEventSubscriber, ISingleton
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
[EventSubscribe("User:maxkey_identity")]
[EventSubscribe("User:Maxkey_Identity")]
public async Task ReceiveUserInfo(EventHandlerExecutingContext context)
{
var log = (UserEventSource)context.Source;
var log = context.Source.Payload;
await _usersService.Receive(log.ToString());
}
}