4
我目前正在试用Google Cloud PubSub的go library并同时查阅文档。Go酒吧子库中的PullWait行为?
我的代码测试PullWait
函数,根据documentation做以下行为:
PullWait从订阅拉消息。如果订阅队列中没有足够的消息,它将会阻塞,直到至少n条消息到达或发生超时,并且n不能大于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)
}
}
}
,并在时间队列只包含一个消息,该消息被rightaway返回到我:
2015年11月4日11点45分十五秒消息[msg-id = 2384294654226]:'你好我的世界我的朋友'