😎修复redis事件订阅程序获取负载 Payload 异常问题

This commit is contained in:
zuohuaijun 2024-11-20 14:19:00 +08:00
parent b71aa7ecdd
commit b385b913b0
6 changed files with 81 additions and 44 deletions

View File

@ -11,7 +11,7 @@
"DbType": "Sqlite", // MySqlSqlServerSqliteOraclePostgreSQLDmKdbndpOscarMySqlConnectorAccessOpenGaussQuestDBHGClickHouseGBaseOdbcCustom
"ConnectionString": "DataSource=./Admin.NET.db", // Sqlite
//"ConnectionString": "PORT=5432;DATABASE=xxx;HOST=localhost;PASSWORD=xxx;USER ID=xxx", // PostgreSQL
//"ConnectionString": "Server=localhost;Database=xxx;Uid=xxx;Pwd=xxx;SslMode=None;", // MySql,
//"ConnectionString": "Server=localhost;Database=xxx;Uid=xxx;Pwd=xxx;SslMode=None;AllowLoadLocalInfile=true;AllowUserVariables=true;", // MySql,
//"ConnectionString": "User Id=xxx; Password=xxx; Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL)))", // Oracle
//"ConnectionString": "Server=localhost;Database=xxx;User Id=xxx;Password=xxx;Encrypt=True;TrustServerCertificate=True;", // SqlServer

View File

@ -6,23 +6,23 @@
namespace Admin.NET.Application;
///// <summary>
///// 示例开放接口
///// </summary>
//[ApiDescriptionSettings("开放接口", Name = "Demo", Order = 100)]
//[Authorize(AuthenticationSchemes = SignatureAuthenticationDefaults.AuthenticationScheme)]
//public class DemoOpenApi : IDynamicApiController
//{
// private readonly UserManager _userManager;
/// <summary>
/// 开放接口示例
/// </summary>
[ApiDescriptionSettings("开放接口", Name = "Demo", Order = 100)]
[Authorize(AuthenticationSchemes = SignatureAuthenticationDefaults.AuthenticationScheme)]
public class DemoOpenApi : IDynamicApiController
{
private readonly UserManager _userManager;
// public DemoOpenApi(UserManager userManager)
// {
// _userManager = userManager;
// }
public DemoOpenApi(UserManager userManager)
{
_userManager = userManager;
}
// [HttpGet("helloWord")]
// public Task<string> HelloWord()
// {
// return Task.FromResult($"Hello word. {_userManager.Account}");
// }
//}
[HttpGet("helloWord")]
public Task<string> HelloWord()
{
return Task.FromResult($"Hello, {_userManager.Account}.");
}
}

View File

@ -0,0 +1,38 @@
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
//
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
//
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using Furion.EventBus;
namespace Admin.NET.Application;
/// <summary>
/// 测试服务
/// </summary>
[ApiDescriptionSettings(ApplicationConst.GroupName, Order = 100, Description = "测试服务")]
public class TestService : IDynamicApiController
{
private readonly UserManager _userManager;
public TestService(UserManager userManager)
{
_userManager = userManager;
}
[HttpGet("helloWord")]
public Task<string> HelloWord()
{
return Task.FromResult($"Hello, {_userManager.Account}.");
}
/// <summary>
/// Redis事件测试 - Payload 🔖
/// </summary>
/// <returns></returns>
public async void EventTestAsync()
{
await App.GetRequiredService<IEventPublisher>().PublishAsync(CommonConst.SendErrorMail, "Admin.NET");
}
}

View File

@ -17,10 +17,10 @@
<PackageReference Include="AngleSharp" Version="1.1.2" />
<PackageReference Include="AspectCore.Extensions.Reflection" Version="2.4.0" />
<PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" />
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.15.10" />
<PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.9.5.23" />
<PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.9.5.23" />
<PackageReference Include="Furion.Pure" Version="4.9.5.23" />
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.16.0" />
<PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.9.5.24" />
<PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.9.5.24" />
<PackageReference Include="Furion.Pure" Version="4.9.5.24" />
<PackageReference Include="Hardware.Info" Version="101.0.0" />
<PackageReference Include="Hashids.net" Version="1.7.0" />
<PackageReference Include="IPTools.China" Version="1.6.0" />
@ -47,7 +47,7 @@
<PackageReference Include="SSH.NET" Version="2024.2.0" />
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.4.9" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="TencentCloudSDK.Sms" Version="3.0.1123" />
<PackageReference Include="TencentCloudSDK.Sms" Version="3.0.1125" />
<PackageReference Include="UAParser" Version="3.1.47" />
<PackageReference Include="Yitter.IdGenerator" Version="1.0.14" />
</ItemGroup>

View File

@ -27,7 +27,7 @@ public class AppEventSubscriber : IEventSubscriber, ISingleton, IDisposable
public async Task CreateExLog(EventHandlerExecutingContext context)
{
var db = _serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>();
await db.CopyNew().Insertable((SysLogEx)context.Source.Payload).ExecuteCommandAsync();
await db.CopyNew().Insertable(context.GetPayload<SysLogEx>()).ExecuteCommandAsync();
}
/// <summary>
@ -44,7 +44,7 @@ public class AppEventSubscriber : IEventSubscriber, ISingleton, IDisposable
var webTitle = await _serviceScope.ServiceProvider.GetRequiredService<SysConfigService>().GetConfigValueByCode<string>(ConfigConst.SysWebTitle);
var title = $"{webTitle} 系统异常";
await _serviceScope.ServiceProvider.GetRequiredService<SysEmailService>().SendEmail(JSON.Serialize(context.Source.Payload), title);
await _serviceScope.ServiceProvider.GetRequiredService<SysEmailService>().SendEmail(JSON.Serialize(context.GetPayload<string>()), title);
}
/// <summary>

View File

@ -1,26 +1,25 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests" />
<link rel="stylesheet" type="text/css" media="print" href="/print-lock.css" />
<link rel="icon" id="favicon" href="data:;base64,=" />
<title>正在加载中...</title>
</head>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" media="print" href="/print-lock.css" />
<link rel="icon" id="favicon" href="data:;base64,=" />
<title>正在加载中...</title>
</head>
<body>
<div id="app"></div>
<script src="/config.js"></script>
<script type="module" src="/src/main.ts"></script>
<!-- <script type="text/javascript" src="https://api.map.baidu.com/api?v=3.0&ak=wsijQt8sLXrCW71YesmispvYHitfG9gv&s=1"></script> -->
<!-- <script src="https://res.zvo.cn/translate/translate.js"></script>
<body>
<div id="app"></div>
<script src="/config.js"></script>
<script type="module" src="/src/main.ts"></script>
<!-- <script type="text/javascript" src="https://api.map.baidu.com/api?v=3.0&ak=wsijQt8sLXrCW71YesmispvYHitfG9gv&s=1"></script> -->
<!-- <script src="https://res.zvo.cn/translate/translate.js"></script>
<script>
translate.language.setLocal('english'); //设置本地语种。默认是 'chinese_simplified' 简体中文。 可填写如 'english'、'chinese_simplified' 等。
translate.listener.start(); // 开启html页面变化的监控对变化部分会进行自动翻译。这里变化区域是指使用 translate.setDocuments(...) 设置的区域。
translate.execute(); // 执行翻译初始化操作显示出select语言选择
</script> -->
</body>
</html>
</body>
</html>