Create and monitor Media Services events with Event Grid using the Azure portal

Azure Event Grid is an eventing service for the cloud. This service uses event subscriptions to route event messages to subscribers. Media Services events contain all the information you need to respond to changes in your data. You can identify a Media Services event because the eventType property starts with "Microsoft.Media.". For more information, see Media Services event schemas.

In this article, you use the Azure portal to subscribe to events for your Azure Media Services account. Then, you trigger events to view the result. Typically, you send events to an endpoint that processes the event data and takes actions. In the article, we send events to a web app that collects and displays the messages.

When you're finished, you see that the event data has been sent to the web app.

Prerequisites

  • Have an active Azure subscription.
  • Create a new Azure Media Services account, as described in this quickstart.

Create a message endpoint

Before subscribing to the events for the Media Services account, let's create the endpoint for the event message. Typically, the endpoint takes actions based on the event data. In this article, you deploy a pre-built web app that displays the event messages. The deployed solution includes an App Service plan, an App Service web app, and source code from GitHub.

  1. Select Deploy to Azure to deploy the solution to your subscription. In the Azure portal, provide values for the parameters.

  2. The deployment may take a few minutes to complete. After the deployment has succeeded, view your web app to make sure it's running. In a web browser, navigate to: https://<your-site-name>.azurewebsites.net

If you switch to the "Azure Event Grid Viewer" site, you see it has no events yet.

Enable Event Grid resource provider

If you haven't previously used Event Grid in your Azure subscription, you may need to register the Event Grid resource provider.

In the Azure portal:

  1. Select Subscriptions.
  2. Select the subscription you're using for Event Grid.
  3. Under Settings, select Resource providers.
  4. Find Microsoft.EventGrid.
  5. If not registered, select Register.

It may take a moment for the registration to finish. Select Refresh to update the status. When Status is Registered, you're ready to continue.

Subscribe to Media Services events

You subscribe to a topic to tell Event Grid which events you want to track, and where to send the events.

  1. In the portal, select your Media Services account and select Events.

  2. To send events to your viewer app, use a web hook for the endpoint.

    Select web hook

  3. The event subscription is prefilled with values for your Media Services account.

  4. Select 'Web Hook' for the Endpoint Type.

  5. In this topic, we leave the Subscribe to all event types checked. However, you can uncheck it and filter for specific event types.

  6. Click on the Select an endpoint link.

    For the web hook endpoint, provide the URL of your web app and add api/updates to the home page URL.

  7. Press Confirm Selection.

  8. Press Create.

  9. Give your subscription a name.

    Select logs

  10. View your web app again, and notice that a subscription validation event has been sent to it.

    Event Grid sends the validation event so the endpoint can verify that it wants to receive event data. The endpoint has to set validationResponse to validationCode. For more information, see Event Grid security and authentication. You can view the web app code to see how it validates the subscription.

Now, let's trigger events to see how Event Grid distributes the message to your endpoint.

Send an event to your endpoint

You can trigger events for the Media Services account by running an encoding job. You can follow this quickstart to encode a file and start sending events. If you subscribed to all events, you will see a screen similar to the following:

Tip

Select the eye icon to expand the event data. Do not refresh the page, if you want to view all the events.

View subscription event

Next steps

Upload, encode, and stream