简体   繁体   中英

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. There is no way to set the flag at this time, though that particular library is in alpha, so that may change.

(Caveat: I am part of the gcloud-java team)

gcloud-java provides three ways of pulling messages:

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.

On the contrary, the last method, which handles continuous pulling on behalf of the user, always sets the "return immediately" flag to 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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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