问题
public final PullResponse pull(SubscriptionName subscription, boolean returnImmediately, int maxMessages)
According to the documentation:
@param returnImmediately If this field set to true, the system will respond immediately even if there are no messages available to return in the Pull
response. Otherwise, the system may wait (for a bounded amount of time) until at least one message is available, rather than returning no messages.
The client may cancel the request if it does not wish to wait any longer for the response.
I have a Thread that calls pull, with the returnImmediately flag set to false. If I interrupt() the thread there is a (roughly 60 second) delay before the pull request times out and I can check the interrupted flag status.
I don't see any way to pass an interrupt request to the call. Nor do I see a way to configure the "bounded amount of time". What am I missing?
回答1:
It looks like you may be using a fairly old version of the alpha Google Cloud Pub/Sub client library. In versions ≥ 0.11.0 (including the latest version, 0.17.1), the inconsistency no longer exists as the API has been altered such that you no longer need to worry about returnImmediately
.
来源:https://stackoverflow.com/questions/43744299/subscriberclient-pull-how-to-cancel-a-request