dongqiang4819 2018-04-11 18:46
浏览 39
已采纳

从GCP发布/订阅中捕获错误代码

I am using go package for pub/sub. On my API dashboard I see this error(google.pubsub.v1.Subscriber.StreamingPull - error code 503). Per docs(https://cloud.google.com/pubsub/docs/reference/error-codes) it seems it is transient condition but better to implement backoff strategy(https://cloud.google.com/storage/docs/exponential-backoff). the question is I am not able to wrap my head where this error code is coming on Receive method.

Here is func:

err = sub.Receive(ctx, func(ctx context.Context, m *pubsub.Message) {
        // Dump message
        // log.Printf("Got message: %s", m.Data)

        // Decoding coming message
        err = json.NewDecoder(bytes.NewReader(m.Data)).Decode(&msg)
        if err != nil {
            log.Printf("Error decoding - %v", err)
        }

        // See streaming messages
        log.Printf(" %s : %s : Product updated for Product Id(%d) : Product Title(%s)",
            msg.AuthID,
            msg.TraceID,
            msg.Product.ID,
            msg.Product.Title,
        )

        //
        // Some business logic
        //


        // Acknowledge on recieve method
        m.Ack()
    })

    if err != context.Canceled {
        // if err != nil {
        return errors.Wrap(err, "Error occurred on recieve data from topic: blah")
    }
  • 写回答

1条回答 默认 最新

  • doujupa7567 2018-04-11 20:12
    关注

    The Cloud Pub/Sub Go client library will retry this transient error on its own, you shouldn't need to handle it. Internally, the client library uses StreamingPull, where it sends a request and receives messages from the service as they are available. Occasionally, there can be a disconnection event requiring the connection to be reestablished. This is why you see the 503 error in the API dashboard. It should not be the case that your code sees an error in this scenario since the underlying library is handling it (including the use of exponential backoff, where relevant).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置