Cloud Run/Cloud Run Functions集成Cloud Pub/Sub时出现grpc超时警告及构建错误的求助
Cloud Run/Cloud Run Functions集成Cloud Pub/Sub时出现grpc超时警告及构建错误的求助
我正在开发一个简单的Web应用,它接收HTTP POST请求并触发Cloud Pub/Sub事件。在没有集成Pub/Sub的时候,应用部署完全正常,我也能正常访问端点。
我分别通过Cloud Run Functions控制台和Cloud Run控制台部署过示例函数,两种方式都能正常部署默认的Hello World示例,没有任何问题。
现在我要添加Pub/Sub功能,做了这些操作:
- 在requirements.txt里添加了
google-cloud-pubsub依赖 - 在代码中引入了Pub/Sub客户端
- 通过控制台创建了Pub/Sub主题
现在我的代码是这样的:
import json import os import functions_framework from google.cloud import pubsub_v1 PROJECT_ID = "my project" publisher = pubsub_v1.PublisherClient() @functions_framework.http def hello_http(request): """HTTP Cloud Function. Args: request (flask.Request): The request object. <https://flask.palletsprojects.com/en/1.1.x/api/#incoming-request-data> Returns: The response text, or any set of values that can be turned into a Response object using `make_response` <https://flask.palletsprojects.com/en/1.1.x/api/#flask.make_response>. """ request_json = request.get_json(silent=True) request_args = request.args topic_name = 'projects/{project_id}/topics/{topic}'.format( project_id=PROJECT_ID, topic='test-topic', ) message = { 'key': 'value', 'info': 'This is a test message' } future = publisher.publish(topic_name, json.dumps(message).encode("utf-8")) future.result() if request_json and 'name' in request_json: name = request_json['name'] elif request_args and 'name' in request_args: name = request_args['name'] else: name = 'World' return 'Hello {}!'.format(name)
现在我在控制台里总会看到这些警告,想知道这是什么意思:
WARNING: All log messages before absl::InitializeLog() is called are written to STDERR E0000 00:00:1734272617.454893 1 init.cc:229] grpc_wait_for_shutdown_with_timeout() timed out.
另外,在Google Cloud Run测试控制台里还会出现一些看起来和构建相关的奇怪错误,有时候报错有时候又不报错,比如:
[9:47:15 PM] - Preparing function sources ... [9:47:15 PM] - Loading new function sources ... [9:47:22 PM] - Starting function... [9:47:22 PM] - WARNING: All log messages before absl::InitializeLog() is called are written to STDERR E0000 00:00:1734144439.303879 20 init.cc:229] grpc_wait_for_shutdown_with_timeout() timed out. WARNING: All log messages before absl::InitializeLog() is called are written to STDERR E0000 00:00:1734144441.495104 7 init.cc:229] grpc_wait_for_shutdown_with_timeout() timed out. /bin/sh: 2c3d685a15e9: not found /bin/sh: 2c3d685a15e9: not found
有没有人遇到过类似的问题,能帮我解释下这些警告和错误的原因,以及怎么解决吗?
备注:内容来源于stack exchange,提问作者Peter
相关产品推荐
相关产品推荐

