Merge pull request '🍒 fix(EventBus): 默认不使用RabbitMQ中间件处理事件源,防止没环境抛异常' (#423) from jasondom/Admin.NET.Pro:v2-fix into v2

Reviewed-on: https://code.adminnet.top/Admin.NET/Admin.NET.Pro/pulls/423
This commit is contained in:
zuohuaijun 2025-08-27 10:37:15 +08:00
commit f9f90d8b1a
2 changed files with 9 additions and 6 deletions

View File

@ -11,7 +11,7 @@
"EventBus": {
// Redis
"EventSourceType": "RabbitMQ", // MemoryRedisRabbitMQKafka
"EventSourceType": "Memory", // MemoryRedisRabbitMQKafka
"Kafka": {
}

View File

@ -14,10 +14,13 @@ public static class RabbitMQExtention
public static IServiceCollection AddRabbitMQ<THandler>(this IServiceCollection services)
where THandler : class, IMessageHandler
{
services.AddSingleton<IMessageHandler, THandler>();
services.AddSingleton<RabbitMqConnection>();
services.AddSingleton<RabbitMqProducer>();
services.AddHostedService<RabbitMqConsumer>();
if (App.GetConfig<string>("EventBus:EventSourceType", true) == "RabbitMQ")
{
services.AddSingleton<IMessageHandler, THandler>();
services.AddSingleton<RabbitMqConnection>();
services.AddSingleton<RabbitMqProducer>();
services.AddHostedService<RabbitMqConsumer>();
}
return services;
}
}
}