-
Notifications
You must be signed in to change notification settings - Fork 373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(pubsub): blocking pulls #10317
feat(pubsub): blocking pulls #10317
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2020 Google LLC | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_PULL_RESPONSE_H | ||
#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_PULL_RESPONSE_H | ||
|
||
#include "google/cloud/pubsub/message.h" | ||
#include "google/cloud/pubsub/pull_ack_handler.h" | ||
#include "google/cloud/pubsub/version.h" | ||
|
||
namespace google { | ||
namespace cloud { | ||
namespace pubsub { | ||
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN | ||
|
||
/** | ||
* The response for a blocking pull. | ||
* | ||
* If the application invokes `handler.nack()` or allows `handler` to go out | ||
* of scope, then the service will redeliver the message. | ||
* | ||
* With exactly-once delivery subscriptions, the service will stop | ||
* redelivering the message once the application invokes `handler.ack()` and | ||
* the invocation succeeds. With best-efforts subscriptions, the service *may* | ||
* redeliver the message, even after a successful `handler.ack()` invocation. | ||
* | ||
* If `handler` is not an rvalue, you may need to use `std::move(ack).ack()` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/std::move(ack)/std::move(handler)/ ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
* or `std::move(handler).nack()`. | ||
* | ||
* @see https://cloud.google.com/pubsub/docs/exactly-once-delivery | ||
*/ | ||
struct PullResponse { | ||
/// The ack/nack handler associated with this message. | ||
pubsub::PullAckHandler handler; | ||
/// The message attributes and payload. | ||
pubsub::Message message; | ||
}; | ||
|
||
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END | ||
} // namespace pubsub | ||
} // namespace cloud | ||
} // namespace google | ||
|
||
#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_PULL_RESPONSE_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,6 +157,30 @@ class Subscriber { | |
future<Status> Subscribe(ExactlyOnceApplicationCallback cb, | ||
Options opts = {}); | ||
|
||
/** | ||
* Pulls one message from @p subscription. | ||
* | ||
* @par Idempotency | ||
* @parblock | ||
* This is an idempotent operation; it only reads messages from the service. | ||
* Will make multiple attempts to pull a message from the service, subject | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/Will/It will/ ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
* to the retry policies configured in the `SubscriberConnection`. | ||
* | ||
* Note that calling `PullAckHandler::ack()` and/or `PullAckHandler::nack()` | ||
* have their own rules with respect to retrying. | ||
* @endparblock | ||
* | ||
* @par Example | ||
* @snippet samples.cc pull | ||
* | ||
* @param opts any option overrides to use in this call. These options take | ||
* precedence over the options passed in the constructor, and over any | ||
* options provided in the `PublisherConnection` initialization. | ||
* @return a response including the message and a `PullAckHandler` to notify | ||
* the library when the message has been successfully handled. | ||
*/ | ||
StatusOr<PullResponse> Pull(Options opts = {}); | ||
|
||
private: | ||
std::shared_ptr<SubscriberConnection> connection_; | ||
google::cloud::Options options_; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we do 2*N iterations for an exactly-once subscription?
Is it to make sure everything gets acked, in the failure case where we
continue
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. For low values of "make sure".