简体   繁体   English

gcloud-java pubsub API:如何设置“立即返回”标志

[英]gcloud-java pubsub API : how to set “Return Immediately” flag

使用gcloud-java pubsub API 0.2.6-如何通过订阅请求将“立即返回”标志设置为TRUE?

The "return immediately" flag is set to true by default in the gcloud-java pubsub API for pull calls. 在gcloud-java pubsub API中,默认情况下,“立即返回”标志设置为true,用于拉取调用。 There is no way to set the flag at this time, though that particular library is in alpha, so that may change. 尽管该特定库位于alpha中,但目前无法设置该标志,因此可能会更改。

(Caveat: I am part of the gcloud-java team) (注意:我是gcloud-java团队的一员)

gcloud-java provides three ways of pulling messages: gcloud-java提供了三种提取消息的方式:

Future<Iterator<ReceivedMessage>> pullAsync(String subscription, int maxMessages);

Iterator<ReceivedMessage> pull(String subscription, int maxMessages);

MessageConsumer pullAsync(String subscription, MessageProcessor callback, PullOption... options);

The first two methods do set the "return immediately" flag to true by default. 默认情况下,前两种方法确实将“立即返回”标志设置为true。

On the contrary, the last method, which handles continuous pulling on behalf of the user, always sets the "return immediately" flag to false. 相反,代表用户处理连续拉动的最后一种方法始终将“立即返回”标志设置为false。 A usage example could be the following 用法示例如下

MessageProcessor messageProcessor = new MessageProcessor() {

  @Override
  public void process(Message message) throws Exception {
    // handle message
  }
};

MessageConsumer consumer = pubsub.pullAsync(subscription, messageProcessor);

// close the consumer to stop pulling
consumer.close();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM