public EventBusrabbitMQConsumer(IRabbitMQConnection connection, IMediator mediator, IMapper mapper, IOrderRepository orderRepository)
 {
     this.connection      = connection;
     this.mediator        = mediator;
     this.mapper          = mapper;
     this.orderRepository = orderRepository;
 }
Пример #2
0
        private static void RabbitConsumeLoggingEvent(IRabbitMQConnection rabbitmqconn, ILogRepository logRepository)
        {
            var consumer = new EventingBasicConsumer(rabbitmqconn.ExchangeChannel);

            consumer.Received += (model, ea) =>
            {
                var body = ea.Body;

                var message = Encoding.UTF8.GetString(body);

                // Deserialize the log object

                Log log = JsonConvert.DeserializeObject <Log>(message);

                var saveTask = logRepository.Add(log);

                saveTask.ContinueWith((r) => {
                    if (r.IsCompletedSuccessfully)
                    {
                        rabbitmqconn.ExchangeChannel.BasicAck(ea.DeliveryTag, false);
                    }
                });
            };

            rabbitmqconn.ExchangeChannel.BasicConsume(RabbitQueues.LoggerApiQ, false, RabbitTags.LOGAPI, false, false, null, consumer);
        }
Пример #3
0
 public RabbitBusContainer(IRabbitMQConnection rabbitConnection, IHandlerItem _handlerItem)
 {
     RabbitConnection = rabbitConnection;
     handlerItem      = _handlerItem;
     BusEndpoint      = _handlerItem.EndPoint;
     Log = LogManager.GetLogger("rabbit4netConsoleApp.Program");
 }
Пример #4
0
 public EventBusRabbitMQConsumer(IRabbitMQConnection rabbitMqConnection, IMediator mediator, IMapper mapper, IOrderRepository orderRepository)
 {
     _rabbitMqConnection = rabbitMqConnection;
     _mediator           = mediator;
     _mapper             = mapper;
     _orderRepository    = orderRepository;
 }
Пример #5
0
 public EventBusRabbitMQConsumer(IRabbitMQConnection connection, IMediator mediator, IMapper mapper, IOrderRepository repository)
 {
     _connection = connection;
     _mediator   = mediator;
     _mapper     = mapper;
     _repository = repository;
 }
 public EventBusRabbitMQConsumer(IRabbitMQConnection connection, IMapper mapper,
                                 IServiceScopeFactory scopeFactory)
 {
     _connection   = connection;
     _mapper       = mapper;
     _scopeFactory = scopeFactory;
 }
 public EventBusRabbitMQConsumer(IRabbitMQConnection connection, IMediator mediator, IMapper mapper, IOrderRepository orderRepository)
 {
     _connection      = connection ?? throw new ArgumentNullException(nameof(connection));
     _mediator        = mediator ?? throw new ArgumentNullException(nameof(mediator));
     _mapper          = mapper ?? throw new ArgumentNullException(nameof(mapper));
     _orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository));
 }
 public EventBusRabbitMQConsumer(IRabbitMQConnection connection, IMediator mediator, IMapper mapper, IOrderRepository repository)
 {
     this.connection = connection ?? throw new ArgumentNullException(nameof(connection));
     this.mediator   = mediator ?? throw new ArgumentNullException(nameof(mediator));
     this.mapper     = mapper ?? throw new ArgumentNullException(nameof(mapper));
     this.repository = repository ?? throw new ArgumentNullException(nameof(repository));
 }
Пример #9
0
        public static void SubscribeRabbitMQEvents(IRabbitMQConnection rabbitmqconn, IServiceProvider services)
        {
            #region Rabbit Event - consume UserApi Settings Data

            var consumerReceivedSettingsData = new EventingBasicConsumer(rabbitmqconn.UserChannel);

            consumerReceivedSettingsData.Received += (model, ea) =>
            {
                var body = ea.Body;

                //the setting queue message contains the setting type
                var message = Encoding.UTF8.GetString(body);

                int settingType = 0;
                int.TryParse(message, out settingType);

                if (settingType == (int)SettingsType.USER)
                {
                    // TODO (joaoOxOc): save user settings that comes from the Rabbit event
                    //bool settingsLoaded = LoadSettings(services);

                    //if (settingsLoaded)
                    rabbitmqconn.UserChannel.BasicAck(ea.DeliveryTag, false);
                }
            };

            rabbitmqconn.UserChannel.BasicConsume(RabbitQueues.UserSettingQ, false, RabbitTags.USERAPI, false, false, null, consumerReceivedSettingsData);

            #endregion
        }
