Simple Message Queue (formerly MNS) callbacks

更新时间:
复制 MD 格式

Use Simple Message Queue (formerly MNS) to receive event notifications from ApsaraVideo VOD.

Background information

Alibaba Cloud Simple Message Queue (formerly MNS) (SMQ) is an efficient, reliable, secure, and scalable distributed message queue service. Simple Message Queue (formerly MNS) provides a queue model that allows multiple producers and consumers to concurrently access the same queue. After a message is retrieved, it becomes unavailable to other consumers for a specific period. You must explicitly delete the message after consumption; otherwise, it can be consumed again. ApsaraVideo VOD supports using Simple Message Queue (formerly MNS) to send callback information. For more information about Simple Message Queue (formerly MNS), see What is Simple Message Queue (formerly MNS)?.

Simple Message Queue (formerly MNS) callback mechanism

  1. You need to create a queue in Simple Message Queue (formerly MNS) and configure the corresponding callbacks in ApsaraVideo VOD.

  2. When an event occurs, ApsaraVideo VOD writes the event notification to the message Simple Message Queue (formerly MNS) in Simple Message Queue (formerly MNS).

  3. A callback is considered successful only if ApsaraVideo VOD successfully writes the message to the Simple Message Queue (formerly MNS). If the write operation fails due to configuration errors such as ApsaraVideo VOD not being authorized to access Simple Message Queue (formerly MNS), the endpoint not being a public endpoint, or an incorrect queue name, ApsaraVideo VOD makes up to three attempts to send the callback. If all three attempts fail, the message is discarded. For more information about the callback validation and retry logic, see Callback validation and retries.

  4. After a successful callback, you must retrieve messages from the Simple Message Queue (formerly MNS) to view the event notification content. After processing a message, you must explicitly delete it to prevent it from being consumed again.

How to use

Prerequisites

Usage notes

  • ApsaraVideo VOD is available in multiple regions. Event notification settings are independent for each region, so you can configure a unique callback method and URL for each region.

  • In Simple Message Queue (formerly MNS), you can create multiple Simple Message Queue (formerly MNS) queues in different regions, but in ApsaraVideo VOD, you can configure only one Simple Message Queue (formerly MNS) queue for MNS callbacks in each region. We recommend that you create and use queues in the following regions:

    • If your videos are stored in a Chinese mainland region, such as China (North 2) or China (East 2), we recommend that you use a queue in the China (Shanghai) region. Pushing messages to a queue outside the China (Shanghai) region may cause minor delays.

    • If your videos are stored in other regions, such as Singapore or Japan, we recommend that you create or use a message queue in the same region.

      For example, if your videos are stored in the Singapore region, you must create or use a message queue in the Singapore region.

  • SMQ callbacks support multiple callback URLs for different development environments. For more information, see Configure multiple callback URLs.

Procedure

  1. Authorize ApsaraVideo VOD to access Simple Message Queue (formerly MNS).

    You can grant authorization in either of the following ways:

    • Method 1: Grant ApsaraVideo VOD permissions to access your cloud resources. This includes partial permissions for OSS, Simple Message Queue (formerly MNS), CDN, and KMS.

      Log on to the Alibaba Cloud Console, go to the RAM Quick Authorization page, and click Agree to Authorization to grant the permissions.image

    • Method 2: Grant a RAM user, RAM user group, or RAM role the required permissions to access Simple Message Queue (formerly MNS).

      Add the AliyunMNSFullAccess (permissions to manage Simple Message Queue (formerly MNS)) or AliyunMNSReadOnlyAccess (permissions to manage Simple Message Queue (formerly MNS)) system policy to your authorization policy. For detailed instructions, see Create a RAM User and Grant Permissions.

  2. Create a queue in Simple Message Queue (formerly MNS).

    Create a new queue or use an existing one in Simple Message Queue (formerly MNS). You can create a queue by using the console or an API/SDK. For console instructions, see Create a queue. For information about the related API operations and SDKs, see Queue operations.

    Note

    We recommend that you create or use a queue in the region suggested in Usage notes.

  3. In ApsaraVideo VOD, configure event notifications to use the Simple Message Queue (formerly MNS) callback method.

    Note

    Callback settings configured in the ApsaraVideo VOD console apply globally. You can use an OpenAPI to configure global callbacks or implement a single-request override.

    Console

    1. Log on to the ApsaraVideo VOD console.

    2. In the left-side navigation pane, choose Configuration Management > Media Processing > Callback.

    3. In the top navigation bar, select the target region from the drop-down list next to Workbench.

    4. Configure the Callback.MNS回调1.png

      1. In the Callback section, click Modify.

      2. Configure the callback parameters.

        Parameter

        Description

        Callback method

        Select Simple Message Queue (formerly MNS).

        Region

        Select the region where the video is stored. We recommend that you select the same region as the queue that you created in Simple Message Queue (formerly MNS).

        Queue

        Select a queue in the specified region.

        Note

        If no queues are available, create one first. For more information, see Create a queue.

        Callback event

        Select the event types for which you want to receive notifications. For more information about the supported event types and their descriptions, see Event list.

        Note

        If you select Video AI Processing Complete, notifications are triggered for any of the AI events, including AIMediaAuditComplete, AIMediaDNAComplete, and AIVideoTagComplete.

      3. Click OK to save the Simple Message Queue (formerly MNS) callback settings.

    API

    Call API operations to configure global callbacks or perform a single-request override.

    Note

    A single-request override by specifying the MessageCallback field in the UserData parameter takes effect only if you have enabled global event notifications in ApsaraVideo VOD and configured the corresponding event types. Otherwise, the override for the single request does not take effect.

  4. Trigger a callback event.

    After you configure event notifications, perform operations in ApsaraVideo VOD such as uploading media files or initiating media processing jobs to trigger callback events.

  5. View messages in Simple Message Queue (formerly MNS).

    When a callback event is triggered, ApsaraVideo VOD writes the event notification to your specified queue. Retrieve messages from Simple Message Queue (formerly MNS) and view the notification content in the message details.

    You can retrieve messages by using the console or an API/SDK. For console instructions, see Receive messages. For a list of related API operations and SDKs, see Overview of queue-related API operations.

  6. Optional: Delete messages in Simple Message Queue (formerly MNS).

    You must explicitly delete a message after it is consumed. Otherwise, it will become visible again in the queue after a specific period and may be consumed again.

    You can delete messages by using the console or an API/SDK. For console instructions, see Queue operations. For a list of related API operations and SDKs, see Overview of queue-related API operations.

SDK examples

Simple Message Queue (formerly MNS) provides SDKs for multiple programming languages. After you configure callbacks, use the corresponding SDK to consume messages:

Related documents