protected override async Task ExecuteAsync(CancellationToken stoppingToken) { var queue = await _sub.SubscribeAsync("orders"); while (!stoppingToken.IsCancellationRequested) { try { var queueMessage = await queue.ReadAsync(stoppingToken); var orderMessage = OrderMessage.FromBytes(queueMessage.Message); await _orderMessages.WriteAsync(orderMessage, stoppingToken); } catch (OperationCanceledException) { _log.LogInformation("Service stopping."); break; } } }
internal ValueTask WriteAsync(OrderMessage message, CancellationToken token) => _channel.Writer.WriteAsync(message, token);