Esempio n. 1
0
 public static IEventBusBuilder UseRabbitMQ(this IEventBusBuilder builder, string sectionPath = "EventBus:RabbitMQ")
 {
     builder.Services.Configure <EventBusRabbitMqOptions>(builder.Configuration.GetSection(sectionPath));
     builder.Services.AddSingleton <IRabbitMQPersistentConnection, DefaultRabbitMQPersistentConnection>();
     builder.Services.AddSingleton <IEventBus, EventBusRabbitMQ>();
     return(builder);
 }
Esempio n. 2
0
        public static IEventBusBuilder AddEventObservers(this IEventBusBuilder builder, Action <IEventObserverBuilder> action)
        {
            builder.AddEventObservers();
            action(new EventObserverBuilder(builder.Services));

            return(builder);
        }
        public static IEventBusBuilder AddSubscriber <TEvent, THandler>(
            this IEventBusBuilder builder,
            string exchangeName,
            string queueName)
            where TEvent : IntegrationEvent
            where THandler : class, IIntegrationEventHandler <TEvent>
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (exchangeName == null)
            {
                throw new ArgumentNullException(nameof(exchangeName));
            }

            if (queueName == null)
            {
                throw new ArgumentNullException(nameof(queueName));
            }

            builder.Services.AddTransient <THandler>();

            builder.Services.AddSingleton(new SubscriberInfo
            {
                EventType    = typeof(TEvent),
                HandlerType  = typeof(THandler),
                ExchangeName = exchangeName,
                QueueName    = queueName
            });

            return(builder);
        }
Esempio n. 4
0
        /// <summary>
        /// 应用模块服务
        /// </summary>
        /// <param name="provider">服务提供者</param>
        public override void UsePack(IServiceProvider provider)
        {
            IEventBusBuilder builder = provider.GetService <IEventBusBuilder>();

            builder.Build();
            IsEnabled = true;
        }
Esempio n. 5
0
 public static IEventBusBuilder UseRabbitMQ(this IEventBusBuilder builder)
 {
     builder.Services.Configure <ConnectionFactory>(builder.Configuration.GetSection("EventBus:RabbitMQ"));
     builder.Services.AddSingleton <IRabbitMQPersistentConnection, DefaultRabbitMQPersistentConnection>();
     builder.Services.AddSingleton <IEventBus, EventBusRabbitMQ>();
     return(builder);
 }
Esempio n. 6
0
        public static IEventBusBuilder AddEventListeners(this IEventBusBuilder builder, Action <EventServiceCollectionConfigurator> configure)
        {
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            var configurator = new ServiceCollectionConfigurator(builder.Services);
            var wrapper      = new EventServiceCollectionConfigurator(configurator);

            configure(wrapper);

            builder.Services.AddSingleton(configurator);
            builder.Services.AddSingleton(provider => EventBusFactory.Build(cfg =>
            {
                var host = cfg.Host(new Uri(builder.Settings.ConnectionString), h =>
                {
                    h.Username(builder.Settings.UserName);
                    h.Password(builder.Settings.Password);
                });

                cfg.ReceiveEndpoint(host, wrapper.EventQueueName, e =>
                {
                    e.LoadFrom(provider);
                });
            }));

            builder.Services.AddSingleton <IHostedService, ServiceBusEventHost>();
            return(builder);
        }
        public static IEventBusBuilder AddMemoryProvider(this IEventBusBuilder builder)
        {
            var services = builder.Services;

            services.TryAddSingleton <IEventBus, MemoryEventBus>();
            return(builder);
        }
Esempio n. 8
0
        /// <summary>
        /// 应用模块服务
        /// </summary>
        /// <param name="app">应用程序构建器</param>
        public override void UsePack(IApplicationBuilder app)
        {
            IEventBusBuilder builder = app.ApplicationServices.GetService <IEventBusBuilder>();

            builder.Build();
            IsEnabled = true;
        }
Esempio n. 9
0
        public static IEventBusBuilder UseJsonSerializer(this IEventBusBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.UseSerializer <JsonEventSerializer>());
        }
Esempio n. 10
0
        public static IEventBusBuilder UseRabbitMQ(this IEventBusBuilder builder, Action <RabbitMqOptions> optionsAction)
        {
            Check.NotNull(optionsAction, nameof(optionsAction));

            builder.Fx.AddRabbitMQ(optionsAction);
            builder.Fx.Services.AddSingleton <IEventBus, RabbitMqDistributedEventBus>();

            return(builder);
        }
