protected override Task ExecuteAsync(CancellationToken cancellationToken) { var channel = _messagingFactory.Configure(); var consumer = new AsyncEventingBasicConsumer(channel); consumer.Received += _messagingService.Dequeue(async(raw, message) => { cancellationToken.ThrowIfCancellationRequested(); if (message == null) { return; } using (_logger.BeginScope(Guid.NewGuid().ToString())) { try { await _databaseFactory.OpenConnectionAsync(); await _databaseFactory.BeginTransactionAsync(); await _orchestratorService.OrchestrateAsync(message); _databaseFactory.CommitTransaction(); } catch (Exception ex) { _databaseFactory.RollbackTransaction(); throw ex; } finally { _databaseFactory.CloseConnection(); } } }); _tag = channel.BasicConsume(_messaging.Consuming.Queue, false, consumer); return(Task.CompletedTask); }
protected override Task ExecuteAsync(CancellationToken cancellationToken) { var channel = _messagingFactory.Configure(); var consumer = new AsyncEventingBasicConsumer(channel); consumer.Received += _messagingService.Dequeue(cancellationToken, async(string raw, NewUserEvent message) => { cancellationToken.ThrowIfCancellationRequested(); if (message == null) { return; } await _orchestratorService.OrchestrateAsync(message); }); _tag = channel.BasicConsume(_messaging.Consuming.Queue, false, consumer); return(Task.CompletedTask); }