我有一个订阅PubSub主题并使用异步请求的服务。闲置10分钟且未收到任何消息后,PubSub抛出504超过期限错误。
总是在大约10分钟后发生错误。我发现的每个类似问题都与同步请求有关,而不与我使用的异步请求有关。
错误信息:
INFO:google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager:Observed non-terminating stream error 504 Deadline Exceeded
INFO:google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager:Observed recoverable stream error 504 Deadline Exceeded
INFO:google.api_core.bidi:Re-established stream
INFO:google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager:Observed non-terminating stream error 504 Deadline Exceeded
INFO:google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager:Observed recoverable stream error 504 Deadline Exceeded
订户类别:
from google.cloud import pubsub_v1
class Subscriber():
def __init__(self):
self.subscriber = pubsub_v1.SubscriberClient()
self.project_id = "my-project-id"
self.subscription_id = "SUBSCRIPTION_MAIL_RECIEVE"
self.subscription_path = self.subscriber.subscription_path(self.project_id,
self.subscription_id)
def subscribe(self, callback):
"""
Parameters:
callback (callable): function to be called for incoming messages on given topic
"""
streaming_pull_future = self.subscriber.subscribe(self.subscription_path,
callback=callback)
return streaming_pull_future
收听消息:
subscriber = Subscriber()
pull_future = subscriber.subscribe(my_callback_function(message))
with subscriber.subscriber:
try:
print("Waiting for messages")
pull_future.result()
except TimeoutError:
pull_future.cancel()
这是正常现象,在重新建立流时可以忽略这些消息。如果无法重新建立流并且未发送心跳,则可能需要将google core API和google cloud Pub / Sub升级到最新版本。
pip install google-cloud-pubsub --upgrade
pip install google-api-core --upgrade
您还可以按照链接https://github.com/googleapis/google-cloud-python/issues/5800中的建议过滤这些错误消息
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句