[英]"The request was aborted because there was no available instance" - Google Cloud Functions (PubSub trigger)
[英]How to return a JSON from Google Cloud functions using PUBSUB as trigger?
我使用Python pubsub客户端发布主题,并且有一个由pubsub消息触发的云功能设置。 我可以正确触发函数并生成所需的返回值,但我无法将该值返回给发布者/客户端。 感谢大家!
客户代码:
def call_getTime():
message_future = publisher.publish(topic_path,
data=data,
)
message_future.add_done_callback(callback)
print(message_future.result())
def callback(message_future):
if message_future.exception(timeout=30):
print('Publishing message threw an Exception {}.'.format(
message_future.exception()))
else:
print(message_future.result())
云功能:
def getTime(data, context):
r = {'time': time.time()}
return flask.jsonify(r)
Pubsub函数不会“返回”消息。 他们只是消费消息,他们通常不关心消息的来源。 这不是一种双向沟通方式。
如果您想要双向通信,请改用HTTP触发器。 您可以在HTTP响应的正文中发回消息。
如果由于某种原因无法使用HTTP并且必须坚持使用pubsub,请考虑将另一条消息发布到另一个主题,并安排发件人在该另一主题上接收该消息。 或使用某种webhook通知某人该消息已被处理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.