Repository: aliyun/fun
Pull request #153 (2019-02-17 01:45:53)

mns trigger support triggerConfig


Patch:
diff --git a/docs/specs/2018-04-03-zh-cn.md b/docs/specs/2018-04-03-zh-cn.md
index 12677a7..87f55aa 100644
--- a/docs/specs/2018-04-03-zh-cn.md
+++ b/docs/specs/2018-04-03-zh-cn.md
@@ -387,7 +387,9 @@ rds-trigger-test: # trigger name
 ---|:---:|---
 TopicName| `string` | **必填。** mns topic的名字
 Region   | `string` | **可选。** mns topic 所在的 region，如果不填，默认为和函数一样的 region
-
+NotifyContentFormat   | `string` | **可选。** 推送给函数入参 event 的格式，可选值：STREAM, JSON, 默认值为: STREAM
+NotifyStrategy   | `string` | **可选。** 调用函数的重试策略，可选值：BACKOFF_RETRY, EXPONENTIAL_DECAY_RETRY, 默认值为: BACKOFF_RETRY, 详情参考 [NotifyStrategy](https://help.aliyun.com/document_detail/27481.html)
+FilterTag   | `string` | **可选。** 描述了该订阅中消息过滤的标签（标签一致的消息才会被推送）,不超过 16 个字符的字符串，默认不进行消息过滤，即默认不填写该字段
 
 ##### 示例：MNSTopic 事件源对象
 
@@ -397,6 +399,8 @@ mns-topic-trigger-test: # trigger name
     Properties:
         TopicName: test-topic
         Region: cn-shanghai
+        NotifyContentFormat: JSON
+        NotifyStrategy: BACKOFF_RETRY
 ```
 
 #### TableStore
diff --git a/docs/specs/2018-04-03.md b/docs/specs/2018-04-03.md
index 1c2d444..19e5ac8 100644
--- a/docs/specs/2018-04-03.md
+++ b/docs/specs/2018-04-03.md
@@ -359,6 +359,9 @@ Property Name | Type | Description
 ---|:---:|---
 TopicName| `string` | **Required.** mns topicName
 Region   | `string` | **Optional.** Region of MNS topic, if not filled in, default is the same as the region of the function
+NotifyContentFormat   | `string` | **Optional.** notification event format, currently support STREAM and JSON， default is STREAM
+NotifyStrategy   | `string` | **Optional.** Retry strategy for invoking function, currently support BACKOFF_RETRY and EXPONENTIAL_DECAY_RETRY,  default is BACKOFF_RETRY,  details refer to [NotifyStrategy](https://help.aliyun.com/document_detail/27481.html)
+FilterTag   | `string` | **Optional.** Message filter tag in the created subscription (Only messages with consistent tags are pushed.), The value is a string of no more than 16 characters, default is no message filter. 
 
 ##### Example: MNSTopic event source object
 
@@ -368,6 +371,8 @@ mns-topic-trigger-test: # trigger name
     Properties:
         TopicName: test-topic
         Region: cn-shanghai
+        NotifyContentFormat: JSON
+        NotifyStrategy: BACKOFF_RETRY
 ```
 
 #### TableStore
diff --git a/examples/mnsTopic-trigger/template.yml b/examples/mnsTopic-trigger/template.yml
index 901c847..5d857aa 100644
--- a/examples/mnsTopic-trigger/template.yml
+++ b/examples/mnsTopic-trigger/template.yml
@@ -24,4 +24,7 @@ Resources:
           Type: MNSTopic
           Properties:
             TopicName: test-topic
+            NotifyContentFormat: JSON
+            NotifyStrategy: EXPONENTIAL_DECAY_RETRY
+            FilterTag : testTag
  
diff --git a/lib/deploy/deploy-support.js b/lib/deploy/deploy-support.js
index 45afd0f..08fd1c5 100644
--- a/lib/deploy/deploy-support.js
+++ b/lib/deploy/deploy-support.js
@@ -521,7 +521,24 @@ function getTriggerConfig(triggerType, triggerProperties) {
       concurrency: triggerProperties.Concurrency,
       eventFormat: triggerProperties.EventFormat
     };
-  } else if (triggerType === 'MNSTopic' || triggerType === 'TableStore') {
+  } else if (triggerType === 'MNSTopic') {
+    var notifyContentFormat = "STREAM";
+    if (triggerProperties.NotifyContentFormat !== undefined){
+      notifyContentFormat = triggerProperties.NotifyContentFormat;
+    }
+    var notifyStrategy = "BACKOFF_RETRY"
+    if (triggerProperties.NotifyStrategy !== undefined){
+      notifyStrategy = triggerProperties.NotifyStrategy;
+    }
+    var triggerCfg = {
+      NotifyContentFormat: notifyContentFormat,
+      NotifyStrategy: notifyStrategy,
+    }
+    if (triggerProperties.FilterTag !== undefined){
+      triggerCfg.FilterTag = triggerProperties.FilterTag;
+    }
+    return triggerCfg;
+  } else if (triggerType === 'TableStore') {
     return {};
   }
   console.error(`trigger type is ${triggerType} not supported.`);
