批量计算服务(BatchCompute)使用 MNS 提供的主题模式来实现消息通知。

用户负责主题(Topic)的创建、管理和订阅,并在使用 BatchCompute 创建集群或提交作业时指定主题相关的配置。BatchCompute 依据配置向指定用户主题推送消息。用户可在 MNS 控制台配置 URL、队列、邮件和短信四种方式获取消息通知。目前,BatchCompute 主要支持两大类消息事件,即集群事件和作业事件。

A) 开通消息服务

B) 创建 MNS 主题

C) 创建 MNS 主题订阅

1. 授权 BatchCompute 推送消息

请登录控制台上进行一键授权。如果没有授权过,控制台会出现这个提示:授权如果已经授权,过请忽略。

2. 计费相关

消息通知产生的费用统一由 消息服务结算,批量计算不再额外收取。

3. 消息类型

A) 集群事件

使用 SDK 或控制台创建集群(cluster)时,可以配置如下类型消息事件。

{
    "Notification": {
        "Topic": {
            "Name": "test-topic",
            "Endpoint": "http://[UserId].mns.[Region].aliyuncs.com/", 
            "Events": [
                "OnClusterDeleted",
                "OnInstanceCreated",
                "OnInstanceActive"
            ]
        }
    }
}
字段 说明
Name MNS 主题名称
Endpoint MNS 私网 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"
            ]
        }
    }
}
字段 说明
Name MNS主题名称
Endpoint MNS私网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"
}