简体   繁体   English

Google Cloud PubSub 在异步拉取消息时抛出 504 Deadline Exceeded 错误

[英]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.

相关问题 Python Google Cloud Firestore 错误 504 Deadline Exceeded - Python Google cloud firestore error 504 Deadline Exceeded 在Google App Engine中使用urllib2会引发“在等待来自URL的HTTP响应时超出了期限:…” - Use of urllib2 in Google App Engine throws “Deadline exceeded while waiting for HTTP response from URL:…” Python GAE-调用Big Query API会引发超过最后期限的错误 - Python GAE - Call to Big Query API throws Deadline exceeded error 未通过回调处理的Google Cloud PubSub消息 - Google Cloud PubSub messages not processed by callback 将BQ查询结果下载到Python dataframe时出现504 Deadline Exceeded错误 - 504 Deadline Exceeded error when downloading BQ query results to Python dataframe Google Cloud PubSub:不发送/接收来自 Cloud Functions 的所有消息 - Google Cloud PubSub: Not sending/receiving all messages from Cloud Functions 用于发布订阅异步拉取的 Python 单元测试 - Python unittest for pubsub asynchronous pull 使用大查询在 Jupiter Notebook(Python)中超过 504 个截止日期 - Got 504 Deadline Exceeded in Jupiter Notebook (Python) with Big query 504 当我尝试获取信息时已超过截止日期 - 504 Deadline Exceeded when I try to get information 我使用 ReadFromSpanner 在 Apache Beam 中收到 504 Deadline Exceeded - I get 504 Deadline Exceeded in Apache Beam using ReadFromSpanner
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM