private async Task RunConsumerAsync(CancellationToken token = default) { while (!token.IsCancellationRequested) { UpdateMarketCommand updateMarketCommand = null; try { var message = _consumer.Consume(token); updateMarketCommand = message.Message.Value; _logger.LogInformation($"Consumer: {nameof(MarketUpdateCommandConsumer)}," + $"MessageKey: {message.Message.Key}, " + $"Topic: {message.Topic}, " + $"Partition: {message.Partition.Value}, " + $"Offset: {message.TopicPartitionOffset.Offset.Value}"); await _retryPolicy.ExecuteAsync(async x => await _mediator.Send(message.Message.Value, token), token); } catch (Exception e) { _logger.LogError(e, e.Message); _logger.LogError($"Exhausted all retries for message with Correlation: {updateMarketCommand?.CorrelationId}"); var updateMarketFailedEvent = _mapper.Map <UpdateMarketFailedEvent>(updateMarketCommand); await _producer.ProduceAsync(updateMarketFailedEvent.MarketId, updateMarketFailedEvent); } } }
public async Task <ActionResult <Market> > Update([FromBody] UpdateMarketCommand command) { return(await Mediator.Send(command)); }