完成MNS主题触发器创建后,您可以开始写入函数代码。本文介绍如何使用函数计算控制台编写函数。
前提条件
编写函数代码(Python)
event格式说明
发布在MNS Topic上的消息根据notifyContentFormat进行处理,即入口函数的event。更多信息,请参见NotifyContentFormat。
- 创建触发器时,若Event格式设置为STREAM。
-
当消息中不含消息属性(MessageAttributes)时,Event格式如下。
说明 当消息中不含消息属性(MessageAttributes)时,Event的内容格式为JSON字符串。# 消息正文。 'hello topic'
-
当消息中含有消息属性(MessageAttributes)时,Event格式如下。
说明 Event的内容中包含MessageAttributes相关的键值对。更多信息,请参见
PublishMessage。{ "body": "hello topic", "attrs": { "Extend": "{\\"key\\":\\"value\\"}" } }
-
- 创建触发器时,若event格式设置为JSON。
-
当消息中不含消息属性(MessageAttributes)时,Event格式如下。
{ "TopicOwner": "118620210433****", "Message": "hello topic", "Subscriber": "118620210433****", "PublishTime": 1550216480040, "SubscriptionName": "test-fc-subscibe", "MessageMD5": "BA4BA9B48AC81F0F9C66F6C909C3****", "TopicName": "test-topic", "MessageId": "2F5B3C082B923D4EAC694B76D928****" }
-
当消息中含有消息属性(MessageAttributes)时,Event格式如下。
说明 Event的内容中包含MessageAttributes相关的键值对。更多信息,请参见
PublishMessage。{ "key": "value", "TopicOwner": "118620210433****", "Message": "hello topic", "Subscriber": "118620210433****", "PublishTime": 1550216302888, "SubscriptionName": "test-fc-subscibe", "MessageMD5": "BA4BA9B48AC81F0F9C66F6C909C3****", "TopicName": "test-topic", "MessageId": "2F5B3C281B283D4EAC694B742528****" }
-