public static void Run([IotFeedbackTrigger] FeedbackBatch req, TraceWriter log) { if (req == null) { return; } foreach (var record in req.Records) { log.Info($"Device : {record.DeviceId}, MessageId: {record.OriginalMessageId}, Status: {record.StatusCode}"); } }
public async Task ListenForCloud2DeviceCommandFeedback() { FeedbackReceiver <FeedbackBatch> feedbackReceiver = _serviceClient.GetFeedbackReceiver(); FeedbackBatch feedbackBatch = await feedbackReceiver.ReceiveAsync(TimeSpan.FromSeconds(5)); if (feedbackBatch == null) { return; } OnCloud2DeviceCommandFeedback?.Invoke(this, new Cloud2DeviceCommandFeedbackEventArgs($"{String.Join("\n", feedbackBatch.Records.Select(item => item.StatusCode).ToArray())}")); await feedbackReceiver.CompleteAsync(feedbackBatch); }
public static async Task receiveMessageFeedback(int listenFor = 100) { FeedbackReceiver <FeedbackBatch> feedbackReceiver = serviceClient.GetFeedbackReceiver(); FeedbackBatch feedback = await feedbackReceiver.ReceiveAsync(TimeSpan.FromSeconds(listenFor)).ConfigureAwait(false); if (feedback != null) { Console.WriteLine( "IotHub has received a message {0}", string.Join(", ", feedback.Records) ); } else { Console.WriteLine("IotHub has not received any messages"); } }
internal async void GetStatus() { ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(_connectionString); var feedbackReceiver = serviceClient.GetFeedbackReceiver(); while (true) { Console.WriteLine("Requesting Delivery Status: {0}", DateTime.Now.ToUniversalTime()); FeedbackBatch feedbackBatch = await feedbackReceiver.ReceiveAsync(); if (feedbackBatch == null) { continue; } Console.WriteLine("Received feedback: {0}", string.Join(" - ", feedbackBatch.Records.Select(deliveryState => deliveryState.StatusCode))); await feedbackReceiver.CompleteAsync(feedbackBatch); } }
private async Task ReceiveMessageFeedbacksAsync(CancellationToken token) { // It is important to note that receiver only gets feedback messages when the device is actively running and acting on messages. _logger.LogInformation("Starting to listen to feedback messages"); var feedbackReceiver = _serviceClient.GetFeedbackReceiver(); while (!token.IsCancellationRequested) { try { FeedbackBatch feedbackMessages = await feedbackReceiver.ReceiveAsync(); if (feedbackMessages != null) { _logger.LogInformation("New Feedback received:"); _logger.LogInformation($"\tEnqueue Time: {feedbackMessages.EnqueuedTime}"); _logger.LogInformation($"\tNumber of messages in the batch: {feedbackMessages.Records.Count()}"); foreach (FeedbackRecord feedbackRecord in feedbackMessages.Records) { _logger.LogInformation($"\tDevice {feedbackRecord.DeviceId} acted on message: {feedbackRecord.OriginalMessageId} with status: {feedbackRecord.StatusCode}"); } await feedbackReceiver.CompleteAsync(feedbackMessages); } await Task.Delay(s_sleepDuration); } catch (Exception e) when(ExceptionHelper.IsNetwork(e)) { _logger.LogError($"Transient Exception occurred; will retry: {e}"); } catch (Exception e) { _logger.LogError($"Unexpected error, will need to reinitialize the client: {e}"); await InitializeServiceClientAsync(); feedbackReceiver = _serviceClient.GetFeedbackReceiver(); } } }
private static async Task ReceiveFeedback(ServiceClient serviceClient) { FeedbackReceiver <FeedbackBatch> feedbackReceiver = serviceClient.GetFeedbackReceiver(); while (true) { FeedbackBatch feedbackBatch = await feedbackReceiver.ReceiveAsync(); if (feedbackBatch == null) { continue; } foreach (FeedbackRecord record in feedbackBatch.Records) { string messageId = record.OriginalMessageId; FeedbackStatusCode statusCode = record.StatusCode; Console.WriteLine($"Feedback for message '{messageId}', status code: {statusCode}"); } await feedbackReceiver.CompleteAsync(feedbackBatch); } }
public async Task CompleteFeedbackAsync(FeedbackBatch feedbackBatch) { var feedbackReceiver = ServiceClient.GetFeedbackReceiver(); await feedbackReceiver.CompleteAsync(feedbackBatch); }