public DmsEventProjection(IConnection connection, IDocumentService documentService, IDispatchCommits dispatcher, ILog logger, ITranslationService translationService)
 {
     _documentService    = documentService;
     _dispatcher         = dispatcher;
     _translationService = translationService;
     _logger             = logger;
     _consumer           = new RabbitMqSubscription(connection, "Cev-Exchange", logger);
     _consumer
     .WithAppName("dms-projection")
     .WithEvent <CreateDocumentPartEvent>(Handle);
 }
        private async Task ExecuteAsync(RabbitMqSubscription subscription, CancellationToken cancellationToken)
        {
            using (var connection = await _connectionFactory.CreateConnectionAsync(cancellationToken))
            {
                var underlyingConnection = connection.UnderlyingConnection;
                var channel  = underlyingConnection.CreateModel();
                var consumer = new AsyncEventingBasicConsumer(channel);
                channel.BasicConsume(consumer: consumer, queue: subscription.Name, autoAck: false);

                while (!cancellationToken.IsCancellationRequested)
                {
                    try
                    {
                        var message = await ReceiveAsync(consumer);

                        try
                        {
                            await OnReceiveAsync(message, cancellationToken).ConfigureAwait(false);

                            channel.BasicAck(message.DeliveryTag, multiple: false);
                        }
                        catch (Exception ex)
                        {
                            _logger.LogError(ex, $"Error: RabbitMQ Message Receiver error, could not consume message '{message.DeliveryTag}'");

                            channel.BasicNack(message.DeliveryTag, multiple: false, requeue: true);

                            await OnErrorAsync(message, ex).ConfigureAwait(false);
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError(ex, $"Unexpected receiver error: {ex.Message}");
                        throw;
                    }
                }
                foreach (var tag in consumer.ConsumerTags)
                {
                    channel.BasicCancel(tag);
                }
            }
        }