go - Go pub 子库中 PullWait 的行为?

标签 go google-cloud-platform google-cloud-pubsub

我目前正在试验 Google Cloud PubSub 的 go library并同时查阅文档。

我的代码测试了 PullWait 函数的行为,根据 documentation执行以下操作:

PullWait pulls messages from the subscription. If there are not enough messages left in the subscription queue, it will block until at least n number of messages arrive or timeout occurs, and n could not be larger than 100.

但是,我的测试表明,无论 n 指定的值如何,我总是会立即收到 m 消息,其中 m <= n。我在这里错过了什么吗?

使用的代码摘录:

msgs, err := pubsub.PullWait(subCtx, subscriptionName, 50)
if err != nil {
    log.Printf("Error when trying to pull messages from subscription: %v", err)
} else {
    for _, msg := range msgs {
        str := string(msg.Data)
        log.Printf("Message [msg-id=%s]: '%v'", msg.ID, str)

        if err := pubsub.Ack(ctx, subscriptionName, msg.AckID); err != nil {
            log.Printf("Unable to acknowledge message [ack-id=%s]: %v", msg.AckID, err)
        }
    }
}

当时队列中只有一条消息,立即返回给我:

2015/11/04 11:45:15 Message [msg-id=2384294654226]: 'hello world my friend'

最佳答案

事实证明文档不正确。 PullWait 调用底层 pull method returnImmediately 设置为 false,这意味着它等待接收至少一条消息(但不超过 n 条消息)。我已提交更正请求。

关于go - Go pub 子库中 PullWait 的行为?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33521546/

相关文章:

Golang os.使用嵌套目录创建路径

具有消息排序功能的 Firebase PubSub 触发器

machine-learning - ML 训练过程不在 GPU 上

python - 在 GCP Composer 上创建 Airflow DAG

google-cloud-platform - 使用推送订阅作为负载均衡器的细节

google-cloud-pubsub - Cloud Pub/Sub 可用于特定区域。这是什么意思?请确认

go - c.JSON gin.H{()} 输出空对象

go - 构建命令行参数 : cannot load go-sql-driver/mysql

go - golang报错函数如何获取编译信息

docker - 如何在 GKE Ingress-gce 上将 HTTPS 设置为默认值