Receive notifications

Updated at:

After a notification is sent, you can receive the notification in the specified Simple Message Queue (SMQ) queue or topic. This topic describes how to receive notifications.

Preparations

The notification feature is enabled. For more information, see Set up notifications.

Receive notifications in an MNS queue

  • Use MNS SDK for Java to receive notifications. For more information, see Manage queues.

    Note

    In this example, MNS SDK for Java is used. For more information about how to use MNS SDKs for other languages to receive notifications, see Download and use SDKs.

  • Use the MNS console to receive notifications. For more information, see Get started with queue-based messaging.

Receive notifications in an MNS topic

  • Use MNS SDK for Java to receive notifications. For more information, see Manage topics.

    Note

    In this example, MNS SDK for Java is used. For more information about how to use MNS SDKs for other languages to receive notifications, see Download and use SDKs.

  • Use the MNS console to receive notifications. For more information, see Get started with topic-based messaging.

Message format for a job

Parameter

Description

jobId(JobId)

The job ID.

requestId(RequestId)

The request ID.

type(Type)

The type of the job. Valid values:

  • Transcode: a transcoding job

  • Analysis: an intelligent template analysis job

  • Snapshot: a snapshot job

  • MediaInfo: a media information analysis job

state(State)

The status of the job. Valid values:

  • Success: The job is successful.

  • Fail: The job fails.

code

The error code returned if the job fails.

msg

The error message returned if the job fails.

UrlPattern

The snapshot URL, which contains placeholders. The value of this parameter is used as a URL template.

Note

This parameter is returned if the type(Type) parameter is set to Snapshot and snapshots are taken at specific points of time.

LastUrl

The URL of the last snapshot.

Note

This parameter is returned if the type(Type) parameter is set to Snapshot and snapshots are taken at specific points of time.

Count

The total number of snapshots.

Note

This parameter is returned if the type(Type) parameter is set to Snapshot and snapshots are taken at specific points of time.

TimeArray

The point in time at which a snapshot is taken.

Note

This parameter is returned if the type(Type) parameter is set to Snapshot and snapshots are taken at specific points of time.

Sample success callback

{
  "jobId": "8f91f1b630f3469eb5ecf445028f****",
  "JobId": "8f91f1b630f3469eb5ecf445028f****",
  "Type": "Snapshot",
  "userData": "{}",
  "UserData": "{}",
  "State": "Success",
  "state": "Success",
  "type": "Snapshot",

  "LastUrl": "http://example.oss-cn-shanghai.aliyuncs.com/example_output/2021-11-14/V4/Async-V2-00005.jpg",
  "TimeArray": [10050, 50000, 110000, 1000500, 1100500],
  "UrlPattern": "http://eaxmple.oss-cn-shanghai.aliyuncs.com/example_output/2021-11-14/V4/Async-V2-{Count}.jpg",
  "Count": 5
}

Sample failed callback

{
  "msg": "TimeArray greater than video duration.",
  "Msg": "TimeArray greater than video duration.",
  "code": "InvalidParameter.TimeArray",
  "userData": "{}",
  "UserData": "{}",
  "type": "Snapshot",
  "Code": "InvalidParameter.TimeArray",
  "jobId": "f8abc5d9dee0425fa26bb9946df1****",
  "Type": "Snapshot",
  "State": "Fail",
  "UrlPattern": "http://example.oss-cn-shanghai.aliyuncs.com/example_output/2023-11-15/regression_test/TimePoint/V1/Async-V1-{Count}.jpg",
  "TimeArray": [10050, 50000, 110000, 1000500, 1100500, 1800000],
  "state": "Fail",
  "JobId": "f8abc5d9dee0425fa26bb9946df1****"
}

Message format for a workflow

A message that is sent as a notification on a media workflow is in the JSON format. For more information about the parameters in the message, see the description of media workflow messages in the Add a media file topic.

Message structure:

  • Start

    The activity type in the basic attributes of the activity is Start.

  • Structure

    The following code shows the structure.

  • Report

    The activity type in the basic attributes of the activity is Report.

  • Sample code

    { 
          // The parameters in the top level, which are in the JSON format. The parameters define the basic attributes of the activity and the information about the workflow.
          // The basic attributes of the activity are not independent objects, but key-value pairs that directly belong to the top level. The basic attributes include the ID of the workflow instance, activity name, activity type, activity status, and error message if the workflow fails.
          "RunId": "8f8aba5a62ab4127ae2add18da20****",
          "Name": "Act-4",
          "Type": "Report",
          "State": "Success",
          // The information about the workflow, which is in the JSON format. The information includes the ID of the workflow instance, the ID of the media workflow, the name of the media workflow, the media ID, the input file, the type of the workflow instance, the array of activity objects, and the time when the workflow instance is created.
          "MediaWorkflowExecution": {
            "Name": "ConcurrentSuccess",
            "RunId": "8f8aba5a62ab4127ae2add18da20****",
            "Input": {
                "InputFile": {
                    "Bucket": "exampleBucket****",
                    "Location": "oss-test", 
                   "Object": "mediaWorkflow/ConcurrentSuccess/01.wmv",
               }
            },
            "State": "Success",
            "MediaId": "2be491ab4cb6499cd0befe5fcf0c****",
            // The array of activity objects, which is in the JSON format. The array includes all activity objects related to the current workflow execution status.
            For example, only the Start activity object is included in a message for notifying you that the execution of the workflow starts, and all activity objects are included in a message for notifying you that the execution of the workflow ends. 
            // Example: Activity object 1, Activity object 2,...
            "ActivityList": 
    [
                // The information about the activity object, which is in the JSON format. The information includes the activity name, activity type, job ID, activity status, start time, end time, and the error message if the activity fails.    
                {
                    "RunId": "8f8aba5a62ab4127ae2add18da20****",
                    "Name": "Act-1",
                    "Type": "Start",
                    "State": "Success",
                    "StartTime": "2016-03-15T02: 53: 41Z",
                    "EndTime": "2016-03-15T02: 53: 41Z",
                },
                {                
                    "RunId": "8f8aba5a62ab4127ae2add18da20****",
                    "Name": "Act-2",
                    "Type": "Transcode",
                    "JobId": "f34b6d1429dd491faa7a6c1c8f90****",
                    "State": "Success",
                    "StartTime": "2016-03-15T02: 53: 43Z",
                    "EndTime": "2016-03-15T02: 53: 47Z",
                },
                {                
                    "RunId": "8f8aba5a62ab4127ae2add18da20****",
                    "Name": "Act-3",
                    "Type": "Snapshot",
                    "JobId": "c14150be33304825a5d67cd5364c****",
                    "State": "Success",
                    "StartTime": "2016-03-15T02: 53: 44Z",                
                    "EndTime": "2016-03-15T02: 53: 45Z",
                },
                {                
                    "RunId": "8f8aba5a62ab4127ae2add18da20****",
                    "Name": "Act-4",
                    "Type": "Report",
                    "State": "Success",
                    "StartTime": "2016-03-15T02: 53: 49Z",
                    "EndTime": "2016-03-15T02: 53: 49Z", 
               }
            ],
            "CreationTime": "2016-03-15T02: 53: 39Z",
          }
      }