diff --git a/lib/validate/schema/mnsTopic-event.js b/lib/validate/schema/mnsTopic-event.js
index 8c339ea..77f4e52 100644
--- a/lib/validate/schema/mnsTopic-event.js
+++ b/lib/validate/schema/mnsTopic-event.js
@@ -12,7 +12,21 @@ const MNSTopicEventSchema = {
       'type': 'object',
       'properties': {
         'TopicName': {
+          'type': 'string'
+        },
+        'Region': {
+          'type': 'string'
+        },
+        'NotifyContentFormat': {
           'type': 'string',
+          'enum': ['STREAM', 'JSON']
+        },
+        'NotifyStrategy': {
+          'type': 'string',
+          'enum': ['BACKOFF_RETRY', 'EXPONENTIAL_DECAY_RETRY']
+        },
+        'FilterTag': {
+          'type': 'string'
         },
       },
       'required': ['TopicName'],
diff --git a/package-lock.json b/package-lock.json
index 7ac6c4c..bc20972 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -147,7 +147,7 @@
     },
     "@sinonjs/formatio": {
       "version": "2.0.0",
-      "resolved": "http://registry.npmjs.org/@sinonjs/formatio/-/formatio-2.0.0.tgz",
+      "resolved": "https://registry.npmjs.org/@sinonjs/formatio/-/formatio-2.0.0.tgz",
       "integrity": "sha512-ls6CAMA6/5gG+O/IdsBcblvnd8qcO/l1TYoNeAzp3wcISOxlPXQEus0mLcdwazEkWjaBdaJ3TaxmNgCLWwvWzg==",
       "dev": true,
       "requires": {
@@ -617,7 +617,7 @@
     },
     "buffer": {
       "version": "4.9.1",
-      "resolved": "https://registry.npmjs.org/buffer/-/buffer-4.9.1.tgz",
+      "resolved": "http://registry.npmjs.org/buffer/-/buffer-4.9.1.tgz",
       "integrity": "sha1-bRu2AbB6TvztlwlBMgkwJ8lbwpg=",
       "requires": {
         "base64-js": "^1.0.2",
@@ -1981,7 +1981,7 @@
     },
     "git-ignore-parser": {
       "version": "0.0.2",
-      "resolved": "https://registry.npmjs.org/git-ignore-parser/-/git-ignore-parser-0.0.2.tgz",
+      "resolved": "http://registry.npm.taobao.org/git-ignore-parser/download/git-ignore-parser-0.0.2.tgz",
       "integrity": "sha1-fykXBKrv9mlvmHePzLJ2AbtzOTI="
     },
     "glob": {
@@ -2952,7 +2952,7 @@
     },
     "mkdirp": {
       "version": "0.5.1",
-      "resolved": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
+      "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
       "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
       "requires": {
         "minimist": "0.0.8"


Test patch:
diff --git a/test/deploy/deploy-by-tpl.test.js b/test/deploy/deploy-by-tpl.test.js
index 14c7041..b765e47 100644
--- a/test/deploy/deploy-by-tpl.test.js
+++ b/test/deploy/deploy-by-tpl.test.js
@@ -406,6 +406,9 @@ describe('deploy', () => {
       triggerType: 'MNSTopic',
       triggerProperties: {
         TopicName: 'test-topic',
+        NotifyContentFormat: 'JSON',
+        NotifyStrategy: 'EXPONENTIAL_DECAY_RETRY',
+        FilterTag : 'testTag'
       },
     });
   });