using JNPF;
using JNPF.Common.Core;
using JNPF.Common.Options;
using JNPF.EventHandler;
using OnceMi.AspNetCore.OSS;
namespace Microsoft.Extensions.DependencyInjection;
///
/// OSS服务配置拓展.
///
public static class ConfigureEventBusExtensions
{
///
/// OSS服务配置.
///
///
///
public static IServiceCollection ConfigureEventBus(this IServiceCollection services)
{
// 注册EventBus服务
// 注册EventBus服务
services.AddEventBus(options =>
{
var config = App.GetOptions();
if (config.EventBusType != EventBusType.Memory)
{
switch (config.EventBusType)
{
case EventBusType.RabbitMQ:
// 创建连接工厂
var factory = new RabbitMQ.Client.ConnectionFactory
{
// 设置主机名
HostName = config.HostName,
// 用户名
UserName = config.UserName,
// 密码
Password = config.Password,
};
// 创建默认内存通道事件源对象,可自定义队列路由key,比如这里是 eventbus
var rbmqEventSourceStorer = new RabbitMQEventSourceStorer(factory, "eventbus", 3000);
// 替换默认事件总线存储器
options.ReplaceStorer(serviceProvider =>
{
return rbmqEventSourceStorer;
});
break;
}
}
options.UseUtcTimestamp = false;
// 不启用事件日志
options.LogEnabled = false;
// 事件执行器(失败重试)
options.AddExecutor();
});
services.AddConfigurableOptions();
return services;
}
}