Google pubsub流控制 [英] Google pubsub flow control
问题描述
我正在尝试实施一项以自己的进度使用google pubsub订阅的服务.通过这种方式,我的意思是我需要对何时需要使用消息进行精细控制,即获取一批消息,暂停一会儿,收到的消息不超过X条...
I'm trying to implement a service which consumes a google pubsub subscription at its own pace. By that, I mean I need fine control on when I need to consume messages i.e get a batch of messages, pause for a while, do not get more than X messages...
使用Google客户端库时,由于MessageReceiver在其自己的线程中运行,因此我没有找到实现此目的的方法,而且我无法控制到底发生了什么.
Using google client libraries I did not find a way to do it as the MessageReceiver is running in its own thread and I don't have any control on what exactly happens.
基本上,能够以同步方式使用消息应该可以解决我的问题.
Basically, being able to consume messages in a synchronous way should solve my issue.
您知道我如何同步使用Google客户端库吗?还是我错过了API中的另一种方法?
Do you know how I can use the google client libs synchronously ? Or is there another way in the API I missed ?
推荐答案
您可以尝试使用 setMaxOutstandingElementCount
或
You might try using setFlowControlSettings
when you build your subscriber. In particular, you can use setMaxOutstandingElementCount
or setMaxOutstandingRequestBytes
to limit the messages sent to your MessageReceiver. When you have enough messages outstanding, i.e., messages for which you have not called Ack()
or Nack()
, to exceed these limits, then your MessageReceiver will not be called until messages have been acked or nacked.
这篇关于Google pubsub流控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!