Google pubsub golang订户闲置了几个小时后停止接收新发布的消息 [英] Google pubsub golang subscriber stops receiving new published message(s) after being idle for a few hours

查看:217
本文介绍了Google pubsub golang订户闲置了几个小时后停止接收新发布的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在google pubsub中创建了一个主题,并在主题中创建了SUBSCRIPTION,并进行了以下设置

I created a TOPIC in google pubsub, and created a SUBSCRIPTION inside the TOPIC, with the following settings

然后我用它的 puller in go ="https://godoc.org/cloud.google.com/go/pubsub#hdr-Receiving" rel ="nofollow noreferrer">接收以提取并确认已发布的消息

then I wrote a puller in go, using its Receive to pull and acknowledge published messages

package main

import (
    ...
)

func main() {
    ctx := context.Background()

    client, err := pubsub.NewClient(ctx, config.C.Project)
    if err != nil {
       // do things with err
    }
    sub := client.Subscription(config.C.PubsubSubscription)
    err := sub.Receive(ctx, func(ctx context.Context, msg *pubsub.Message) {
        msg.Ack()
    })

    if err != context.Canceled {
      logger.Error(fmt.Sprintf("Cancelled: %s", err.Error()))
    }
    if err != nil {
      logger.Error(fmt.Sprintf("Error: %s", err.Error()))
    }
  }

没什么花哨的,它运作良好,但是过了一会儿(闲置3个小时后,〜),它停止接收新发布的消息,没有错误,什么也没有.我想念什么吗?

Nothing fancy, its working well, but then after a while (~ after 3 hours idle), it stops receiving new published messages, no error(s), nothing. Am i missing something?

推荐答案

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

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

  1. 如果订户不确认或拒绝消息,则可以达到流控制限制,这意味着无法再传递消息.考虑到您立即确认消息,在您的特定情况下情况似乎并非如此.
  2. 如果另一个订户启动了相同的订阅,则它可能正在接收消息.在这种情况下,人们希望订户接收到一部分消息,而不是根本没有消息.
  3. 发布者只是停止发布消息,因此没有要接收的消息.如果重新启动订阅服务器,并且订阅服务器再次开始接收消息,则可能不是这种情况.您还可以通过查看 Stackdriver指标表示subscription/backlog_bytes.
  1. If a subscriber does not ack or nack messages, the flow control limits can be reached, meaning no more messages can be delivered. This does not seem to be the case in your particular instance given that you immediately ack messages.
  2. If another subscriber starts up for the same subscription, it could be receiving the messages. In this scenario, one would expect the subscriber to receive a subset of the messages rather than no messages at all.
  3. Publishers just stop publishing messages and therefore there are no messages to receive. If you restart the subscriber and it starts receiving messages again, this probably isn't the case. You can also verify that a backlog is being built up by looking at the Stackdriver metric for subscription/backlog_bytes.

如果您的问题不属于上述类别之一,则最好与您的项目名称,主题名称和订阅名称联系以获得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 itself, or the service.

这篇关于Google pubsub golang订户闲置了几个小时后停止接收新发布的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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