示例#1
0
        private void ConsumeMessages(string eventSubscriber, ushort prefetchCount = 10)
        {
            var channel = _config.Channel();

            DeclareQueue(channel, eventSubscriber);

            channel.BasicQos(0, prefetchCount, false);
            var consumer = new EventingBasicConsumer(channel);

            consumer.Received += async(_, ea) =>
            {
                try
                {
                    var body    = ea.Body.ToArray();
                    var message = Encoding.UTF8.GetString(body);

                    var @event = _deserializer.Deserialize(message);

                    await _domainEventMediator.ExecuteOn(@event, eventSubscriber, CancellationToken.None);
                }
                catch (Exception ex)
                {
                    _logger.Error(ex, ex.Message);
                    HandleConsumptionError(ea, eventSubscriber);
                }

                channel.BasicAck(ea.DeliveryTag, false);
            };

            channel.BasicConsume(eventSubscriber, false, consumer);
        }
        public void Consume(DomainEvent @event)
        {
            var subscribers = DomainEventSubscriberInformationService.GetAllEventsSubscribers(@event);

            foreach (var subscriber in subscribers)
            {
                _domainEventsToExecute.Subscribers.Add(cancellationToken =>
                                                       _domainEventMediator.ExecuteOn(@event, subscriber, cancellationToken));
            }
            //return Task.WhenAll(subscribers.Select(subscriber =>
            //    _domainEventMediator.ExecuteOn(@event, subscriber, cancellationToken)));
        }