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

Azure Media Services How to Set Up Job Notifications

在我之前的问题 中,建议 Azure 媒体服务 "Notifications features which supports WebHooks" 可以在编码作业完成时回调到 URL。我在让它工作时遇到了一些麻烦。

采取的步骤:

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

{
    "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 年遇到这个 post 时,我能够解决这个问题: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. 在请求header中,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. 在请求header中,我需要将Content-Type=application/json;odata=verbose更改为Content-Type=application/json

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