Пример #10
0
        public static void SubscribeRabbitMQEvents(IRabbitMQConnection rabbitmqconn, ILogRepository logRepository)
        {
            #region Rabbit Consume Logging Event

            RabbitConsumeLoggingEvent(rabbitmqconn, logRepository);

            #endregion

            #region Hangfire Delete Account

            //var consumerDeleteExpiredAccount = new EventingBasicConsumer(rabbitmqconn.HangfireDeleteAccountChannel);

            //consumerDeleteExpiredAccount.Received += (model, ea) =>
            //{
            //    var body = ea.Body;

            //    var message = Encoding.UTF8.GetString(body);
            //    HangfireDeleteExpiredAccountsRequest request = JsonConvert.DeserializeObject<HangfireDeleteExpiredAccountsRequest>(message);

            //    HangfireJobs.HangfireDeleteExpiredAccounts(logRepository, rabbitmqconn, request);

            //    rabbitmqconn.HangfireDeleteAccountChannel.BasicAck(ea.DeliveryTag, false);
            //};

            //rabbitmqconn.HangfireDeleteAccountChannel.BasicConsume(RabbitQueues.HangfireDeleteExpiredAccountsQ_Logs, false, "hangfire", false, false, null, consumerDeleteExpiredAccount);

            #endregion
        }
        private readonly ISprintDetailRepository _repository; // we added this in order to resolve in mediatR

        public EventBusRabbitMQConsumer(IRabbitMQConnection connection, IMediator mediator, IMapper mapper, ISprintDetailRepository _repository)
        {
            _connection = connection ?? throw new ArgumentNullException(nameof(connection));
            _mediator   = mediator ?? throw new ArgumentNullException(nameof(mediator));
            _mapper     = mapper ?? throw new ArgumentNullException(nameof(mapper));
            _repository = _repository ?? throw new ArgumentNullException(nameof(_repository));
        }
 public RabbitMQEventBus(IRabbitMQConnection connection, ILogger <RabbitMQEventBus> logger, ISubscriptionManager subscriptionManager)
 {
     this.connection          = connection;
     this.logger              = logger;
     this.subscriptionManager = subscriptionManager;
     this.queueName           = connection.QueueName;
     this.exchange            = connection.Exchange;
 }
        public EventBusRabbitMQConsumer(IServiceProvider serviceProvider, IRabbitMQConnection connection,
                                        IMapper mapper)
        {
            _serviceProvider = serviceProvider;

            _connection = connection ?? throw new ArgumentNullException(nameof(connection));
            _mapper     = mapper ?? throw new ArgumentNullException(nameof(mapper));
        }
Пример #14
0
 public WorkQueue(IRabbitMQConnection persistentConnection,
                  ILogger <WorkQueue> logger,
                  TinyEventBusConfiguration configuration)
 {
     _connection    = persistentConnection ?? throw new ArgumentNullException(nameof(persistentConnection));
     _logger        = logger;
     _configuration = configuration;
 }
Пример #15
0
 public BusRabbitMQ(IRabbitMQConnection persistentConnection, ILogger <BusRabbitMQ> logger,
                    string queueName = null, int retryCount = 5)
 {
     _persistentConnection = persistentConnection ?? throw new ArgumentNullException(nameof(persistentConnection));
     _logger          = logger ?? throw new ArgumentNullException(nameof(logger));
     _queueName       = queueName;
     _consumerChannel = CreateConsumerChannel();
     _retryCount      = retryCount;
 }
Пример #16
0
 public RabbitMQBus(IMediator mediator, IServiceScopeFactory serviceScopeFactory, IRabbitMQConnection rabbitMQConnection, int retryCount = 5)
 {
     _mediator             = mediator;
     _serviceScopeFactory  = serviceScopeFactory;
     _handlers             = new Dictionary <string, List <Type> >();
     _eventTypes           = new List <Type>();
     _persistentConnection = rabbitMQConnection ?? throw new ArgumentNullException(nameof(rabbitMQConnection));
     _retryCount           = retryCount;
 }
Пример #17
0
 public RabbitMQConsumer(
     IRabbitMQConnection connection,
     IMediator mediator,
     IMapper mapper)
 {
     this.connection = connection ?? throw new ArgumentNullException(nameof(connection));
     this.mediator   = mediator ?? throw new ArgumentNullException(nameof(mediator));
     this.mapper     = mapper ?? throw new ArgumentNullException(nameof(mapper));
 }
 public RabbitMQEventBus(IRabbitMQConnection connection, IEventBusSubscriptionsManager subsManager, ILifetimeScope autofac)
 {
     _connection                  = connection ?? throw new ArgumentNullException(nameof(connection));
     _subsManager                 = subsManager ?? new InMemoryEventBusSubscriptionsManager();
     _queueName                   = Guid.NewGuid().ToString();
     _autofac                     = autofac;
     _consumerChannel             = CreateConsumerChannel();
     _subsManager.OnEventRemoved += SubsManager_OnEventRemoved;
 }
