【问题标题】:How to fetch the number of unacknowledged messages in a Pub/Sub Subscription via the Google Cloud Monitoring JAVA Client Library如何通过 Google Cloud Monitoring JAVA 客户端库获取 Pub/Sub 订阅中未确认消息的数量
【发布时间】:2021-01-11 07:35:33
【问题描述】:

我在创建的 Pub/Sub 订阅上有一个编号,它没有附加消费者,并且可以存储长达 7 天的消息。这是因为理想情况下,这些 Pub/Sub 中的消息数量不应超过某个阈值。我想从我的应用程序中定期监视这些 Pub/Sub,然后在数量超过阈值的极少数情况下处理消息。如果没有,即使设置相同的警报也会有所帮助。

我知道我可以从 Google Cloud Console 为订阅设置 Cloud Monitoring 并创建信息中心/警报。有没有办法通过 JAVA 客户端库 (Google Cloud Monitoring Link to Documentation) 以编程方式执行此操作?由于没有很多可用的代码示例,我觉得很难。

TLDR:如何在我的代码中使用 google-cloud-monitoring JAVA 客户端库获取 Pub/Sub 订阅中未确认消息的数量

【问题讨论】:

    标签: java google-cloud-platform google-cloud-pubsub google-cloud-monitoring


    【解决方案1】:

    您可以使用listTimeSeries方法获取数据。

    【讨论】:

      【解决方案2】:

      您可以使用 MetricServiceClient.ListTimeSeriesRequest 以编程方式读取这些指标(例如 subscription/num_undelivered_messages)。 Cloud Monitoring 文档页面包含有关如何初始化客户端库的一般示例:https://cloud.google.com/monitoring/docs/reference/libraries#using_the_client_library

      【讨论】:

        猜你喜欢
        • 2021-12-12
        • 2022-07-27
        • 2021-12-12
        • 2018-04-11
        • 2019-08-09
        • 2021-12-10
        • 2019-04-10
        • 2020-02-02
        • 2019-07-27
        相关资源
        最近更新 更多