全部产品
存储与CDN 数据库 安全 应用服务 数加·人工智能 数加·大数据基础服务 互联网中间件 视频服务 开发者工具 解决方案 物联网 钉钉智能硬件
批量计算

消息通知

更新时间:2017-06-07 13:26:11

消息通知

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

1. 前期准备

(1) 开通消息服务

(2) 创建MNS主题

(3) 创建MNS主题订阅

(4) 授权BatchCompute推送消息

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

2. 计费相关

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

3. 消息类型

3.1 集群事件

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

  1. {
  2. "Notification": {
  3. "Topic": {
  4. "Name": "test-topic",
  5. "Endpoint": "http://[UserId].mns.[Region].aliyuncs.com/",
  6. "Events": [
  7. "OnClusterDeleted",
  8. "OnInstanceCreated",
  9. "OnInstanceActive"
  10. ]
  11. }
  12. }
  13. }
字段 说明
Name MNS主题名称
Endpoint MNS私网Endpoint,如何获取Endpoint。

3.2 作业事件

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

  1. {
  2. "Notification": {
  3. "Topic": {
  4. "Name": "test-topic",
  5. "Endpoint": "http://[UserId].mns.[Region].aliyuncs.com/",
  6. "Events": [
  7. "OnJobWaiting",
  8. "OnJobRunning",
  9. "OnJobStopped",
  10. "OnJobFinished",
  11. "OnJobFailed",
  12. "OnTaskWaiting",
  13. "OnTaskRunning",
  14. "OnTaskStopped",
  15. "OnTaskFinished",
  16. "OnTaskFailed",
  17. "OnInstanceWaiting",
  18. "OnInstanceRunning",
  19. "OnInstanceStopped",
  20. "OnInstanceFinished",
  21. "OnInstanceFailed",
  22. "OnPriorityChange"
  23. ]
  24. }
  25. }
  26. }
字段 说明
Name MNS主题名称
Endpoint MNS私网Endpoint,如何获取Endpoint。

4. 消息格式

消息格式目前支持json string。

4.1 集群事件

适用于OnClusterDeleted

  1. {
  2. "Category": "Cluster",
  3. "ClusterId": "cls-hr2rbl6qt5gki7392b8001",
  4. "ClusterName": "test-cluster",
  5. "CreationTime": "2016-11-01T15:25:02.837728Z",
  6. "State": "Deleted",
  7. "Event": "OnClusterDeleted"
  8. }

适用于OnInstanceCreated/OnInstanceActive

  1. {
  2. "Category": "Cluster",
  3. "ClusterId": "cls-hr2rbl6qt5gki7392b8001",
  4. "Group": "group1",
  5. "InstanceId": "i-wz9c51g2s6zsrtnqi4fa",
  6. "InnerIpAddress": "10.45.168.26",
  7. "Hints": "",
  8. "State": "Starting",
  9. "CreationTime": "2016-11-01T15:25:02.837728Z",
  10. "Event": "OnInstanceCreated"
  11. }

4.2 作业事件

适用于OnJobWaiting/OnJobRunning/OnJobStopped/OnJobFinished/OnJobFailed

  1. {
  2. "Category": "Job",
  3. "JobId": "job-0000000058524720000077E900007257",
  4. "JobName": "test-job",
  5. "Event": "OnJobWaiting",
  6. "State": "Waiting",
  7. "CreationTime": "2016-11-01T15:25:02.837728Z",
  8. "StartTime": "2016-11-01T15:35:02.837728Z",
  9. "EndTime": "2016-11-01T15:45:02.837728Z",
  10. "Message": ""
  11. }

适用于OnTaskWaiting/OnTaskRunning/OnTaskStopped/OnTaskFinished/OnTaskFailed

  1. {
  2. "Category": "Job",
  3. "JobId": "job-0000000058524720000077E900007257",
  4. "Task": "Echo",
  5. "Event": "OnTaskWaiting",
  6. "State": "Waiting",
  7. "StartTime": "2016-11-01T15:35:02.837728Z",
  8. "EndTime": "2016-11-01T15:45:02.837728Z"
  9. }

适用于OnInstanceWaiting/OnInstanceRunning/OnInstanceStopped/OnInstanceFinished/OnInstanceFailed

  1. {
  2. "Category": "Job",
  3. "JobId": "job-0000000058524720000077E900007257",
  4. "Task": "Echo",
  5. "InstanceId": "0",
  6. "Event": "OnInstanceWaiting",
  7. "State": "Waiting",
  8. "StartTime": "2016-11-01T15:35:02.837728Z",
  9. "EndTime": "2016-11-01T15:45:02.837728Z",
  10. "RetryCount": "0",
  11. "Progress": "0",
  12. "StdoutRedirectPath": "oss://bucket/tests/a44c0ad8-a003-11e6-8f8e-fefec0a80e06/logs/stderr.job-0000000058184218000008150000000D.task.0",
  13. "StderrRedirectPath": "oss://bucket/tests/a44c0ad8-a003-11e6-8f8e-fefec0a80e06/logs/stdout.job-0000000058184218000008150000000D.task.0",
  14. "ExitCode": "0",
  15. "ErrorCode": "",
  16. "ErrorMessage": "",
  17. "Detail": ""
  18. }

适用于OnPriorityChange

  1. {
  2. "Category": "Job",
  3. "JobId": "job-0000000058524720000077E900007257",
  4. "JobName": "test-job",
  5. "Event": "OnPriorityChange",
  6. "State": "Waiting",
  7. "CreationTime": "2016-11-01T15:45:02.837728Z",
  8. "StartTime": "2016-11-01T15:55:02.837728Z",
  9. "EndTime": "2016-11-01T15:57:02.837728Z",
  10. "Message": "",
  11. "From": "10",
  12. "To": "20"
  13. }
本文导读目录