google pub-sub setMaxMessages [英] google pub-sub setMaxMessages
问题描述
我正在使用google pubsub同步获取消息
com.google.pubsub.v1.PullRequest.Builder pullRequestBuilder = PullRequest.newBuilder().setSubscription(subscriptionName).setReturnImmediately(returnImmediately);
if (maxMessages != 0) {
pullRequestBuilder.setMaxMessages(maxMessages);
}
PullRequest pullRequest = pullRequestBuilder.build();
PullResponse pullResponse = (PullResponse)this.subscriber.pullCallable().call(pullRequest);
return pullResponse.getReceivedMessagesList();
我在文档中看到:
setMaxMessages
public PullRequest setMaxMessages(java.lang.Integer maxMessages)
The maximum number of messages returned for this request. The Pub/Sub system may return fewer than the number specified.
Parameters:
maxMessages - maxMessages or null for none
在我的代码中,我传递MAX_INT以避免任何最大消息限制
但是我看到我的Java代码一一读取消息.
跳过最大限制的正确方法是什么?
我怎么知道这不只是发布订阅错误?
即使pubsub中有一些消息,我有时也会收到0条消息.
在使用同步pull方法时,设置maxMessages
字段不能保证您会收到很多消息,即使该数量更多也是如此.可用的.消息的端到端延迟与单个响应中返回的消息数之间需要权衡.如果服务等待直到可以发送maxMessages
,则缓冲并等待的消息将具有更高的端到端延迟.</p>
单个响应中最多可以返回1000条消息,而不管其上设置的maxMessages
有多高.如果要使您的响应更有可能包含更多消息,请确保将returnImmediately
设置为false.如果此字段为true,则服务将尝试尽可能快地返回,这意味着它可能不等待消息加载再返回.这很可能是您在某些响应中看到0条消息返回的原因.
如果您要最大程度地提高吞吐量,则需要使用 StreamingPull 一个>甚至更好的 Cloud Pub/Sub客户端库 ,在后台使用StreamingPull.这样一来,邮件就可以在可用时立即将其传递到开放的流式传输连接.
I'm using google pubsub to fetch messages synchronously
com.google.pubsub.v1.PullRequest.Builder pullRequestBuilder = PullRequest.newBuilder().setSubscription(subscriptionName).setReturnImmediately(returnImmediately);
if (maxMessages != 0) {
pullRequestBuilder.setMaxMessages(maxMessages);
}
PullRequest pullRequest = pullRequestBuilder.build();
PullResponse pullResponse = (PullResponse)this.subscriber.pullCallable().call(pullRequest);
return pullResponse.getReceivedMessagesList();
I saw in the documentation:
setMaxMessages
public PullRequest setMaxMessages(java.lang.Integer maxMessages)
The maximum number of messages returned for this request. The Pub/Sub system may return fewer than the number specified.
Parameters:
maxMessages - maxMessages or null for none
In my code I pass MAX_INT to avoid any max messages limitation
but I see my java code fetches messages one by one.
What is the right way to skip the max limit?
How can I know it's not just a pub-sub bug?
I sometimes get 0 messages even though there are some in the pubsub.
When you are using the synchronous pull method, setting the maxMessages
field does not guarantee you will receive that many messages, even if there are more than that number available. There is a tradeoff between end-to-end latency of messages and number of messages returned in a single response. If the service waits until maxMessages
are available to be sent, then the messages that are buffered and waiting will have a higher end-to-end latency.
The maximum number of messages that can be returned in a single response is 1,000, regardless of how high maxMessages
is set above that. If you want to make it more likely that your response will contain more messages, make sure you set returnImmediately
to false. If this field is true, then the service attempts to return as quickly as it possibly can, meaning it may not wait for messages to be loaded before returning. This is likely why you see 0 messages being returned in some responses.
If you are trying to maximize throughput, you'll want to use StreamingPull, or even better, the Cloud Pub/Sub client libraries, which use StreamingPull under the hood. That way, messages can be deliver messages to an open streaming connection as soon as they are available.
这篇关于google pub-sub setMaxMessages的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!