[英]Google Cloud PubSub throws 504 Deadline Exceeded error while listening for messages in asynchronous pull
I have a service that subscribes to a PubSub topic and uses the asynchronous pull.我有一个订阅 PubSub 主题并使用异步拉取的服务。 After an idle of 10 minutes and not receiving any messages, PubSub throws an 504 Deadline exceeded error.
在闲置 10 分钟且未收到任何消息后,PubSub 会引发 504 Deadline exceeded 错误。
Error always occurs after about 10 minutes.错误总是在大约 10 分钟后发生。 Every similar issue I found was related to synchronous pull, not the asynchronous pull I use.
我发现的每个类似问题都与同步拉动有关,而不是我使用的异步拉动。
Error message:错误信息:
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
Subscriber Class:订户 Class:
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
Listening for messages:收听消息:
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()
This is the normal behaviour and these messages can be ignored as your stream is getting re-established.这是正常行为,这些消息可以忽略,因为您的 stream 正在重新建立。 If in case of the stream is not getting re-established and heartbeat is not sent, then probably you need to upgrade your google core API and google cloud Pub/Sub to latest versions.
如果 stream 没有重新建立并且没有发送心跳,那么您可能需要将您的谷歌核心 API 和谷歌云 Pub/Sub 升级到最新版本。
pip install google-cloud-pubsub --upgrade
pip install google-api-core --upgrade
You can also filter these error messages as suggested in link https://github.com/googleapis/google-cloud-python/issues/5800您还可以按照链接https://github.com/googleapis/google-cloud-python/issues/5800中的建议过滤这些错误消息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.