Google Pub/Sub订阅者过一会儿未收到消息 [英] Google Pub/Sub Subscriber not receiving messages after a while

查看:124
本文介绍了Google Pub/Sub订阅者过一会儿未收到消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Python脚本,该脚本使用Google pubsub来检测Google云存储中的新文件.该脚本只是将新消息添加到队列中,另一个线程在该队列中处理这些消息:

I have a simple python script that uses Google pubsub to detect new files in the google cloud storage. The script simply adds new messages to a queue where another thread processes those messages:

subscriber = pubsub.SubscriberClient()
subscription_path = subscriber.subscription_path(
    project, subscription_name)

subscriber.subscribe(subscription_path, callback=callback_fun)

while True:
    if not message_queue:
        time.sleep(60)
        continue
    else:
        process_next_message(message_queue.pop())

在这里,callback_fun只是将消息添加到队列中:

Here, callback_fun simply adds the message to the queue:

def callback_fun(message):
    message.ack()
    message_queue.append(message)

我遇到的问题是一段时间(也许是几天)之后,订户停止接收新文件通知.如果我停止并重新启动脚本,它将立即获取所有通知.

The problem I am having is that after a while (maybe a couple of days), the subscriber stops receiving new file notifications. If I stop and restart the script, it gets all of the notifications at once.

我想知道是否还有其他人遇到类似的问题和/或可以提出解决问题的方法(可能是通过打印通常看不见的调试消息).我现在正在尝试停止/重新启动订户,但是我确信这不是在生产环境中使用的最佳方法.

I was wondering if anyone else is having similar issues and/or can suggest ways to troubleshoot (maybe by printing debugging messages that are normally unseen). I am now trying to stop/restart the subscriber, but I am sure that this is not the best idea for using in a production environment.

我正在使用google-cloud 0.32.0和google-cloud-pubsub 0.30.1.

I am using google-cloud 0.32.0 and google-cloud-pubsub 0.30.1.

谢谢.

推荐答案

通常,订户可能停止接收消息的原因可能有多种:

In general, there can be several reasons why a subscriber may stop receiving messages:

  1. 如果订户不确认或拒绝消息,则可以达到流控制限制,这意味着无法再传递消息.考虑到您立即确认消息,在您的特定实例中似乎情况并非如此.顺便说一句,我建议您不要在队列处理完消息之前先对消息进行确认,除非您可以确定消息是否会被处理.否则,如果您的应用程序在确认后崩溃,但是在消息队列处理它们之前,您将没有处理该消息,并且由于被确认而无法重新发送该消息.
  2. 如果另一个订户启动了相同的订阅,则它可能正在接收消息.在这种情况下,人们希望订户接收到一部分消息,而不是根本没有消息.
  3. 发布者只是停止发布消息,因此没有要接收的消息.如果重新启动订阅服务器,并且订阅服务器再次开始接收消息,则可能不是这种情况.您还可以通过查看subscription/backlog_bytes的Stackdriver指标来验证是否积压了工作.

如果您的问题不属于上述类别之一,则最好与您的项目名称,主题名称和订阅名称联系以获得Google Cloud支持,以便他们可以将问题缩小到您的用户代码中,客户端库或服务.

If your problem does not fall into one of those categories, it would be best to reach out to Google Cloud support with your project name, topic name, and subscription name so that they can narrow down the issue to either your user code, the client library, or the service.

这篇关于Google Pub/Sub订阅者过一会儿未收到消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