Google Cloud Pub/Sub C++ Client 2.13.0
A C++ Client Library for Google Cloud Pub/Sub
Loading...
Searching...
No Matches
topic_admin_connection.h
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_TOPIC_ADMIN_CONNECTION_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_TOPIC_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/publisher_stub.h"
21#include "google/cloud/pubsub/retry_policy.h"
22#include "google/cloud/pubsub/subscription.h"
23#include "google/cloud/pubsub/topic.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 <memory>
30#include <string>
31
32namespace google {
33namespace cloud {
34namespace pubsub {
35GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
36
37/**
38 * An input range to stream Cloud Pub/Sub topics.
39 *
40 * This type models an [input range][cppref-input-range] of
41 * `google::pubsub::v1::Topic` objects. Applications can make a
42 * single pass through the results.
43 *
44 * [cppref-input-range]: https://en.cppreference.com/w/cpp/ranges/input_range
45 */
46using ListTopicsRange =
47 google::cloud::internal::PaginationRange<google::pubsub::v1::Topic>;
48
49/**
50 * An input range to stream the Cloud Pub/Sub subscriptions of a topic.
51 *
52 * This type models an [input range][cppref-input-range] of
53 * `std::string` objects. Applications can make a
54 * single pass through the results.
55 *
56 * [cppref-input-range]: https://en.cppreference.com/w/cpp/ranges/input_range
57 */
58using ListTopicSubscriptionsRange =
59 google::cloud::internal::PaginationRange<std::string>;
60
61/**
62 * An input range to stream the Cloud Pub/Sub snapshots of a topic.
63 *
64 * This type models an [input range][cppref-input-range] of
65 * `std::string` objects. Applications can make a
66 * single pass through the results.
67 *
68 * [cppref-input-range]: https://en.cppreference.com/w/cpp/ranges/input_range
69 */
70using ListTopicSnapshotsRange =
71 google::cloud::internal::PaginationRange<std::string>;
72
73/**
74 * A connection to Cloud Pub/Sub for topic-related administrative operations.
75 *
76 * This interface defines pure-virtual functions for each of the user-facing
77 * overload sets in `TopicAdminClient`. That is, all of `TopicAdminClient`'s
78 * overloads will forward to the one pure-virtual function declared in this
79 * interface. This allows users to inject custom behavior (e.g., with a Google
80 * Mock object) in a `TopicAdminClient` object for use in their own tests.
81 *
82 * To create a concrete instance that connects you to the real Cloud Pub/Sub
83 * service, see `MakeTopicAdminConnection()`.
84 *
85 * @par The *Params nested classes
86 * Applications may define classes derived from `TopicAdminConnection`, for
87 * example, because they want to mock the class. To avoid breaking all such
88 * derived classes when we change the number or type of the arguments to the
89 * member functions we define lightweight structures to pass the arguments.
90 */
92 public:
93 virtual ~TopicAdminConnection() = 0;
94
95 /// Wrap the arguments for `CreateTopic()`
96 struct CreateTopicParams {
97 google::pubsub::v1::Topic topic;
98 };
99
100 /// Wrap the arguments for `GetTopic()`
101 struct GetTopicParams {
102 Topic topic;
103 };
104
105 /// Wrap the arguments for `UpdateTopic()`
106 struct UpdateTopicParams {
107 google::pubsub::v1::UpdateTopicRequest request;
108 };
109
110 /// Wrap the arguments for `ListTopics()`
111 struct ListTopicsParams {
112 std::string project_id;
113 };
114
115 /// Wrap the arguments for `DeleteTopic()`
116 struct DeleteTopicParams {
117 Topic topic;
118 };
119
120 /// Wrap the arguments for `DetachSubscription()`
123 };
124
125 /// Wrap the arguments for `ListTopicSubscriptions()`
127 std::string topic_full_name;
128 };
129
130 /// Wrap the arguments for `ListTopicSnapshots()`
132 std::string topic_full_name;
133 };
134
135 /// Defines the interface for `TopicAdminClient::CreateTopic()`
136 virtual StatusOr<google::pubsub::v1::Topic> CreateTopic(CreateTopicParams);
137
138 /// Defines the interface for `TopicAdminClient::GetTopic()`
139 virtual StatusOr<google::pubsub::v1::Topic> GetTopic(GetTopicParams);
140
141 /// Defines the interface for `TopicAdminClient::UpdateTopic()`
142 virtual StatusOr<google::pubsub::v1::Topic> UpdateTopic(UpdateTopicParams);
143
144 /// Defines the interface for `TopicAdminClient::ListTopics()`
145 virtual ListTopicsRange ListTopics(ListTopicsParams);
146
147 /// Defines the interface for `TopicAdminClient::DeleteTopic()`
149
150 /// Defines the interface for `TopicAdminClient::DetachSubscriptions()`
151 virtual StatusOr<google::pubsub::v1::DetachSubscriptionResponse>
153
154 /// Defines the interface for `TopicAdminClient::ListTopicSubscriptions()`
155 virtual ListTopicSubscriptionsRange ListTopicSubscriptions(
157
158 /// Defines the interface for `TopicAdminClient::ListTopicSnapshots()`
159 virtual ListTopicSnapshotsRange ListTopicSnapshots(ListTopicSnapshotsParams);
160
161 /// Returns the options used to create the connection
162 virtual Options options() const { return Options{}; }
163};
164
165/**
166 * Creates a new `TopicAdminConnection` object to work with `TopicAdminClient`.
167 *
168 * @note This function exists solely for backwards compatibility. It prevents
169 * existing code that calls `MakeTopicAdminConnection({})` from breaking,
170 * due to ambiguity.
171 *
172 * @deprecated Please use `MakeTopicAdminConnection()` instead.
173 */
174GOOGLE_CLOUD_CPP_DEPRECATED("use MakeTopicAdminConnection() instead")
176 std::initializer_list<internal::NonConstructible>);
177
178/**
179 * Creates a new `TopicAdminConnection` object to work with `TopicAdminClient`.
180 *
181 * The `TopicAdminConnection` class is provided for applications wanting to mock
182 * the `TopicAdminClient` behavior in their tests. It is not intended for direct
183 * use.
184 *
185 * @par Performance
186 * Creating a new `TopicAdminConnection` is relatively expensive. This typically
187 * initiates connections to the service, and therefore these objects should be
188 * shared and reused when possible. Note that gRPC reuses existing OS resources
189 * (sockets) whenever possible, so applications may experience better
190 * performance on the second (and subsequent) calls to this function with the
191 * same `Options` from `GrpcOptionList` and `CommonOptionList`. However, this
192 * behavior is not guaranteed and applications should not rely on it.
193 *
194 * @see `TopicAdminClient`
195 *
196 * @param opts The options to use for this call. Expected options are any
197 * of the types in the following option lists.
198 * - `google::cloud::CommonOptionList`
199 * - `google::cloud::GrpcOptionList`
200 * - `google::cloud::pubsub::PolicyOptionList`
201 */
203 Options opts = {});
204
205/**
206 * Creates a new `TopicAdminConnection` object to work with `TopicAdminClient`.
207 *
208 * The `TopicAdminConnection` class is provided for applications wanting to mock
209 * the `TopicAdminClient` behavior in their tests. It is not intended for direct
210 * use.
211 *
212 * @par Performance
213 * Creating a new `TopicAdminConnection` is relatively expensive. This typically
214 * initiate connections to the service, and therefore these objects should be
215 * shared and reused when possible. Note that gRPC reuses existing OS resources
216 * (sockets) whenever possible, so applications may experience better
217 * performance on the second (and subsequent) calls to this function with the
218 * identical values for @p options. However, this behavior is not guaranteed
219 * and applications should not rely on it.
220 *
221 * @see `TopicAdminClient`
222 *
223 * @param options (optional) configure the `TopicAdminConnection` created by
224 * this function.
225 * @param retry_policy control for how long (or how many times) are retryable
226 * RPCs attempted.
227 * @param backoff_policy controls the backoff behavior between retry attempts,
228 * typically some form of exponential backoff with jitter.
229 *
230 * @deprecated Please use the `MakeTopicAdminConnection` function that accepts
231 * `google::cloud::Options` instead.
232 */
233GOOGLE_CLOUD_CPP_DEPRECATED(
234 "use the overload consuming google::cloud::Options instead")
236 ConnectionOptions const& options,
237 std::unique_ptr<pubsub::RetryPolicy const> retry_policy = {},
238 std::unique_ptr<pubsub::BackoffPolicy const> backoff_policy = {});
239
240GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
241} // namespace pubsub
242
243namespace pubsub_internal {
244GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
245
246std::shared_ptr<pubsub::TopicAdminConnection> MakeTestTopicAdminConnection(
247 Options const& opts, std::shared_ptr<PublisherStub> stub);
248
249GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
250} // namespace pubsub_internal
251} // namespace cloud
252} // namespace google
253
254#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_TOPIC_ADMIN_CONNECTION_H
Objects of this class identify a Cloud Pub/Sub subscription.
Definition: subscription.h:37
A connection to Cloud Pub/Sub for topic-related administrative operations.
Definition: topic_admin_connection.h:91
virtual StatusOr< google::pubsub::v1::Topic > CreateTopic(CreateTopicParams)
Defines the interface for TopicAdminClient::CreateTopic()
virtual StatusOr< google::pubsub::v1::Topic > UpdateTopic(UpdateTopicParams)
Defines the interface for TopicAdminClient::UpdateTopic()
virtual Status DeleteTopic(DeleteTopicParams)
Defines the interface for TopicAdminClient::DeleteTopic()
virtual ListTopicSnapshotsRange ListTopicSnapshots(ListTopicSnapshotsParams)
Defines the interface for TopicAdminClient::ListTopicSnapshots()
virtual StatusOr< google::pubsub::v1::Topic > GetTopic(GetTopicParams)
Defines the interface for TopicAdminClient::GetTopic()
virtual ListTopicsRange ListTopics(ListTopicsParams)
Defines the interface for TopicAdminClient::ListTopics()
virtual ListTopicSubscriptionsRange ListTopicSubscriptions(ListTopicSubscriptionsParams)
Defines the interface for TopicAdminClient::ListTopicSubscriptions()
virtual Options options() const
Returns the options used to create the connection.
Definition: topic_admin_connection.h:162
virtual StatusOr< google::pubsub::v1::DetachSubscriptionResponse > DetachSubscription(DetachSubscriptionParams)
Defines the interface for TopicAdminClient::DetachSubscriptions()
Objects of this class identify a Cloud Pub/Sub topic.
Definition: topic.h:37
Contains all the Cloud Pub/Sub C++ client types and functions.
Definition: ack_handler.h:25
std::shared_ptr< TopicAdminConnection > MakeTopicAdminConnection(Options opts={})
Creates a new TopicAdminConnection object to work with TopicAdminClient.
std::shared_ptr< TopicAdminConnection > MakeTopicAdminConnection(ConnectionOptions const &options, std::unique_ptr< pubsub::RetryPolicy const > retry_policy={}, std::unique_ptr< pubsub::BackoffPolicy const > backoff_policy={})
Creates a new TopicAdminConnection object to work with TopicAdminClient.
std::shared_ptr< TopicAdminConnection > MakeTopicAdminConnection(std::initializer_list< internal::NonConstructible >)
Creates a new TopicAdminConnection object to work with TopicAdminClient.
The namespace Google Cloud Platform C++ client libraries.
Wrap the arguments for CreateTopic()
Definition: topic_admin_connection.h:96
google::pubsub::v1::Topic topic
Definition: topic_admin_connection.h:97
Wrap the arguments for DeleteTopic()
Definition: topic_admin_connection.h:116
Topic topic
Definition: topic_admin_connection.h:117
Wrap the arguments for DetachSubscription()
Definition: topic_admin_connection.h:121
Subscription subscription
Definition: topic_admin_connection.h:122
Wrap the arguments for GetTopic()
Definition: topic_admin_connection.h:101
Topic topic
Definition: topic_admin_connection.h:102
Wrap the arguments for ListTopicSnapshots()
Definition: topic_admin_connection.h:131
std::string topic_full_name
Definition: topic_admin_connection.h:132
Wrap the arguments for ListTopicSubscriptions()
Definition: topic_admin_connection.h:126
std::string topic_full_name
Definition: topic_admin_connection.h:127
Wrap the arguments for ListTopics()
Definition: topic_admin_connection.h:111
std::string project_id
Definition: topic_admin_connection.h:112
Wrap the arguments for UpdateTopic()
Definition: topic_admin_connection.h:106
google::pubsub::v1::UpdateTopicRequest request
Definition: topic_admin_connection.h:107