2

Using gcloud-java pubsub API 0.2.6 - how can I set "Return Immediately" flag to TRUE with the subscription pull?

Evgeny Minkevich
  • 2,319
  • 3
  • 28
  • 42

2 Answers2

2

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.

Kamal Aboul-Hosn
  • 15,111
  • 1
  • 34
  • 46
  • That would result in considerable cost overhead if there is a situation where there is not messages for extended period of time. Hopefully it is back to default (false) for GA. – Evgeny Minkevich Jul 28 '16 at 21:25
  • This answer is inaccurate. `MessageConsumer pullAsync(String subscription, MessageProcessor callback, PullOption... options)` sets the "return immediately" flag to false by default. – mziccard Aug 22 '16 at 17:55
0

(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();
mziccard
  • 2,158
  • 9
  • 17