Esempio n. 11
0
        public static IEventBusBuilder AddEventObservers(this IEventBusBuilder builder)
        {
            var services = builder.Services;

            services.TryAddSingleton <IEventBusRegistrator, EventBusRegistrator>();
            services.TryAddSingleton <IEventObserverFactory, EventObserverFactory>();
            services.AddApplicationStageObject <EventObserverRegisterService>();

            return(builder);
        }
        public static IEventBusBuilder PublishToAmazonSns(this IEventBusBuilder builder,
                                                          Action <AmazonSnsEventPublisherOptions> setupActions)
        {
            builder.Services
            .Configure(setupActions)
            ;

            return(builder
                   .AddEventPublisher <AmazonSnsEventPublisher>());
        }
Esempio n. 13
0
        public static IEventBusBuilder Configure <TOptions>(this IEventBusBuilder builder, Action <TOptions> configureOptions) where TOptions : class
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Services.Configure(builder.Name, configureOptions);

            return(builder);
        }
        /// <summary>
        /// Register event handler for the event interface.
        /// </summary>
        /// <typeparam name="TEventInterface">Event interface of the type <see cref="IEvent"/>.</typeparam>
        /// <typeparam name="TImplementation">Handler for the event interface.</typeparam>
        /// <param name="builder">Instance of <see cref="IEventBusBuilder"/>.</param>
        /// <returns>Instance of <see cref="IEventBusBuilder"/>.</returns>
        public static IEventBusBuilder AddHandler <TEventInterface, TImplementation>(this IEventBusBuilder builder)
            where TEventInterface : IEvent
            where TImplementation : class, IEventHandler <TEventInterface>
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.Add(EventHandlerRegistration.Register <TEventInterface, TImplementation>()));
        }
Esempio n. 15
0
        public static IEventBusBuilder AddInMemoryEventBus(this IEventBusBuilder builder, Action <IEventBusSubscriber> subscribeAction)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var subscriber = new InMemoryEventBusSubscriber(builder.Services);

            subscribeAction?.Invoke(subscriber);

            return(builder.AddEventPublisher <InMemoryEventBus>());
        }
Esempio n. 16
0
        public static IEventBusBuilder InitEventBus(this IEventBusBuilder builder, Action <IEventBus> configureEventBus)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (configureEventBus != null)
            {
                builder.Configure <EventBusFactoryOptions>(options => options.EventBusInitActions.Add(configureEventBus));
            }

            return(builder);
        }
        /// <summary>
        /// 使用内存事件总线
        /// </summary>
        /// <param name="builder"></param>
        /// <returns></returns>
        public static IEventBusBuilder UseMemory(this IEventBusBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Services.TryAddTransient <MemoryEventBus>();

            return(builder.Configure <EventBusFactoryOptions>(options =>
            {
                options.EventBusProvider = new MemoryEventBusProvider();
            }));
        }
Esempio n. 18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="eventBusBuilder"></param>
        /// <returns></returns>
        public static IEventBusBuilder AddOpenTracing(this IEventBusBuilder eventBusBuilder)
        {
            var services = eventBusBuilder.Services;

            /**
             * if (!GlobalTracer.IsRegistered())
             *  throw new NullReferenceException("The GlobalTracer is not registered. <null>");*/

            var eventBusDescriptor = services.First(s => s.ServiceType == typeof(IEventBus));

            var serviceProvider = services.BuildServiceProvider();

            services.Replace(ServiceDescriptor.Scoped <IEventBus>(locator =>
            {
                var eventBus = (IEventBus)(eventBusDescriptor?.ImplementationInstance ??
                                           ActivatorUtilities.GetServiceOrCreateInstance(locator, eventBusDescriptor.ImplementationType));

                return(new EventBusTracing(eventBus, GlobalTracer.Instance));
            }));

            return(eventBusBuilder);
        }
Esempio n. 19
0
 public static IEventBusBuilder Configure(this IEventBusBuilder builder, Action <EventBusOptions> configureDelegate)
 {
     return(builder);
 }
Esempio n. 20
0
 public static IEventBusBuilder AddEventPublisher(this IEventBusBuilder builder)
 {
     builder.Services.AddScoped <IIntegrationEventPublisher, EventPublisher>();
     return(builder);
 }
        public static IEventBusBuilder AddEventBusHostedService(this IEventBusBuilder builder)
        {
            builder.Services.AddHostedService <EventBusHostedService>();

            return(builder);
        }