15#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_SUBSCRIPTION_BUILDER_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_SUBSCRIPTION_BUILDER_H
18#include "google/cloud/pubsub/subscription.h"
19#include "google/cloud/pubsub/topic.h"
20#include "google/cloud/pubsub/version.h"
21#include "google/cloud/internal/time_utils.h"
22#include <google/protobuf/util/field_mask_util.h>
23#include <google/pubsub/v1/pubsub.pb.h>
32GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
36
37
38
39
40
41
42
43
58 proto_.set_push_endpoint(std::move(v));
59 paths_.insert(
"push_endpoint");
67 std::string
const& value) & {
68 proto_.mutable_attributes()->insert(
69 google::protobuf::Map<std::string, std::string>::value_type(key,
71 paths_.insert(
"attributes");
75 std::string
const& value) && {
80 std::vector<std::pair<std::string, std::string>> attr) & {
81 google::protobuf::Map<std::string, std::string> attributes;
82 for (
auto& kv : attr) {
83 attributes[kv.first] = std::move(kv.second);
85 proto_.mutable_attributes()->swap(attributes);
86 paths_.insert(
"attributes");
90 std::vector<std::pair<std::string, std::string>> attr) && {
95 proto_.mutable_attributes()->clear();
96 paths_.insert(
"attributes");
104 std::string service_account_email) {
105 google::pubsub::v1::PushConfig::OidcToken proto;
106 proto.set_service_account_email(std::move(service_account_email));
111 std::string service_account_email, std::string audience) {
112 google::pubsub::v1::PushConfig::OidcToken proto;
113 proto.set_service_account_email(std::move(service_account_email));
114 proto.set_audience(std::move(audience));
119 google::pubsub::v1::PushConfig::OidcToken token) & {
120 *proto_.mutable_oidc_token() = std::move(token);
121 paths_.insert(
"oidc_token");
125 google::pubsub::v1::PushConfig::OidcToken token) && {
132 google::pubsub::v1::PushConfig proto_;
133 std::set<std::string> paths_;
137
138
139
140
141
142
143
144
152 *proto_.mutable_table() = std::move(full_path);
153 paths_.insert(
"table");
160 std::string
const& data_set_id,
161 std::string
const& table_id) & {
162 return set_table(project_id +
':' + data_set_id +
'.' + table_id
);
165 std::string
const& data_set_id,
166 std::string
const& table_id) && {
167 return std::move(
set_table(project_id
, data_set_id
, table_id
));
171 proto_.set_use_topic_schema(v);
172 paths_.insert(
"use_topic_schema");
180 proto_.set_write_metadata(v);
181 paths_.insert(
"write_metadata");
189 proto_.set_drop_unknown_fields(v);
190 paths_.insert(
"drop_unknown_fields");
200 google::pubsub::v1::BigQueryConfig proto_;
201 std::set<std::string> paths_;
205
206
207
208
209
210
211
212
220 *proto_.mutable_bucket() = std::move(bucket);
221 paths_.insert(
"bucket");
229 std::string filename_prefix) & {
230 *proto_.mutable_filename_prefix() = std::move(filename_prefix);
231 paths_.insert(
"filename_prefix");
235 std::string filename_prefix) && {
240 std::string filename_suffix) & {
241 *proto_.mutable_filename_suffix() = std::move(filename_suffix);
242 paths_.insert(
"filename_suffix");
246 std::string filename_suffix) && {
251 bool write_metadata) {
252 google::pubsub::v1::CloudStorageConfig::AvroConfig proto;
253 proto.set_write_metadata(write_metadata);
258 google::pubsub::v1::CloudStorageConfig::AvroConfig avro_config) & {
259 *proto_.mutable_avro_config() = std::move(avro_config);
260 paths_.insert(
"avro_config");
264 google::pubsub::v1::CloudStorageConfig::AvroConfig avro_config) && {
268 template <
typename Rep,
typename Period>
270 std::chrono::duration<Rep, Period> d) & {
271 *proto_.mutable_max_duration() =
273 paths_.insert(
"max_duration");
276 template <
typename Rep,
typename Period>
278 std::chrono::duration<Rep, Period> d) && {
279 return std::move(set_max_duration(d));
282 google::protobuf::Duration
const& d) & {
283 *proto_.mutable_max_duration() = d;
284 paths_.insert(
"max_duration");
288 google::protobuf::Duration
const& d) && {
293 proto_.set_max_bytes(v);
294 paths_.insert(
"max_bytes");
304 google::pubsub::v1::CloudStorageConfig proto_;
305 std::set<std::string> paths_;
309
310
311
312
313
314
315
316
348 proto_.set_ack_deadline_seconds(
static_cast<std::int32_t>(v.count()));
349 paths_.insert(
"ack_deadline_seconds");
357 proto_.set_retain_acked_messages(v);
358 paths_.insert(
"retain_acked_messages");
365 template <
typename Rep,
typename Period>
367 std::chrono::duration<Rep, Period> d) & {
368 *proto_.mutable_message_retention_duration() =
369 google::
cloud::internal::ToDurationProto(std::move(d));
370 paths_.insert(
"message_retention_duration");
373 template <
typename Rep,
typename Period>
375 std::chrono::duration<Rep, Period> d) && {
376 return std::move(set_message_retention_duration(d));
380 std::string
const& value) & {
382 google::protobuf::Map<std::string, std::string>::value_type;
383 proto_.mutable_labels()->insert(value_type(key, value));
384 paths_.insert(
"labels");
388 std::string
const& value) && {
393 std::vector<std::pair<std::string, std::string>> new_labels) & {
394 google::protobuf::Map<std::string, std::string> labels;
395 for (
auto& kv : new_labels) {
396 labels[kv.first] = std::move(kv.second);
398 proto_.mutable_labels()->swap(labels);
399 paths_.insert(
"labels");
403 std::vector<std::pair<std::string, std::string>> new_labels) && {
408 proto_.clear_labels();
409 paths_.insert(
"labels");
415 proto_.set_enable_message_ordering(v);
416 paths_.insert(
"enable_message_ordering");
424 google::pubsub::v1::ExpirationPolicy v) & {
425 *proto_.mutable_expiration_policy() = std::move(v);
426 paths_.insert(
"expiration_policy");
430 google::pubsub::v1::ExpirationPolicy v) && {
435 proto_.set_filter(std::move(v));
436 paths_.insert(
"filter");
444 google::pubsub::v1::DeadLetterPolicy v) & {
445 *proto_.mutable_dead_letter_policy() = std::move(v);
446 paths_.insert(
"dead_letter_policy");
450 google::pubsub::v1::DeadLetterPolicy v) && {
455 proto_.clear_dead_letter_policy();
456 paths_.insert(
"dead_letter_policy");
464 *proto_.mutable_retry_policy() = std::move(v);
465 paths_.insert(
"retry_policy");
473 proto_.clear_retry_policy();
474 paths_.insert(
"retry_policy");
482 proto_.set_enable_exactly_once_delivery(v);
483 paths_.insert(
"enable_exactly_once_delivery");
492
493
494
495
496
497 template <
typename Rep,
typename Period>
499 std::chrono::duration<Rep, Period> d) {
500 google::pubsub::v1::ExpirationPolicy result;
501 *result.mutable_ttl() =
502 google::
cloud::internal::ToDurationProto(std::move(d));
507
508
509
510
511
513 Topic const& dead_letter_topic, std::int32_t max_delivery_attempts = 0) {
514 google::pubsub::v1::DeadLetterPolicy result;
515 result.set_dead_letter_topic(dead_letter_topic
.FullName());
516 result.set_max_delivery_attempts(max_delivery_attempts);
521
522
523
524
525
526 template <
typename Rep1,
typename Period1,
typename Rep2,
typename Period2>
528 std::chrono::duration<Rep1, Period1> minimum_backoff,
529 std::chrono::duration<Rep2, Period2> maximum_backoff) {
530 google::pubsub::v1::RetryPolicy result;
531 *result.mutable_minimum_backoff() =
532 google::
cloud::internal::ToDurationProto(minimum_backoff);
533 *result.mutable_maximum_backoff() =
534 google::
cloud::internal::ToDurationProto(maximum_backoff);
539 google::pubsub::v1::Subscription proto_;
540 std::set<std::string> paths_;
543GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
A helper class to build google::pubsub::v1::BigQueryConfig protos.
Definition: subscription_builder.h:145
BigQueryConfigBuilder & set_drop_unknown_fields(bool v) &
Definition: subscription_builder.h:188
BigQueryConfigBuilder & set_table(std::string full_path) &
Definition: subscription_builder.h:151
BigQueryConfigBuilder && set_use_topic_schema(bool v) &&
Definition: subscription_builder.h:175
BigQueryConfigBuilder && set_write_metadata(bool v) &&
Definition: subscription_builder.h:184
BigQueryConfigBuilder()=default
BigQueryConfigBuilder && set_table(std::string full_path) &&
Definition: subscription_builder.h:156
BigQueryConfigBuilder & set_use_topic_schema(bool v) &
Definition: subscription_builder.h:170
BigQueryConfigBuilder & set_write_metadata(bool v) &
Definition: subscription_builder.h:179
BigQueryConfigBuilder & set_table(std::string const &project_id, std::string const &data_set_id, std::string const &table_id) &
Definition: subscription_builder.h:159
BigQueryConfigBuilder && set_drop_unknown_fields(bool v) &&
Definition: subscription_builder.h:193
BigQueryConfigBuilder && set_table(std::string const &project_id, std::string const &data_set_id, std::string const &table_id) &&
Definition: subscription_builder.h:164
A helper class to build google::pubsub::v1::CloudStorageConfig protos.
Definition: subscription_builder.h:213
CloudStorageConfigBuilder & set_max_duration(std::chrono::duration< Rep, Period > d) &
Definition: subscription_builder.h:269
CloudStorageConfigBuilder && set_avro_config(google::pubsub::v1::CloudStorageConfig::AvroConfig avro_config) &&
Definition: subscription_builder.h:263
CloudStorageConfigBuilder && set_max_duration(google::protobuf::Duration const &d) &&
Definition: subscription_builder.h:287
CloudStorageConfigBuilder & set_avro_config(google::pubsub::v1::CloudStorageConfig::AvroConfig avro_config) &
Definition: subscription_builder.h:257
CloudStorageConfigBuilder && set_max_duration(std::chrono::duration< Rep, Period > d) &&
Definition: subscription_builder.h:277
CloudStorageConfigBuilder()=default
CloudStorageConfigBuilder && set_bucket(std::string bucket) &&
Definition: subscription_builder.h:224
CloudStorageConfigBuilder & set_max_bytes(int v) &
Definition: subscription_builder.h:292
static google::pubsub::v1::CloudStorageConfig::AvroConfig MakeAvroConfig(bool write_metadata)
Definition: subscription_builder.h:250
CloudStorageConfigBuilder && set_filename_prefix(std::string filename_prefix) &&
Definition: subscription_builder.h:234
CloudStorageConfigBuilder & set_max_duration(google::protobuf::Duration const &d) &
Definition: subscription_builder.h:281
CloudStorageConfigBuilder & set_filename_prefix(std::string filename_prefix) &
Definition: subscription_builder.h:228
CloudStorageConfigBuilder & set_bucket(std::string bucket) &
Definition: subscription_builder.h:219
CloudStorageConfigBuilder && set_filename_suffix(std::string filename_suffix) &&
Definition: subscription_builder.h:245
CloudStorageConfigBuilder && set_max_bytes(int v) &&
Definition: subscription_builder.h:297
CloudStorageConfigBuilder & set_filename_suffix(std::string filename_suffix) &
Definition: subscription_builder.h:239
Helper class to create google::pubsub::v1::PushConfig protos.
Definition: subscription_builder.h:44
PushConfigBuilder && clear_attributes() &&
Definition: subscription_builder.h:99
static google::pubsub::v1::PushConfig::OidcToken MakeOidcToken(std::string service_account_email)
Definition: subscription_builder.h:103
PushConfigBuilder & clear_attributes() &
Definition: subscription_builder.h:94
google::pubsub::v1::ModifyPushConfigRequest BuildModifyPushConfig(Subscription const &subscription) &&
Build a protocol buffer message to update an existing push config.
PushConfigBuilder & set_attributes(std::vector< std::pair< std::string, std::string > > attr) &
Definition: subscription_builder.h:79
PushConfigBuilder()=default
PushConfigBuilder & add_attribute(std::string const &key, std::string const &value) &
Definition: subscription_builder.h:66
PushConfigBuilder && set_push_endpoint(std::string v) &&
Definition: subscription_builder.h:62
PushConfigBuilder & set_authentication(google::pubsub::v1::PushConfig::OidcToken token) &
Definition: subscription_builder.h:118
PushConfigBuilder & set_push_endpoint(std::string v) &
Definition: subscription_builder.h:57
static google::pubsub::v1::PushConfig::OidcToken MakeOidcToken(std::string service_account_email, std::string audience)
Definition: subscription_builder.h:110
PushConfigBuilder && set_authentication(google::pubsub::v1::PushConfig::OidcToken token) &&
Definition: subscription_builder.h:124
PushConfigBuilder && add_attribute(std::string const &key, std::string const &value) &&
Definition: subscription_builder.h:74
PushConfigBuilder(std::string push_endpoint)
Definition: subscription_builder.h:47
PushConfigBuilder && set_attributes(std::vector< std::pair< std::string, std::string > > attr) &&
Definition: subscription_builder.h:89
Create a Cloud Pub/Sub subscription configuration.
Definition: subscription_builder.h:317
static google::pubsub::v1::DeadLetterPolicy MakeDeadLetterPolicy(Topic const &dead_letter_topic, std::int32_t max_delivery_attempts=0)
Construct a google::pubsub::v1::DeadLetterPolicy.
Definition: subscription_builder.h:512
SubscriptionBuilder & enable_exactly_once_delivery(bool v) &
Definition: subscription_builder.h:481
SubscriptionBuilder && set_dead_letter_policy(google::pubsub::v1::DeadLetterPolicy v) &&
Definition: subscription_builder.h:449
static google::pubsub::v1::ExpirationPolicy MakeExpirationPolicy(std::chrono::duration< Rep, Period > d)
Construct a google::pubsub::v1::ExpirationPolicy using a C++ duration.
Definition: subscription_builder.h:498
SubscriptionBuilder && clear_labels() &&
Definition: subscription_builder.h:412
SubscriptionBuilder && set_retry_policy(google::pubsub::v1::RetryPolicy v) &&
Definition: subscription_builder.h:468
SubscriptionBuilder && set_retain_acked_messages(bool v) &&
Definition: subscription_builder.h:361
SubscriptionBuilder && clear_retry_policy() &&
Definition: subscription_builder.h:477
google::pubsub::v1::Subscription BuildCreateRequest(Topic const &topic, Subscription const &subscription) &&
Build a protocol buffer message to create a new subscription.
SubscriptionBuilder & set_retry_policy(google::pubsub::v1::RetryPolicy v) &
Definition: subscription_builder.h:463
SubscriptionBuilder && set_bigquery_config(BigQueryConfigBuilder v) &&
Definition: subscription_builder.h:337
SubscriptionBuilder && set_push_config(PushConfigBuilder v) &&
Definition: subscription_builder.h:332
SubscriptionBuilder & clear_dead_letter_policy() &
Definition: subscription_builder.h:454
SubscriptionBuilder & clear_retry_policy() &
Definition: subscription_builder.h:472
SubscriptionBuilder & add_label(std::string const &key, std::string const &value) &
Definition: subscription_builder.h:379
SubscriptionBuilder & clear_labels() &
Definition: subscription_builder.h:407
SubscriptionBuilder()=default
SubscriptionBuilder & set_labels(std::vector< std::pair< std::string, std::string > > new_labels) &
Definition: subscription_builder.h:392
SubscriptionBuilder && set_ack_deadline(std::chrono::seconds v) &&
Definition: subscription_builder.h:352
SubscriptionBuilder & set_push_config(PushConfigBuilder v) &
SubscriptionBuilder & set_expiration_policy(google::pubsub::v1::ExpirationPolicy v) &
Definition: subscription_builder.h:423
SubscriptionBuilder & set_dead_letter_policy(google::pubsub::v1::DeadLetterPolicy v) &
Definition: subscription_builder.h:443
SubscriptionBuilder && set_message_retention_duration(std::chrono::duration< Rep, Period > d) &&
Definition: subscription_builder.h:374
SubscriptionBuilder & set_retain_acked_messages(bool v) &
Definition: subscription_builder.h:356
static google::pubsub::v1::RetryPolicy MakeRetryPolicy(std::chrono::duration< Rep1, Period1 > minimum_backoff, std::chrono::duration< Rep2, Period2 > maximum_backoff)
Construct a google::pubsub::v1::RetryPolicy using C++ durations.
Definition: subscription_builder.h:527
SubscriptionBuilder && set_labels(std::vector< std::pair< std::string, std::string > > new_labels) &&
Definition: subscription_builder.h:402
SubscriptionBuilder && set_filter(std::string v) &&
Definition: subscription_builder.h:439
SubscriptionBuilder & set_filter(std::string v) &
Definition: subscription_builder.h:434
SubscriptionBuilder & set_bigquery_config(BigQueryConfigBuilder v) &
SubscriptionBuilder && set_expiration_policy(google::pubsub::v1::ExpirationPolicy v) &&
Definition: subscription_builder.h:429
SubscriptionBuilder & set_cloud_storage_config(CloudStorageConfigBuilder v) &
SubscriptionBuilder & set_ack_deadline(std::chrono::seconds v) &
Definition: subscription_builder.h:347
SubscriptionBuilder & enable_message_ordering(bool v) &
Definition: subscription_builder.h:414
SubscriptionBuilder && clear_dead_letter_policy() &&
Definition: subscription_builder.h:459
SubscriptionBuilder && enable_exactly_once_delivery(bool v) &&
Definition: subscription_builder.h:486
SubscriptionBuilder && add_label(std::string const &key, std::string const &value) &&
Definition: subscription_builder.h:387
SubscriptionBuilder & set_message_retention_duration(std::chrono::duration< Rep, Period > d) &
Definition: subscription_builder.h:366
SubscriptionBuilder && set_cloud_storage_config(CloudStorageConfigBuilder v) &&
Definition: subscription_builder.h:342
SubscriptionBuilder && enable_message_ordering(bool v) &&
Definition: subscription_builder.h:419
google::pubsub::v1::UpdateSubscriptionRequest BuildUpdateRequest(Subscription const &subscription) &&
Build a protocol buffer message to update an existing subscription.
Objects of this class identify a Cloud Pub/Sub subscription.
Definition: subscription.h:37
Objects of this class identify a Cloud Pub/Sub topic.
Definition: topic.h:37
std::string FullName() const
Returns the fully qualified topic name as a string of the form: "projects/<project-id>/topics/<topic-...
Contains all the Cloud Pub/Sub C++ client types and functions.
Definition: ack_handler.h:25
The namespace Google Cloud Platform C++ client libraries.