Пример #19
0
 public EventBusRabbitMQ(IRabbitMQConnection rabbitMQConnection, ILifetimeScope lifetimeScope, ILogger <EventBusRabbitMQ> logger, IEventBusSubscribeManager eventBusSubscribeManager, string queueName = null)
 {
     this.rabbitMQConnection                  = rabbitMQConnection;
     this.lifetimeScope                       = lifetimeScope;
     this.logger                              = logger;
     this.eventBusSubscribeManager            = eventBusSubscribeManager;
     this.queueName                           = queueName;
     consumerChannel                          = CreateConsumerChannel();
     eventBusSubscribeManager.OnEventRemoved += EventBusSubscribeManager_OnEventRemoved;
 }
Пример #20
0
        public EventBusRabbitMQ(IRabbitMQConnection connection, IEventBusSubscriptionsManager subscriptionsManager, ILifetimeScope autofac, ILogger <EventBusRabbitMQ> logger, string queueName)
        {
            _subscriptionsManager = subscriptionsManager;
            _connection           = connection;
            _autofac         = autofac;
            _logger          = logger;
            _queueName       = queueName;
            _consumerChannel = CreateConsumerChannel();

            _subscriptionsManager.OnEventRemoved += SubscriptionsManager_OnEventRemoved;
        }
Пример #21
0
 public RabbitMQConnectionService(IRabbitMQConnection persistentConnection, ILogger <RabbitMQConnectionService> logger,
                                  ILifetimeScope autofac, ISubscriptionManager subsManager, string queueName = null, int retryCount = 5)
 {
     _connection                  = persistentConnection ?? throw new ArgumentNullException(nameof(persistentConnection));
     _logger                      = logger ?? throw new ArgumentNullException(nameof(logger));
     _subsManager                 = subsManager ?? new SubscriptionManager();
     _queueName                   = queueName;
     _consumerChannel             = CreateConsumerChannel();
     _autofac                     = autofac;
     _subsManager.OnEventRemoved += SubsManager_OnEventRemoved;
 }
Пример #22
0
 public RabbitMQEventBus(IRabbitMQConnection connection, IEventBusSubscriptionsManager subsManager, ILifetimeScope autofac,
                         ILogger <RabbitMQEventBus> logger, string queueName = null, int retryCount = 5)
 {
     _connection                  = connection ?? throw new ArgumentNullException(nameof(connection));
     _subsManager                 = subsManager ?? new InMemoryEventBusSubscriptionsManager();
     _queueName                   = queueName;
     _logger                      = logger;
     _autofac                     = autofac;
     _consumerChannel             = CreateConsumerChannel();
     _subsManager.OnEventRemoved += SubsManager_OnEventRemoved;
 }
Пример #23
0
 public EventBusRabbitMQ(IRabbitMQConnection persistedConnection, ILogger <EventBusRabbitMQ> logger,
                         ILifetimeScope autofac, IEventBusSubscriptionManager subsManager, string queueName = null, int retryCount = 5)
 {
     _connection                  = persistedConnection;
     _logger                      = logger;
     _subsManager                 = subsManager;
     _autofac                     = autofac;
     _retryCount                  = retryCount;
     _queueName                   = queueName;
     _consumerChannel             = CreateConsumerChannel();
     _subsManager.OnEventRemoved += SubsManager_OnEventRemoved;
 }
