Google Cloud Pub/Sub C++ Client  2.5.0
A C++ Client Library for Google Cloud Pub/Sub
subscription_admin_connection.h
Go to the documentation of this file.
1 // Copyright 2020 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_SUBSCRIPTION_ADMIN_CONNECTION_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_SUBSCRIPTION_ADMIN_CONNECTION_H
17 
18 #include "google/cloud/pubsub/backoff_policy.h"
19 #include "google/cloud/pubsub/connection_options.h"
20 #include "google/cloud/pubsub/internal/subscriber_stub.h"
21 #include "google/cloud/pubsub/retry_policy.h"
22 #include "google/cloud/pubsub/snapshot.h"
23 #include "google/cloud/pubsub/subscription.h"
24 #include "google/cloud/pubsub/version.h"
25 #include "google/cloud/internal/non_constructible.h"
26 #include "google/cloud/internal/pagination_range.h"
27 #include "google/cloud/status_or.h"
28 #include <google/pubsub/v1/pubsub.pb.h>
29 #include <initializer_list>
30 #include <memory>
31 #include <string>
32 
33 namespace google {
34 namespace cloud {
35 namespace pubsub {
37 
38 /**
39  * An input range to stream Cloud Pub/Sub subscriptions.
40  *
41  * This type models an [input range][cppref-input-range] of
42  * `google::pubsub::v1::Subscription` objects. Applications can make a
43  * single pass through the results.
44  *
45  * [cppref-input-range]: https://en.cppreference.com/w/cpp/ranges/input_range
46  */
47 using ListSubscriptionsRange =
48  google::cloud::internal::PaginationRange<google::pubsub::v1::Subscription>;
49 
50 /**
51  * An input range to stream Cloud Pub/Sub snapshots.
52  *
53  * This type models an [input range][cppref-input-range] of
54  * `google::pubsub::v1::Snapshot` objects. Applications can make a
55  * single pass through the results.
56  *
57  * [cppref-input-range]: https://en.cppreference.com/w/cpp/ranges/input_range
58  */
59 using ListSnapshotsRange =
60  google::cloud::internal::PaginationRange<google::pubsub::v1::Snapshot>;
61 
62 /**
63  * A connection to Cloud Pub/Sub for subscription-related administrative
64  * operations.
65  *
66  * This interface defines pure-virtual functions for each of the user-facing
67  * overload sets in `SubscriptionAdminClient`. That is, all of
68  * `SubscriptionAdminClient` overloads will forward to the one pure-virtual
69  * function declared in this interface. This allows users to inject custom
70  * behavior (e.g., with a Google Mock object) in a `SubscriptionAdminClient`
71  * object for use in their own tests.
72  *
73  * To create a concrete instance that connects you to the real Cloud Pub/Sub
74  * service, see `MakeSubscriptionAdminConnection()`.
75  *
76  * @par The *Params nested classes
77  * Applications may define classes derived from `SubscriptionAdminConnection`,
78  * for example, because they want to mock the class. To avoid breaking all such
79  * derived classes when we change the number or type of the arguments to the
80  * member functions we define lightweight structures to pass the arguments.
81  */
83  public:
85 
86  /// Wrap the arguments for `CreateSubscription()`
88  google::pubsub::v1::Subscription subscription;
89  };
90 
91  /// Wrap the arguments for `GetSubscription()`
94  };
95 
96  /// Wrap the arguments for `UpdateSubscription()`
98  google::pubsub::v1::UpdateSubscriptionRequest request;
99  };
100 
101  /// Wrap the arguments for `ListSubscriptions()`
103  std::string project_id;
104  };
105 
106  /// Wrap the arguments for `DeleteSubscription()`
109  };
110 
111  /// Wrap the arguments for `ModifyPushConfig()`
113  google::pubsub::v1::ModifyPushConfigRequest request;
114  };
115 
116  /// Wrap the arguments for `CreateSnapshot()`
118  google::pubsub::v1::CreateSnapshotRequest request;
119  };
120 
121  /// Wrap the arguments for `GetSnapshot()`
124  };
125 
126  /// Wrap the arguments for `ListSnapshots()`
128  std::string project_id;
129  };
130 
131  /// Wrap the arguments for `UpdateSnapshot()`
133  google::pubsub::v1::UpdateSnapshotRequest request;
134  };
135 
136  /// Wrap the arguments for `DeleteSnapshot()`
139  };
140 
141  /// Wrap the arguments for `Seek()`
142  struct SeekParams {
143  google::pubsub::v1::SeekRequest request;
144  };
145 
146  /// Defines the interface for `SubscriptionAdminClient::CreateSubscription()`
147  virtual StatusOr<google::pubsub::v1::Subscription> CreateSubscription(
149 
150  /// Defines the interface for `SubscriptionAdminClient::GetSubscription()`
151  virtual StatusOr<google::pubsub::v1::Subscription> GetSubscription(
153 
154  /// Defines the interface for `SubscriptionAdminClient::UpdateSubscription()`
155  virtual StatusOr<google::pubsub::v1::Subscription> UpdateSubscription(
157 
158  /// Defines the interface for `SubscriptionAdminClient::ListSubscriptions()`
159  virtual ListSubscriptionsRange ListSubscriptions(ListSubscriptionsParams);
160 
161  /// Defines the interface for `SubscriptionAdminClient::DeleteSubscription()`
163 
164  /// Defines the interface for `SubscriptionAdminClient::ModifyPushConfig()`
166 
167  /// Defines the interface for `SnapshotAdminClient::CreateSnapshot()`
168  virtual StatusOr<google::pubsub::v1::Snapshot> CreateSnapshot(
170 
171  /// Defines the interface for `SnapshotAdminClient::GetSnapshot()`
172  virtual StatusOr<google::pubsub::v1::Snapshot> GetSnapshot(GetSnapshotParams);
173 
174  /// Defines the interface for `SnapshotAdminClient::UpdateSnapshot()`
175  virtual StatusOr<google::pubsub::v1::Snapshot> UpdateSnapshot(
177 
178  /// Defines the interface for `SubscriptionAdminClient::ListSnapshots()`
179  virtual ListSnapshotsRange ListSnapshots(ListSnapshotsParams);
180 
181  /// Defines the interface for `SnapshotAdminClient::DeleteSnapshot()`
183 
184  /// Defines the interface for `SubscriptionAdminClient::Seek()`
185  virtual StatusOr<google::pubsub::v1::SeekResponse> Seek(SeekParams);
186 
187  /// Return the options used to create the connection.
188  virtual Options options() const { return Options{}; }
189 };
190 
191 /**
192  * Creates a new `SubscriptionAdminConnection` object to work with
193  * `SubscriptionAdminClient`.
194  *
195  * @note This function exists solely for backwards compatibility. It prevents
196  * existing code that calls `MakeSubscriptionAdminConnection({})` from
197  * breaking, due to ambiguity.
198  *
199  * @deprecated Please use `MakeSubscriptionAdminConnection()` instead.
200  */
201 GOOGLE_CLOUD_CPP_DEPRECATED("use MakeSubscriptionAdminConnection() instead")
203  std::initializer_list<internal::NonConstructible>);
204 
205 /**
206  * Creates a new `SubscriptionAdminConnection` object to work with
207  * `SubscriptionAdminClient`.
208  *
209  * The `SubscriptionAdminConnection` class is provided for applications wanting
210  * to mock the `SubscriptionAdminClient` behavior in their tests. It is not
211  * intended for direct use.
212  *
213  * @par Performance
214  * Creating a new `SubscriptionAdminConnection` is relatively expensive. This
215  * typically initiates connections to the service, and therefore these objects
216  * should be shared and reused when possible. Note that gRPC reuses existing OS
217  * resources (sockets) whenever possible, so applications may experience better
218  * performance on the second (and subsequent) calls to this function with the
219  * same `Options` from `GrpcOptionList` and `CommonOptionList`. However, this
220  * behavior is not guaranteed and applications should not rely on it.
221  *
222  * @see `SubscriptionAdminClient`
223  *
224  * @param opts The options to use for this call. Expected options are any of
225  * the types in the following option lists.
226  * - `google::cloud::CommonOptionList`
227  * - `google::cloud::GrpcOptionList`
228  * - `google::cloud::pubsub::PolicyOptionList`
229  */
231  Options opts = {});
232 
233 /**
234  * Creates a new `SubscriptionAdminConnection` object to work with
235  * `SubscriptionAdminClient`.
236  *
237  * The `SubscriptionAdminConnection` class is not intended for direct use in
238  * applications, it is provided for applications wanting to mock the
239  * `SubscriptionAdminClient` behavior in their tests.
240  *
241  * @par Performance
242  * Creating a new `SubscriptionAdminConnection` is relatively expensive. This
243  * typically initiates connections to the service, and therefore these objects
244  * should be shared and reused when possible. Note that gRPC reuses existing OS
245  * resources (sockets) whenever possible, so applications may experience better
246  * performance on the second (and subsequent) calls to this function with the
247  * identical values for @p options. However, this behavior is not guaranteed
248  * and applications should not rely on it.
249  *
250  * @see `SubscriberConnection`
251  *
252  * @param options (optional) configure the `SubscriptionAdminConnection` created
253  * by this function.
254  * @param retry_policy control for how long (or how many times) are retryable
255  * RPCs attempted.
256  * @param backoff_policy controls the backoff behavior between retry attempts,
257  * typically some form of exponential backoff with jitter.
258  *
259  * @deprecated Please use the `MakeSubscriptionAdminConnection` function that
260  * accepts `google::cloud::Options` instead.
261  */
262 GOOGLE_CLOUD_CPP_DEPRECATED(
263  "use the overload consuming google::cloud::Options instead")
265  ConnectionOptions const& options,
266  std::unique_ptr<pubsub::RetryPolicy const> retry_policy = {},
267  std::unique_ptr<pubsub::BackoffPolicy const> backoff_policy = {});
268 
270 } // namespace pubsub
271 
272 namespace pubsub_internal {
274 
275 std::shared_ptr<pubsub::SubscriptionAdminConnection>
276 MakeTestSubscriptionAdminConnection(Options const& opts,
277  std::shared_ptr<SubscriberStub> stub);
278 
280 } // namespace pubsub_internal
281 } // namespace cloud
282 } // namespace google
283 
284 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_SUBSCRIPTION_ADMIN_CONNECTION_H