When you use the online editing feature of Intelligent Media Services (IMS), you can configure callback events to obtain the progress and status of jobs at the earliest opportunity. This way, you can perform other business operations based on the events. This topic describes how to configure callback settings for completed editing jobs.
Callback methods
You can use HTTP requests and SMQ queues to receive event notifications. For more information, see Callback methods.
Implementation
You can configure custom callback URLs for individual jobs or configure a global callback URL.
Custom callback URL for a single job: the callback URL that is specified when you submit an editing and production job. You must call the SubmitMediaProducingJob operation to specify the HTTP or HTTPS callback URL or a Simple Message Queue (SMQ) callback URL.
If you use HTTP or HTTPS callbacks, you must deploy an HTTP service to receive callback messages and configure a callback URL when you submit an editing and production job. When the job is complete, the IMS server sends an HTTP POST request to the URL. The progress of the job is sent to the user through the HTTP request body.
If you select MNS callbacks, you must configure a message queue that starts with
ice-callback
in the region where the job is completed. The IMS server sends messages to the message queue.
Global callback URL: applies to callback notifications for all media processing jobs. You can specify a message queue endpoint as the global callback URL in Global Settings of IMS. When a job is completed, IMS sends a notification to the configured global callback URL.
NoteOnly message queues of SMQ are supported.
Message structure
For more information about the message structure when an editing and production job is completed, see Event list.
Prerequisites
IMS is authorized to access SMQ if the SMQ queue method is used. For more information, see Activate SMQ and authorize RAM users to access SMQ.
Configure a custom callback URL for a single job
You can configure a custom callback URL for a single job to receive notifications when the job is complete. When you call the SubmitMediaProducingJob operation to submit a job, you can specify the HTTP, HTTPS, or SMQ callback URL in the UserData parameter. Sample code:
HTTP or HTTPS callback URL
{"NotifyAddress":"http(s)://**.**.***"}
SMQ callback URL (must be the endpoint of a message queue that starts with
ice-callback
){"NotifyAddress":"ice-callback-****"}
Configure a global callback URL
Create a message queue in the SMQ console. The message queue must start with
ice-callback
. For more information, see Create a queue.Call the SetEventCallback operation to configure event callbacks and specify the name of the message queue created in Step 1 in the
CallbackQueueName
parameter.Listen to the message queue in Step 1 and process the messages. The following sample code provides an example.
NoteThe version number of the server SDK introduced in the following sample code is for reference only. For more information about how to obtain the latest version, see Server SDK.
<dependencies> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.9</version> </dependency> <dependency> <groupId>com.aliyun.mns</groupId> <artifactId>aliyun-sdk-mns</artifactId> <version>1.1.9</version> </dependency> </dependencies>
import java.util.List; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.aliyun.mns.client.CloudAccount; import com.aliyun.mns.client.CloudQueue; import com.aliyun.mns.client.MNSClient; import com.aliyun.mns.common.ClientException; import com.aliyun.mns.common.ServiceException; import com.aliyun.mns.common.utils.ServiceSettings; import com.aliyun.mns.model.Message; public class IceProduceMessageConsumerDemo { public static void main(String[] args) { // Read the SMQ configuration from the ~/.aliyun-mns.properties file: // mns.accesskeyid, mns.accesskeysecret, mns.queue.endpoint // The RAM user to which the AccessKey pair belongs has full read and write permissions on SMQ. CloudAccount account = new CloudAccount( ServiceSettings.getMNSAccessKeyId(), ServiceSettings.getMNSAccessKeySecret(), ServiceSettings.getMNSAccountEndpoint()); MNSClient client = account.getMNSClient(); //this client need only initialize once // Demo for receive message code try{ CloudQueue queue = client.getQueueRef("ice-callback-test");// replace with your queue name List<Message> messages = queue.batchPopMessage(10, 30); for(Message popMsg : messages) { if (popMsg != null){ System.out.println("message handle: " + popMsg.getReceiptHandle()); System.out.println("message body: " + popMsg.getMessageBodyAsString()); System.out.println("message id: " + popMsg.getMessageId()); System.out.println("message dequeue count:" + popMsg.getDequeueCount()); JSONObject jsonObject = JSON.parseObject(popMsg.getMessageBodyAsString()); // Process only messages of the ProduceMediaComplete type: if("ProduceMediaComplete".equals(jsonObject.getString("EventType"))){ JSONObject messageBody = jsonObject.getJSONObject("MessageBody"); System.out.println("ProjectId:" + messageBody.getString("ProjectId")); System.out.println("JobId:" + messageBody.getString("JobId")); System.out.println("Status:" + messageBody.getString("Status")); System.out.println("MediaId:" + messageBody.getString("MediaId")); System.out.println("MediaURL:" + messageBody.getString("MediaURL")); //<<to add your special logic.>> //remember to delete message when consume message successfully. //queue.deleteMessage(popMsg.getReceiptHandle()); System.out.println("delete message successfully.\n"); } } } } catch (ClientException ce) { System.out.println("Something wrong with the network connection between client and MNS service." + "Please check your network and DNS availability."); ce.printStackTrace(); } catch (ServiceException se) { if (se.getErrorCode().equals("QueueNotExist")) { System.out.println("Queue is not exist.Please create queue before use"); } else if (se.getErrorCode().equals("TimeExpired")) { System.out.println("The request is time expired. Please check your local machine timeclock"); } /* you can get more MNS service error code in following link. https://help.aliyun.com/document_detail/mns/api_reference/error_code/error_code.html?spm=5176.docmns/api_reference/error_code/error_response */ se.printStackTrace(); } catch (Exception e) { System.out.println("Unknown exception happened!"); e.printStackTrace(); } client.close(); } }