【发布时间】:2020-05-07 14:52:35
【问题描述】:
我一直在使用 Google Cloud PubSub 来触发 Google Cloud Functions。到目前为止,我一直在使用单个参数“uuid”,现在我还需要发送开发/生产标志。
以下是 Google App Engine/Django 中的发布者:
publisher = pubsub_v1.PublisherClient()
topic_name = 'projects/project/topics/cloudfunction_topic'
message_to_publish = video.uuid
publisher.publish(topic_name, data=message_to_publish.encode('utf-8'), spam='')
下面是 GCF 中的订阅者部分:
if os.getenv('GCF', None):
uuid = base64.b64decode(event['data']).decode('utf-8')
我应该如何更改此设置,以便消息中可以有多个参数(video.uuid、生产/开发)?
【问题讨论】:
-
尝试将数据字典序列化为 JSON。这可以是您消息的有效负载。
标签: python django google-cloud-platform google-cloud-functions google-cloud-pubsub