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).

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

报告相同问题?

悬赏问题

  • ¥18 模拟电路问题解答有偿
  • ¥15 Matlab在app上输入带有矩阵形式的初始条件发生错误
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题