2016-07-28 23 views

回答

1

默認情況下,gcloud-java pubsub API中的「立即返回」標誌設置爲true以進行拉式調用。目前沒有辦法設置標誌,儘管該特定的庫位於alpha中,因此可能會改變。

+0

如果存在長時間沒有消息的情況,這會導致相當大的成本開銷。希望它恢復爲GA的默認(錯誤)。 –

+0

此答案不正確。 'MessageConsumer pullAsync(String subscription,MessageProcessor callback,PullOption ... options)'默認設置「立即返回」標誌爲false。 – mziccard

0

(警告:我是gcloud-java團隊的一部分)

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); 

前兩種方法都默認設置「立即返回」標誌設置爲true 。

相反,最後一個代表用戶處理連續提取的方法始終將「立即返回」標誌設置爲false。一個使用示例可能如下

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();