Search code examples
azure-storageazure-media-servicesazure-queues

Azure Notification Messages never reach the notification queue using Media Services


I am currently adding video services to an application using Azure media services and Azure Storage with C# web api. The upload process seems to be working correctly and I can see where the job completes successfully from the admin. console.

However, if I run the application under the debugger I see where messages are being added to the queue for actually processing the videos but I never get any messages in the notification queue. I keep reviewing the code but I don't see anything that appears to be off. Has anyone encountered this before or have any idea of what the problem could be? I am currently testing in debug mode with my connection strings set to UseDevelopmentStorage=true.

// create a NotificationEndPoint queue based on the endPointAddress
string endPointAddress = "queuename";

// setup the notificationEndPoint based on the queue and endPointAddress
this.notificationEndPoint = this._context.NotificationEndPoints.Create(Guid.NewGuid().ToString(), NotificationEndPointType.AzureQueue, endPointAddress);

if (this.notificationEndPoint != null)
{
     job.JobNotificationSubscriptions.AddNew(NotificationJobState.All, this.notificationEndPoint);
     await job.SubmitAsync().ConfigureAwait(false);
      .
      .
      .



Here is the message object:
public class VideoJobNotificationMessage : AzureQueueMessage
{
// MessageVersion is used for version control. 
public string MessageVersion { get; set; }

// Type of the event. Valid values are 
// JobStateChange and NotificationEndpointRegistration.
public string EventType { get; set; }

// ETag is used to help the customer detect if 
// the message is a duplicate of another message previously sent.
public string ETag { get; set; }

// Time of occurrence of the event.
public string TimeStamp { get; set; }

// Collection of values specific to the event.
public IDictionary<string, object> Properties { get; set; }
}

Solution

  • Just run verification test ShouldReceiveNotificationsForCompeletedJob from https://github.com/Azure/azure-sdk-for-media-services/blob/dev/test/net/Scenario/JobTests.cs which verifies notifications workflow. Test is passing in US WEST data center.

    Please note that job notifications through azure storage queue are not designed to be real time and as you can see there is few minutes delay between messages appears in queue.

    Pasting code related to queue creation:

     string endPointAddress = Guid.NewGuid().ToString();
                    CloudQueueClient client = CloudStorageAccount.Parse(WindowsAzureMediaServicesTestConfiguration.ClientStorageConnectionString).CreateCloudQueueClient();
                    CloudQueue queue = client.GetQueueReference(endPointAddress);
                    queue.CreateIfNotExists();
                    string endPointName = Guid.NewGuid().ToString();
                    INotificationEndPoint notificationEndPoint = _mediaContext.NotificationEndPoints.Create(endPointName, NotificationEndPointType.AzureQueue, endPointAddress);
                    Assert.IsNotNull(notificationEndPoint);
     job.JobNotificationSubscriptions.AddNew(NotificationJobState.All, notificationEndPoint);
    
    .......
    
                job.Submit();
    
                Assert.IsTrue(job.JobNotificationSubscriptions.Count > 0);
    
                WaitForJob(job.Id, JobState.Finished, VerifyAllTasksFinished);
                Thread.Sleep((int)TimeSpan.FromMinutes(5).TotalMilliseconds);
    
                Assert.IsNotNull(queue);
                Assert.IsTrue(queue.Exists());
                IEnumerable<CloudQueueMessage> messages = queue.GetMessages(10);
                Assert.IsTrue(messages.Any());
                Assert.AreEqual(4, messages.Count(), "Expecting to have 4 notifications messages");