sunpengfei
2025-08-13 6b2c36c4b5533584783955819d766d013c23f2ac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using Furion;
using Furion.EventBus;
using Microsoft.Extensions.DependencyInjection;
using RabbitMQ.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
 
namespace FlexJobApi.Core
{
    /// <summary>
    /// 事件总线
    /// </summary>
    public class EventBusServiceComponent : IServiceComponent
    {
        public void Load(IServiceCollection services, ComponentContext componentContext)
        {
            services.AddEventBus(options =>
            {
                // 创建连接工厂
                var factory = new ConnectionFactory
                {
                    HostName = "118.178.252.28",
                    Port = 5672,
                    UserName = "admin",
                    Password = "Bole12345678",
                };
 
                // 创建默认内存通道事件源对象,可自定义队列路由key,比如这里是启动项目名称
                var rbmqEventSourceStorer = new RabbitMQEventSourceStorer(factory, Assembly.GetExecutingAssembly().GetName().Name, 12000);
 
                // 替换默认事件总线存储器
                options.ReplaceStorer(serviceProvider =>
                {
                    return rbmqEventSourceStorer;
                });
            });
        }
    }
}