Ejemplo n.º 1
0
        public static IServiceCollection AddEventBus(this IServiceCollection services, EventBusOptions options)
        {
            services.AddSingleton <IEventBus, EventBusRabbitMq>(sp =>
            {
                var rabbitMqPersistentConnection = sp.GetRequiredService <IRabbitMqPersistentConnection>();
                var lifetimeScope = sp.GetRequiredService <ILifetimeScope>();
                var eventBusSubscriptionsManager = sp.GetRequiredService <IEventBusSubscriptionManager>();

                var brokerName       = options.BrokerName;
                var autofacScopeName = options.AutofacScopeName;
                var queueName        = options.QueueName;
                var retryCount       = 5;

                if (!string.IsNullOrEmpty(options.RetryCount))
                {
                    retryCount = int.Parse(options.RetryCount);
                }

                return(new EventBusRabbitMq(rabbitMqPersistentConnection,
                                            lifetimeScope,
                                            eventBusSubscriptionsManager,
                                            brokerName,
                                            autofacScopeName,
                                            queueName,
                                            retryCount));
            });

            services.AddSingleton <IEventBusSubscriptionManager, InMemoryEventBusSubscriptionManager>();

            return(services);
        }
Ejemplo n.º 2
0
 public static EventBusOptions AddLocalMq(this EventBusOptions options)
 {
     options.AddExtensions(new EventBusLocalOptionsExtensions());
     return(options);
 }
 public DefaultRabbitMQPersistentConnection(ILogger <DefaultRabbitMQPersistentConnection> logger, IOptions <EventBusOptions> options)
 {
     _logger            = logger;
     _options           = options.Value;
     _connectionFactory = CreateConnectionFactory();
 }
Ejemplo n.º 4
0
 public EventBusOptionsBuilder(EventBusOptions options)
 {
     Options = options;
 }
 public static EventBusOptions AddPostgreSql(this EventBusOptions options, Action <EventBusPostgreSqlOptions> actionOptions)
 {
     options.AddExtensions(new EventBusPostgreSqlOptionsExtensions(actionOptions));
     return(options);
 }
 public static EventBusOptions AddSqlServer(this EventBusOptions options, Action <EventBusSqlServerOptions> actionOptions)
 {
     options.AddExtensions(new EventBusSqlServerOptionsExtensions(actionOptions));
     return(options);
 }
Ejemplo n.º 7
0
 public EventBusHostedService(IServiceProvider serviceProvider, IOptions <EventBusOptions> eventBusOptions)
 {
     this.serviceProvider = serviceProvider;
     this.eventBusOptions = eventBusOptions.Value;
 }
Ejemplo n.º 8
0
 public QueryEventBusTimedHostedService(ILogger <QueryEventBusTimedHostedService> logger, IQueryEventBus queryEventBus, IOptionsMonitor <EventBusOptions> eventBusOptionsAccessor)
 {
     _logger          = logger;
     _queryEventBus   = queryEventBus;
     _eventBusOptions = eventBusOptionsAccessor.CurrentValue;
 }
        public static IServiceCollection AddEventBus(this IServiceCollection services, EventBusOptions eventBusOptions)
        {
            services.AddTransient <IIntegrationEventService, IntegrationEventService>();

            services.AddSingleton <IRabbitMqPersistentConnection>(sp =>
            {
                var logger = sp.GetRequiredService <ILogger <DefaultRabbitMqPersistentConnection> >();
                Console.WriteLine(eventBusOptions.Host + " " + eventBusOptions.Port);

                var factory = new ConnectionFactory()
                {
                    HostName = eventBusOptions.Host,
                    Port     = eventBusOptions.Port,
                    DispatchConsumersAsync = true
                };

                if (!string.IsNullOrEmpty(eventBusOptions.UserName))
                {
                    factory.UserName = eventBusOptions.UserName;
                }

                if (!string.IsNullOrEmpty(eventBusOptions.Password))
                {
                    factory.Password = eventBusOptions.Password;
                }

                var retryCount = 5;
                if (eventBusOptions.RetryCount > 0)
                {
                    retryCount = eventBusOptions.RetryCount;
                }

                return(new DefaultRabbitMqPersistentConnection(factory, logger, retryCount));
            });

            var subscriptionClientName = eventBusOptions.ClientName;

            services.AddSingleton <IEventBus, EventBusRabbitMQ>(sp =>
            {
                var rabbitMQPersistentConnection = sp.GetRequiredService <IRabbitMqPersistentConnection>();
                var iLifetimeScope = sp.GetRequiredService <ILifetimeScope>();
                var logger         = sp.GetRequiredService <ILogger <EventBusRabbitMQ> >();
                var eventBusSubcriptionsManager = sp.GetRequiredService <IEventBusSubscriptionsManager>();

                var retryCount = 5;
                if (eventBusOptions.RetryCount > 0)
                {
                    retryCount = eventBusOptions.RetryCount;
                }

                return(new EventBusRabbitMQ(rabbitMQPersistentConnection, logger, iLifetimeScope,
                                            eventBusSubcriptionsManager, subscriptionClientName, retryCount));
            });

            services.AddSingleton <IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();

            return(services);
        }
        public static IServiceCollection AddEventBusConnection(this IServiceCollection services, EventBusOptions options)
        {
            services.AddSingleton <IRabbitMqPersistentConnection>(sp =>
            {
                var retryCount = 5;

                var factory = new ConnectionFactory
                {
                    HostName = options.Connection,
                    DispatchConsumersAsync = options.DispatchConsumersAsync
                };

                if (!string.IsNullOrEmpty(options.VirtualHost))
                {
                    factory.VirtualHost = options.VirtualHost;
                }

                if (!string.IsNullOrEmpty(options.Username))
                {
                    factory.UserName = options.Username;
                }

                if (!string.IsNullOrEmpty(options.Password))
                {
                    factory.Password = options.Password;
                }

                if (!string.IsNullOrEmpty(options.RetryCount))
                {
                    retryCount = int.Parse(options.RetryCount);
                }

                return(new DefaultRabbitMqPersistentConnection(factory, retryCount));
            });

            return(services);
        }