douhuan1380
douhuan1380
2019-04-04 05:16
浏览 132
已采纳

Google pubsub golang订户闲置了几个小时后停止接收新发布的消息

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

enter image description here

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()))
    }
  }

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?

图片转代码服务由CSDN问答提供 功能建议

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

”在此处输入图片描述“

然后我写了拉动,使用其接收以提取并确认已发布的消息

 程序包main 
 
import(
 ... 
)
  
func main(){
 ctx:= context.Background()
 
 client,err:= pubsub.NewClient(ctx,config.C.Project)
 if err!= nil {
 // 错误的内容
} 
 sub:= client.Subscription(config.C.PubsubSubscription)
 err:= sub.Receive(ctx,func(ctx context.Context,msg * pubsub.Message){
 msg。 确认()
  })
 
如果错误!=上下文。取消{
 logger.Error(fmt.Sprintf(“ Cancelled:%s”,err.Error()))
} 
如果错误!= nil {\  n logger.Error(fmt.Sprintf(“ Error:%s”,err.Error()))
} 
} 
   
 
 

没什么好看的 工作正常,但过了一会儿(在闲置3个小时后〜),它停止接收新发布的消息,没有错误,没有任何反应。 我想念什么吗?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • doumi1099
    doumi1099 2019-04-04 14:13
    已采纳

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

    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.

    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.

    点赞 评论
  • douweida2669
    douweida2669 2019-04-04 09:27

    Few changes will help you to investigate the issue better: - Check error from Receive - Use separate context for Receive

    ctx := context.Background()
    err := sub.Receive(ctx, func(ctx context.Context, msg *pubsub.Message) {
        msg.Ack()
    })
    if err != nil {
        log.Fatal(err)
    }
    
    点赞 评论
  • dongxiong5546
    dongxiong5546 2019-04-04 11:38

    Does your code work before? I have problems with PubSub since today. Methods like get_topic(), create_topic() in Python PubSub library stop working, but I don't have any problems with sending and pulling messages. Yesterday everything was working fine but today not...

    点赞 评论
  • duanqian2368
    duanqian2368 2019-04-26 11:13

    I was experiencing something similar and I was pretty sure there was not another subscriber pulling those messages.

    Try this: go to the topic, create a new bogus subscription (name it whatever you want, because you'll just delete it later). Right after I did that both the fake subscription (which I was using the python sample code client to subscribe to) and the real one was receiving messages again. Strange solution, but maybe it kicked the topic awake again.

    Hopefully someone from Google could give us some insight into what's happening here, but I'm definitely not paying them enough to get direct support.

    点赞 评论

相关推荐