Пример #24
0
 public EventBusRabbitMQ(IRabbitMQConnection persistentConnection,
                         ILifetimeScope autofac, ISubscriptionsManager subsManager, ILogger logger, int retryCount, string queueName = null)
 {
     _persistentConnection = persistentConnection ?? throw new ArgumentNullException(nameof(persistentConnection));
     _logger                      = logger;
     _subsManager                 = subsManager ?? new InMemorySubscriptionsManager();
     _queueName                   = queueName;
     _consumerChannel             = CreateConsumerChannel();
     _autofac                     = autofac;
     _retryCount                  = retryCount;
     _subsManager.OnEventRemoved += SubsManager_OnEventRemoved;
 }
 public RabbitMQEventBus(IRabbitMQConnection connection,
                         IEventBusSubscriptionsHandler eventBusSubscriptions,
                         IServiceProvider serviceProvider,
                         ILogger <RabbitMQEventBus> logger, string clientName, int retryCount)
 {
     _connection      = connection;
     _logger          = logger;
     _eventBusSubs    = eventBusSubscriptions;
     _serviceProvider = serviceProvider;
     _retryCount      = retryCount;
     _queueName       = clientName;
     _consumerChannel = CreateConsumerChannel();
 }
        public static ContainerBuilder RegisterEventBus(this ContainerBuilder builder)
        {
            string EnableRabbitMQ = System.Configuration.ConfigurationManager.AppSettings["RabittMQ:EnableRabbitMQ"];

            if (EnableRabbitMQ != "1")
            {
                return(builder);
            }
            // Register RabbitMQ Connection
            builder.Register <RabbitMQConnection>(options =>
            {
                ConnectionFactory factory = new ConnectionFactory()
                {
                    HostName = System.Configuration.ConfigurationManager.AppSettings.Get("RabittMQ:EventBusHostName")
                };

                if (!string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings.Get("RabittMQ:EventBusUserName")))
                {
                    factory.UserName = System.Configuration.ConfigurationManager.AppSettings.Get("RabittMQ:EventBusUserName");
                }

                if (!string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings.Get("RabittMQ:EventBusPassword")))
                {
                    factory.Password = System.Configuration.ConfigurationManager.AppSettings.Get("RabittMQ:EventBusPassword");
                }

                int retryCount = 5;
                if (!string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings.Get("RabittMQ:EventBusRetryCount")))
                {
                    retryCount = int.Parse(System.Configuration.ConfigurationManager.AppSettings.Get("RabittMQ:EventBusRetryCount"));
                }

                return(new RabbitMQConnection(factory, retryCount));
            }).As <IRabbitMQConnection>().SingleInstance();

            //Register Event Bus
            builder.Register <EventBus>(sp =>
            {
                string subscriptionClientName          = string.Empty;
                IRabbitMQConnection rabbitMQConnection = sp.Resolve <IRabbitMQConnection>();
                ILifetimeScope iLifetimeScope          = sp.Resolve <ILifetimeScope>();
                int retryCount = 5;
                if (!string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings.Get("RabittMQ:EventBusRetryCount")))
                {
                    retryCount = int.Parse(System.Configuration.ConfigurationManager.AppSettings.Get("RabittMQ:EventBusRetryCount"));
                }

                return(new EventBus(rabbitMQConnection, iLifetimeScope, subscriptionClientName, retryCount));
            }).As <IEventBus>().SingleInstance();
            return(builder);
        }
Пример #27
0
        public RabbitMQEventBus(IRabbitMQConnection persistentConnection,
                                IServiceProvider serviceProvider, ILoggerFactory loggerFactory,
                                ISubscriptionsManager subsManager, EventReceivedFunc eventReceiver,
                                IEventSerializer <byte[]> eventSerializer, IEventNameTypeResolver eventNameTypeResolver)
        {
            _persistentConnection = persistentConnection ?? throw new ArgumentNullException(nameof(persistentConnection));
            _logger = loggerFactory.CreateLogger <RabbitMQEventBus>();

            _serviceProvider       = serviceProvider;
            SubscriptionsManager   = subsManager;
            _eventReceiver         = eventReceiver;
            _eventSerializer       = eventSerializer;
            _eventNameTypeResolver = eventNameTypeResolver;
        }
Пример #28
0
        public PubSub(IRabbitMQConnection persistentConnection,
                      ILogger <PubSub> logger,
                      TinyEventBusConfiguration configuration)
        {
            _connection    = persistentConnection ?? throw new ArgumentNullException(nameof(persistentConnection));
            _logger        = logger;
            _configuration = configuration;

            _exchangeType = configuration.ExchangeType;
            if (string.IsNullOrEmpty(_exchangeType))
            {
                _exchangeType = ExchangeType.Direct;
            }
        }
Пример #29
0
 public RpcClient(IRabbitMQConnection connection)
 {
     _connection        = connection;
     channel            = connection.CreateModel();
     replyQueueName     = channel.QueueDeclare().QueueName;
     consumer           = new EventingBasicConsumer(channel);
     consumer.Received += (model, ea) =>
     {
         if (!callbackMapper.TryRemove(ea.BasicProperties.CorrelationId, out TaskCompletionSource <string> tcs))
         {
             return;
         }
         var body     = ea.Body.ToArray();
         var response = Encoding.UTF8.GetString(body);
         tcs.TrySetResult(response);
     };
 }
Пример #30
0
        public RabbitMQEventBus(IServiceProvider serviceProvider,
                                IRabbitMQConnection persistentConnection,
                                IEventBusSubscriptionsManager subsManager
                                , string queueName = null, int retryCount = 5
                                )
        {
            _serviceProvider      = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
            _persistentConnection = persistentConnection ?? throw new ArgumentNullException(nameof(persistentConnection));
            _subsManager          = subsManager ?? new InMemoryEventBusSubscriptionsManager();
            _logger = serviceProvider.GetRequiredService <LoggerFactory>().CreateLogger <RabbitMQEventBus>();

            _queueName  = queueName;
            _retryCount = retryCount;

            _consumerChannel             = CreateConsumerChannel();
            _subsManager.OnEventRemoved += SubsManager_OnEventRemoved;
        }