Azure 媒体服务如何设置作业通知



在我之前的问题 Azure 媒体服务编码作业回调到 URL中,建议可以在编码作业完成时将 Azure 媒体服务"支持 WebHook 的通知功能"用于回调到 URL。我在让它工作时遇到了一些麻烦。

采取的步骤:

  1. 创建并测试了一个 Azure 函数,该函数能够向我的任意回调 URL 发送 POST 请求。
  2. 使用 REST API 创建 NotificationEndPoint 并检索 Id(类似于nb:nepid:UUID:e9203dcb-b6a0-4b44-3cc6-69c4a573bb8d(。
  3. 现在尝试将通知添加到我的编码作业中。作业创建 REST API 调用的 JSON 有效负载如下所示:

{
"Name": "TestJob",
"InputMediaAssets" : [
{
"__metadata" : {"uri" : "https://media.windows.net/api/AssetsAssets('nb%3Acid%3AUUID%3A3679cd1f-74ba-4374-8d4b-8c26feba4e1d')"}
}
],
"JobNotificationSubscriptions": [
{
"NotificationEndPointId": "nb:nepid:UUID:e9203dcb-b6a0-4b44-3cc6-69c4a573bb8d",
"TargetJobState": 1
}
],
"Tasks": [
{
"Configuration": "Adaptive Streaming",
"MediaProcessorId": "nb:mpid:UUID:fa4df505-d219-42b0-bc17-a481c1441e56",
"TaskBody": "<?xml version="1.0" encoding="utf-8"?><taskBody><inputAsset>JobInputAsset(0)</inputAsset><outputAsset>JobOutputAsset(0)</outputAsset></taskBody>"
}
]
}

这在没有JobNotificationSubscriptions部分的情况下有效,但有了它,我只是得到响应:

"error": {
"code": "",
"message": {
"lang": "en-US",
"value": "An error occurred while processing this request."
}
}

如何使通知与我的作业配合使用?

当我在 2014 年偶然看到这篇文章时,我能够解决这个问题:https://social.msdn.microsoft.com/Forums/sqlserver/en-US/cc69a85f-74b0-4d52-8e69-629ff5007169/create-an-encoding-job-with-jobnotificationsubscriptions-by-using-rest-api-got-a-response-with-400?forum=MediaServices

这里有三个明显的因素导致成功:

  1. 在请求标头中,DataServiceVersion 和 MaxDataServiceVersion 都需要设置为 3.0。这对我来说已经是这种情况,不需要改变,但对于其他试图解决相同问题的人来说可能很重要。
  2. 需要将InputMediaAssets属性更改为格式InputMediaAssets@odata.bind":["https://wamsos1clus001rest-hs.cloudapp.net/api/Assets('nb%3Acid%3AUUID%3Acee6b356-a0d0-4cfa-955b-e81cbebebb8e')"],
  3. 在请求标头中,我需要从Content-Type=application/json;odata=verbose更改为Content-Type=application/json

当请求在没有JobNotificationSubscriptions部分的情况下工作时,为什么这些因素很重要仍然是一个谜。

最新更新