async Task ProcessMessagesAsync(Message message, CancellationToken token) { if (_queueClient.IsClosedOrClosing) { Logger.Log("Queue is closing, abandoning message."); await _queueClient.AbandonAsync(message.SystemProperties.LockToken); return; } string videoUrl = ""; try { // Process the message. Logger.Log($"Received message: SequenceNumber:{message.SystemProperties.SequenceNumber} Body:{Encoding.UTF8.GetString(message.Body)}"); string json = Encoding.UTF8.GetString(message.Body); videoUrl = QueueMessageParser.GetUrl(json); Logger.Log($"Received this videoUrl: {videoUrl}"); if (videoUrl.EndsWith("test.MP4")) { throw new ApplicationException("Something broke, fail safe for testing exceptions!"); } SkiVideoProcessor processor = new SkiVideoProcessor(videoUrl); await processor.ProcessAsync(); await _queueClient.CompleteAsync(message.SystemProperties.LockToken); } catch (Exception e) { if (message.SystemProperties.DeliveryCount <= 2) { Logger.Log($"Abandoned message.", e); // abandon and allow another to try in case of transient errors await _queueClient.AbandonAsync(message.SystemProperties.LockToken); } else { Logger.Log($"Dead lettering message.", e); await _queueClient.DeadLetterAsync(message.SystemProperties.LockToken, e.Message, e.InnerException?.Message); } } finally { Logger.Log($"Message handler completed for {videoUrl}."); if (Completed != null) { Completed(this, null); } } }
private string GetVideoUrlFromRequest() { string json = GetJsonFromBody(); string videoUrl = QueueMessageParser.GetUrl(json); if (videoUrl == null || videoUrl.Trim() == string.Empty) { throw new ApplicationException("Unable to find video url in payload: \n" + json); } return(videoUrl); }