All Products
Search
Document Center

ApsaraVideo VOD:MNS callbacks

Last Updated:Apr 02, 2024

This topic describes the mechanism and usage of Alibaba Cloud Message Service (MNS) callbacks.

Background information

MNS is a distributed messaging service that features scalability, high efficiency, reliability, security, and availability. MNS provides queues to support a large number of concurrent requests from multiple producers and consumers. After a message is pulled from a queue, the message cannot be pulled again for a specified period of time. A message is invisible for a period of time after it is consumed. If you do not manually delete the message, it can be consumed again. You can use MNS to receive event notifications for ApsaraVideo VOD. For more information about MNS, see What is MNS?.

MNS callback mechanism

  1. You must create a queue in the MNS console and configure callbacks in the ApsaraVideo VOD console.

  2. When an event occurs, ApsaraVideo VOD pushes the callback message to the queue in MNS.

  3. If the message is pushed to the MNS queue, the callback is successful. Otherwise, the callback fails. If the callback message fails to be pushed to the queue due to incorrect configurations, ApsaraVideo VOD retries to push the message two times. For example, the callback message fails to be pushed if ApsaraVideo VOD is not authorized to access MNS, the MNS endpoint is not a public endpoint, or the queue name is incorrect. If the callback message fails to be pushed after three attempts, ApsaraVideo VOD discards the message. For more information about the retry logic and how to determine a successful callback, see Overview.

  4. After the callback succeeds, you must obtain the callback message from MNS. You can delete a message only after it is received and consumed. A message is invisible for a period of time after it is consumed. If you do not manually delete the message, it can be consumed again.

Usage notes

Prerequisites

Limits

  • ApsaraVideo VOD supports multiple storage regions. The event notification configurations among regions are independent of each other. You can use different callback methods and callback URLs for different regions. You can upload videos to different regions. After a video is processed, such as uploaded or transcoded, ApsaraVideo VOD notifies you of the processing results based on the callback configurations for the regions and pushes messages to your MNS queues.

  • We recommend that you configure MNS callbacks based on the following rules:

    • If you store videos in the Chinese mainland, push callback messages to an MNS queue in the China (Shanghai) region. If you push callback messages to a queue in a region other than China (Shanghai), you may experience a short delay.

    • If you store videos outside the Chinese mainland, such as the Singapore or Japan (Tokyo) region, we recommend that you push callback messages to an MNS queue in the same region where your videos are stored.

      For example, if you store videos in the Singapore region, we recommend that you create or use an MNS queue in the Singapore region.

Procedure

  1. Authorize ApsaraVideo VOD to access MNS.

    You can use one of the following methods to authorize ApsaraVideo VOD to access MNS:

    • Method 1: Authorize ApsaraVideo VOD to access cloud resources in Object Storage Service (OSS), MNS, Alibaba Cloud CDN, and Key Management Service (KMS).

      Log on to the Alibaba Cloud Management Console. On the Cloud Resource Access Authorization page, click Confirm Authorization Policy. Cloud Resource Access Authorization

    • Method 2: Grant permissions to users, user groups, or roles of ApsaraVideo VOD to access MNS.

      Attach the AliyunMNSFullAccess or AliyunMNSReadOnlyAccess policy to users, users groups, or roles of ApsaraVideo VOD. For more information, see Create and grant permissions to a RAM user.

  2. Create an MNS queue.

    Create an MNS queue or use an existing queue. You can create a queue by using the MNS console, API, or SDK. For information about how to create a queue by using the MNS console, see Create a queue. For information about how to create a queue by using the MNS API or SDK, see Queue-related operations.

    Note

    We recommend that you follow the rules described in Limits to create or use queues.

  3. Configure MNS callbacks to receive event notifications.

    Select an MNS queue and events for which you want to configure callbacks in ApsaraVideo VOD based on your business requirements. For more information about supported events and event notification content, see Events.

    You can configure event notifications by using the ApsaraVideo VOD console, API, or SDK. The following items describe how to configure event notifications:

    • By using the ApsaraVideo VOD console

      Log on to the ApsaraVideo VOD console. In the left-side navigation pane, choose Configuration Management > Media Processing > Callback. On the Callback page, configure the region, MNS queue, and the events for which you want to configure callbacks. For more information, see Configure callbacks.

      MNS callback

      Note
      • If you configure event callbacks by using the ApsaraVideo VOD console, the settings take effect globally.

      • If you select AI Processing Completed, notifications are sent for all AI events such as AIMediaAuditComplete, AIMediaDNAComplete, and AIVideoTagComplete.

    • By using the ApsaraVideo VOD API or SDK

      Call the SetMessageCallback operation. Set CallbackType to MNS and specify other request parameters such as EventTypeList, MnsEndpoint, and MnsQueueName.

  4. Trigger the event.

    After you configure event notifications, you can perform operations, such as uploading audio, video, or image files, to trigger the event. You can also submit media processing jobs, such as transcoding jobs and snapshot jobs, to trigger the event.

  5. View the callback message in MNS.

    When a callback is triggered, ApsaraVideo VOD pushes the callback message to the MNS queue that you specified. You must receive the message in MNS and view the notification content.

    You can receive callback messages by using the MNS console, API, or SDK. For information about how to receive callback messages by using the MNS console, see Receive a message. For information about how to receive callback messages by using the MNS API or SDK, see Message-related operations.

  6. Optional:Delete the callback message in MNS.

    MNS queues support a large number of concurrent access requests from multiple producers and consumers. After a message is pulled from a queue, the message cannot be pulled again within a specified period of time. A message is invisible for a period of time after it is consumed. If you do not manually delete the message, it can be consumed again.

    You can delete callback messages by using the MNS console, API, or SDK. For information about how to delete callback messages by using the MNS console, see Delete a message. For information about how to delete callback messages by using the MNS API or SDK, see Message-related operations.

SDKs

MNS provides SDKs for multiple languages. After you configure callbacks, you can use code to consume callback messages. The following items provide references on how to consume callback messages:

  • For information about how to consume messages by using Java code, see Manage queues.

  • For information about how to consume messages by using Python code, see Manage queues.

  • For information about how to consume messages by using C# code, see Manage queues.

  • For information about how to consume messages by using PHP code, see Manage queues.

  • If the programming language that you use is not listed in the preceding items, you can call the ReceiveMessage operation to receive messages and the DeleteMessage operation to delete messages. For more information, see Request structure.

References

  • For more information about the comparison between HTTP callbacks and MNS callbacks, see the "Comparison between HTTP callbacks and MNS callbacks" section of the Overview topic.

  • If issues occur when you configure MNS callbacks, see FAQ about event notifications.