public async Task Consume(ConsumeContext <ISendSmsRequestReceived> context) { var smsList = ToSmsList(context); await StoreAsync(smsList); foreach (var message in smsList) { try { var smsBody = await _smsClient.SendAsync(message); if (context.Message.UserId != default) { await _webApiClient.DeductSmsCreditsAsync(context.Message.UserId, smsBody); } } catch (Exception ex) { _logger.LogError(ex, "Error while sending sms"); await PublishSmsRequestFailedEventAsync(context, message, ex); } } }