全部產品
Search
文件中心

Batch Compute:訊息通知

更新時間:Jul 06, 2024

批次運算服務(BatchCompute)使用 MNS 提供的主題模式來實現訊息通知。

使用者負責主題(Topic)的建立、管理和訂閱,並在使用 BatchCompute 建立叢集或提交作業時指定主題相關的配置。BatchCompute 依據配置向指定使用者主題推送訊息。使用者可在 MNS 控制台配置 URL、隊列、郵件和簡訊四種方式擷取訊息通知。目前,BatchCompute 主要支援兩大類訊息事件,即叢集事件和作業事件。

A) 開通Message Service

B) 建立 MNS 主題

C) 建立 MNS 主題訂閱

1. 授權 BatchCompute 推送訊息

請登入控制台上進行一鍵授權。如果沒有授權過,控制台會出現這個提示:授權如果已經授權,過請忽略。

2. 計費相關

訊息通知產生的費用統一由 Message Service結算,批次運算不再額外收取。

3. 訊息類型

A) 叢集事件

使用 SDK 或控制台建立叢集(cluster)時,可以配置如下類型訊息事件。

{
    "Notification": {
        "Topic": {
            "Name": "test-topic",
            "Endpoint": "http://[UserId].mns.[Region].aliyuncs.com/", 
            "Events": [
                "OnClusterDeleted",
                "OnInstanceCreated",
                "OnInstanceActive"
            ]
        }
    }
}
欄位說明
NameMNS 主題名稱
EndpointMNS 私網 Endpoint,參考 如何擷取 Endpoint

B) 作業事件

使用 SDK 或控制台建立作業(job)時,可以配置如下類型訊息事件。

{
    "Notification": {
        "Topic": {
            "Name": "test-topic",
            "Endpoint": "http://[UserId].mns.[Region].aliyuncs.com/",
            "Events": [
                "OnJobWaiting",
                "OnJobRunning",
                "OnJobStopped",
                "OnJobFinished",
                "OnJobFailed",
                "OnTaskWaiting",
                "OnTaskRunning",
                "OnTaskStopped",
                "OnTaskFinished",
                "OnTaskFailed",
                "OnInstanceWaiting",
                "OnInstanceRunning",
                "OnInstanceStopped",
                "OnInstanceFinished",
                "OnInstanceFailed",
                "OnPriorityChange"
            ]
        }
    }
}
欄位說明
NameMNS主題名稱
EndpointMNS私網Endpoint,參考 如何擷取 Endpoint

4. 訊息格式

訊息格式目前支援 json string。

A) 叢集事件

適用於 OnClusterDeleted

 {
    "Category": "Cluster",
    "ClusterId": "cls-hr2rbl6qt5gki7392b8001",
    "ClusterName": "test-cluster",
    "CreationTime": "2016-11-01T15:25:02.837728Z",
    "State": "Deleted",
    "Event": "OnClusterDeleted"
}

適用於 OnInstanceCreated/OnInstanceActive

{
    "Category": "Cluster",
    "ClusterId": "cls-hr2rbl6qt5gki7392b8001",
    "Group": "group1",
    "InstanceId": "i-wz9c51g2s6zsrtnqi4fa",
    "InnerIpAddress": "10.45.168.26",
    "Hints": "",
    "State": "Starting",
    "CreationTime": "2016-11-01T15:25:02.837728Z",
    "Event": "OnInstanceCreated"
}

B) 作業事件

適用於 OnJobWaiting/OnJobRunning/OnJobStopped/OnJobFinished/OnJobFailed

{
    "Category": "Job",
    "JobId": "job-0000000058524720000077E900007257",
    "JobName": "test-job",
    "Event": "OnJobWaiting",
    "State": "Waiting",
    "CreationTime": "2016-11-01T15:25:02.837728Z",
    "StartTime": "2016-11-01T15:35:02.837728Z",
    "EndTime": "2016-11-01T15:45:02.837728Z",
    "Message": ""
}

適用於 OnTaskWaiting/OnTaskRunning/OnTaskStopped/OnTaskFinished/OnTaskFailed

{
    "Category": "Job",
    "JobId": "job-0000000058524720000077E900007257",
    "Task": "Echo",
    "Event": "OnTaskWaiting",
    "State": "Waiting",
    "StartTime": "2016-11-01T15:35:02.837728Z",
    "EndTime": "2016-11-01T15:45:02.837728Z"
}

適用於 OnInstanceWaiting/OnInstanceRunning/OnInstanceStopped/OnInstanceFinished/OnInstanceFailed

{
    "Category": "Job",
    "JobId": "job-0000000058524720000077E900007257",
    "Task": "Echo",
    "InstanceId": "0",
    "Event": "OnInstanceWaiting",
    "State": "Waiting",
    "StartTime": "2016-11-01T15:35:02.837728Z",
    "EndTime": "2016-11-01T15:45:02.837728Z",
    "RetryCount": "0",
    "Progress": "0",
    "StdoutRedirectPath": "oss://bucket/tests/a44c0ad8-a003-11e6-8f8e-fefec0a80e06/logs/stderr.job-0000000058184218000008150000000D.task.0",
    "StderrRedirectPath": "oss://bucket/tests/a44c0ad8-a003-11e6-8f8e-fefec0a80e06/logs/stdout.job-0000000058184218000008150000000D.task.0",
    "ExitCode": "0",
    "ErrorCode": "",
    "ErrorMessage": "",
    "Detail": ""
}

適用於 OnPriorityChange

{
    "Category": "Job",
    "JobId": "job-0000000058524720000077E900007257",
    "JobName": "test-job",
    "Event": "OnPriorityChange",
    "State": "Waiting",
    "CreationTime": "2016-11-01T15:45:02.837728Z",
    "StartTime": "2016-11-01T15:55:02.837728Z",
    "EndTime": "2016-11-01T15:57:02.837728Z",
    "Message": "",
    "From": "10",
    "To": "20"
}