通过阅读本文,您可以了解配置剪辑完成时回调的方法。
实现说明
配置剪辑完成时的回调可以通过自定义单任务回调地址或配置全局回调地址来实现,实现说明如下所示:
- 自定义单任务回调地址时,您需要调用SubmitMediaProducingJob接口,传入HTTP(S)回调地址或MNS回调地址。HTTP(S)回调需要部署一个HTTP服务来接收回调消息,并在剪辑合成请求中配置回调URL;当剪辑合成任务完成时,IMS服务端会对该URL发起HTTP
POST请求,任务完成情况内容将通过HTTP Body送达给用户。MNS回调则需要用户在任务完成的地域(Region)配置以
ice-callback
开头的消息队列,IMS服务器会将消息内容发送至您的MNS消息队列中。
- 配置全局回调地址仅支持MNS消息的配置。
关于剪辑合成任务完成时的消息结构,请参见智能剪辑。
配置全局回调地址
- 在消息服务MNS控制台创建回调消息队列,队列名称必须以
ice-callback
开头。具体操作,请参见创建队列。
- 调用SetEventCallback设置事件回调,传入
CallbackQueueName
,即步骤 1中的队列名称。
- 监听步骤 1中的消息队列,并对消息进行处理。示例代码如下所示:
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) {
// 读取 ~/.aliyun-mns.properties 文件中的mns 配置:
// mns.accesskeyid, mns.accesskeysecret, mns.queue.endpoint
// ak/sk 所属子用户拥有 MNS 的完全读写权限
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());
// 只处理 ProduceMediaComplete 类型消息:
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();
}
}