public EventBusRabbitMQRetryConsumerStrategy(
     EventBusConfiguration configuration,
     ILogger <EventBusRabbitMQRetryConsumerStrategy> logger)
 {
     _configuration = configuration;
     _logger        = logger;
 }
Exemplo n.º 2
0
        public EventBusRabbitMQ(
            EventBusConfiguration configuration,
            EventBusRabbitMQConfiguration rabbitmqConfiguration,
            EventBusRabbitMQConnection eventBusConnection,
            EventBusRabbitMQRetryConsumerStrategy retryConsumerStrategy,
            EventBusManager manager,
            ILogger <EventBusRabbitMQ> logger)
        {
            _configuration         = configuration ?? throw new ArgumentNullException(nameof(configuration));
            _rabbitmqConfiguration = rabbitmqConfiguration ?? throw new ArgumentNullException(nameof(rabbitmqConfiguration));
            _exchangeName          = rabbitmqConfiguration.ExchangeName;
            _queueName             = rabbitmqConfiguration.QueueName;
            _eventBusConnection    = eventBusConnection ?? throw new ArgumentNullException(nameof(eventBusConnection));
            _manager = manager ?? throw new ArgumentNullException(nameof(manager));
            _retryConsumerStrategy = retryConsumerStrategy ?? throw new ArgumentNullException(nameof(retryConsumerStrategy));
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));

            using (var channel = _eventBusConnection.CreateModel())
            {
                channel.ExchangeDeclare(
                    exchange: _exchangeName,
                    type: ExchangeType.Direct,
                    arguments: new Dictionary <string, object>()
                {
                    { "x-dead-letter-exchange", $"{_exchangeName}{_configuration.FailSuffix}" }
                });
            }
        }
Exemplo n.º 3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, EventBusConfiguration bus)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthorization();


            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute("default", "{controller=HomeGetWeb}/{action=Index}/{id?}");
                endpoints.MapHealthChecks("/health-check");
            });

            bus.Configure();
        }
Exemplo n.º 4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
            services.AddTransient <MessagePostedEventHandler>();
            services.AddTransient <MessagePutEventHandler>();
            services.AddScoped <ScopedDependency>();
            EventBusConfiguration eventBusConfiguration = new EventBusConfiguration();

            Configuration.GetSection("EventBus").Bind(eventBusConfiguration);
            if (eventBusConfiguration.UseRabbitMQ)
            {
                var rabbitConfig = eventBusConfiguration.RabbitMQConfiguration;
                services.AddRabbitMQ(new RabbitMQOptions()
                {
                    HostName     = rabbitConfig.Host,
                    UserName     = rabbitConfig.UserName,
                    Password     = rabbitConfig.Password,
                    VirtualHost  = rabbitConfig.VirtualHost,
                    QueueName    = rabbitConfig.QueueName,
                    ExchangeName = rabbitConfig.ExchangeName
                });
            }
            else
            {
                var azureConfig = eventBusConfiguration.AzureServiceBusConfiguration;
                services.AddAzureServiceBus(new AzureServiceBusOptions()
                {
                    SubscriptionName = azureConfig.ClientName,
                    ConnectionString = azureConfig.ConnectionString
                });
            }
        }
Exemplo n.º 5
0
 public EventBusManager(
     EventBusConfiguration configuration,
     ILogger <EventBusManager> logger)
 {
     _configuration = configuration;
     _logger        = logger;
     _subscriptions = new List <EventBusSubscription>();
 }
Exemplo n.º 6
0
 public RabbitEventBus(IOptions <EventBusConfiguration> options, IMessageSerializer messageSerializer,
                       IServiceScopeFactory serviceScopeFactory
                       )
 {
     this.messageSerializer = messageSerializer;
     Config               = options.Value;
     handlers             = new Dictionary <string, List <Type> >();
     _serviceScopeFactory = serviceScopeFactory;
 }
Exemplo n.º 7
0
 private void ConfigureEventBus(IServiceCollection services, EventBusConfiguration settings)
 {
     services.AddSingleton <IServiceBusPersisterConnection>(sp =>
     {
         var logger = sp.GetRequiredService <ILogger <DefaultServiceBusPersisterConnection> >();
         var serviceBusConnection = new ServiceBusConnectionStringBuilder(settings.EventBusConnection);
         return(new DefaultServiceBusPersisterConnection(serviceBusConnection, logger));
     });
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="AzureServiceBusManager"/> class.
        /// </summary>
        /// <param name="eventBusConfigurationList">The event bus configuration list.</param>
        /// <param name="domainManager">The domain manager.</param>
        public AzureServiceBusManager(EventBusConfiguration eventBusConfigurationList, IOptions <DomainManager> domainManager)
        {
            _eventBusConfiguration = eventBusConfigurationList;
            _domainManager         = domainManager.Value;

            if (_topicManager != null && _topicManager.Count == 0)
            {
                SetupAzureTopicProvider(domainManager.Value);
            }

            if (_queueManager != null && _queueManager.Count == 0)
            {
                SetupAzureQueueProvider(domainManager.Value);
            }
        }
Exemplo n.º 9
0
        private void RegisterEventBus(IServiceCollection services, EventBusConfiguration settings)
        {
            var subscriptionClientName = settings.SubscriptionClientName;

            services.AddSingleton <IEventBus, EventBusServiceBus>(sp =>
            {
                var serviceBusPersisterConnection = sp.GetRequiredService <IServiceBusPersisterConnection>();
                var iLifetimeScope = sp.GetRequiredService <ILifetimeScope>();
                var logger         = sp.GetRequiredService <ILogger <EventBusServiceBus> >();
                var eventBusSubcriptionsManager = sp.GetRequiredService <IEventBusSubscriptionsManager>();

                return(new EventBusServiceBus(serviceBusPersisterConnection, logger,
                                              eventBusSubcriptionsManager, subscriptionClientName, iLifetimeScope));
            });


            services.AddSingleton <IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
            services.AddTransient <TransactionCreatedIntegrationEventHandler>();
            services.AddTransient <TransactionCreateFailedIntegrationEventHandler>();
        }
Exemplo n.º 10
0
        public static void Configure(IApplicationBuilder app, IWebHostEnvironment env, EventBusConfiguration bus)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            app.UseHttpsRedirection();

            app.UseRouting();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
            });

            bus.Configure();
        }