😎优化自定义事件源存储
This commit is contained in:
parent
57dbfd3e01
commit
0bc75bb7d5
@ -2,11 +2,15 @@
|
|||||||
"$schema": "https://gitee.com/dotnetchina/Furion/raw/v4/schemas/v4/furion-schema.json",
|
"$schema": "https://gitee.com/dotnetchina/Furion/raw/v4/schemas/v4/furion-schema.json",
|
||||||
|
|
||||||
"EventBus": {
|
"EventBus": {
|
||||||
|
// 事件源存储器类型,默认内存存储(Redis则需要配合缓存相关配置)
|
||||||
|
"EventSourceType": "Memory", // Memory、Redis、RabbitMQ、Kafka
|
||||||
"RabbitMQ": {
|
"RabbitMQ": {
|
||||||
"UserName": "adminnet",
|
"UserName": "adminnet",
|
||||||
"Password": "adminnet++123456",
|
"Password": "adminnet++123456",
|
||||||
"HostName": "127.0.0.1",
|
"HostName": "127.0.0.1",
|
||||||
"Port": 5672
|
"Port": 5672
|
||||||
|
},
|
||||||
|
"Kafka": {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -11,6 +11,11 @@ namespace Admin.NET.Core;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class EventBusOptions : IConfigurableOptions
|
public sealed class EventBusOptions : IConfigurableOptions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 事件源存储器类型
|
||||||
|
/// </summary>
|
||||||
|
public string EventSourceType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// RabbitMQ
|
/// RabbitMQ
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -24,6 +24,7 @@ using Microsoft.Extensions.FileProviders;
|
|||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using OnceMi.AspNetCore.OSS;
|
using OnceMi.AspNetCore.OSS;
|
||||||
|
using RabbitMQ.Client;
|
||||||
using SixLabors.ImageSharp.Web.DependencyInjection;
|
using SixLabors.ImageSharp.Web.DependencyInjection;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -150,46 +151,40 @@ public class Startup : AppStartup
|
|||||||
options.UnobservedTaskExceptionHandler = (obj, args) =>
|
options.UnobservedTaskExceptionHandler = (obj, args) =>
|
||||||
{
|
{
|
||||||
if (args.Exception?.Message != null)
|
if (args.Exception?.Message != null)
|
||||||
Log.Error($"EeventBus 有未处理异常 :{args.Exception?.Message} ", args.Exception);
|
Log.Error($"事件总线未处理异常 :{args.Exception?.Message} ", args.Exception);
|
||||||
};
|
};
|
||||||
//// 事件执行监视器(执行之前、执行之后、执行异常)
|
//// 事件执行监视器(执行之前、执行之后、执行异常)
|
||||||
//options.AddMonitor<EventHandlerMonitor>();
|
//options.AddMonitor<EventHandlerMonitor>();
|
||||||
|
|
||||||
#region Redis消息队列
|
// 自定义事件源存储器
|
||||||
|
var eventBusOpt = App.GetConfig<EventBusOptions>("EventBus", true);
|
||||||
// 替换事件源存储器为Redis
|
if (eventBusOpt.EventSourceType == "Redis")
|
||||||
var cacheOptions = App.GetConfig<CacheOptions>("Cache", true);
|
|
||||||
if (cacheOptions.CacheType == CacheTypeEnum.Redis.ToString())
|
|
||||||
{
|
{
|
||||||
|
// Redis消息队列
|
||||||
|
if (App.GetConfig<CacheOptions>("Cache", true).CacheType == CacheTypeEnum.Redis.ToString())
|
||||||
|
{
|
||||||
|
options.ReplaceStorerOrFallback(serviceProvider =>
|
||||||
|
{
|
||||||
|
var cacheProvider = serviceProvider.GetRequiredService<NewLife.Caching.ICacheProvider>();
|
||||||
|
return new RedisEventSourceStorer(cacheProvider, "adminnet_eventsource_queue", 3000);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (eventBusOpt.EventSourceType == "RabbitMQ")
|
||||||
|
{
|
||||||
|
// RabbitMQ消息队列
|
||||||
|
var rbmqEventSourceStorer = new RabbitMQEventSourceStore(new ConnectionFactory
|
||||||
|
{
|
||||||
|
UserName = eventBusOpt.RabbitMQ.UserName,
|
||||||
|
Password = eventBusOpt.RabbitMQ.Password,
|
||||||
|
HostName = eventBusOpt.RabbitMQ.HostName,
|
||||||
|
Port = eventBusOpt.RabbitMQ.Port
|
||||||
|
}, "adminnet_eventsource_queue", 3000);
|
||||||
options.ReplaceStorerOrFallback(serviceProvider =>
|
options.ReplaceStorerOrFallback(serviceProvider =>
|
||||||
{
|
{
|
||||||
var cacheProvider = serviceProvider.GetRequiredService<NewLife.Caching.ICacheProvider>();
|
return rbmqEventSourceStorer;
|
||||||
// 创建默认内存通道事件源对象,可自定义队列路由key,如:adminnet_eventsource_queue
|
|
||||||
return new RedisEventSourceStorer(cacheProvider, "adminnet_eventsource_queue", 3000);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Redis消息队列
|
|
||||||
|
|
||||||
#region RabbitMQ消息队列
|
|
||||||
|
|
||||||
//// 创建默认内存通道事件源对象,可自定义队列路由key,如:adminnet
|
|
||||||
//var eventBusOpt = App.GetConfig<EventBusOptions>("EventBus", true);
|
|
||||||
//var rbmqEventSourceStorer = new RabbitMQEventSourceStore(new ConnectionFactory
|
|
||||||
//{
|
|
||||||
// UserName = eventBusOpt.RabbitMQ.UserName,
|
|
||||||
// Password = eventBusOpt.RabbitMQ.Password,
|
|
||||||
// HostName = eventBusOpt.RabbitMQ.HostName,
|
|
||||||
// Port = eventBusOpt.RabbitMQ.Port
|
|
||||||
//}, "adminnet", 3000);
|
|
||||||
|
|
||||||
//// 替换默认事件总线存储器
|
|
||||||
//options.ReplaceStorer(serviceProvider =>
|
|
||||||
//{
|
|
||||||
// return rbmqEventSourceStorer;
|
|
||||||
//});
|
|
||||||
|
|
||||||
#endregion RabbitMQ消息队列
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 图像处理
|
// 图像处理
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user