google_cloud_pubsub/generated/gapic/client.rs
1// Copyright 2025 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// Code generated by sidekick. DO NOT EDIT.
16#![allow(rustdoc::redundant_explicit_links)]
17#![allow(rustdoc::broken_intra_doc_links)]
18
19/// Implements a client for the Cloud Pub/Sub API.
20///
21/// # Example
22/// ```
23/// # use google_cloud_pubsub::client::TopicAdmin;
24/// async fn sample(
25/// project_id: &str,
26/// topic_id: &str,
27/// ) -> anyhow::Result<()> {
28/// let client = TopicAdmin::builder().build().await?;
29/// let response = client.get_topic()
30/// .set_topic(format!("projects/{project_id}/topics/{topic_id}"))
31/// .send().await?;
32/// println!("response {:?}", response);
33/// Ok(())
34/// }
35/// ```
36///
37/// # Service Description
38///
39/// The service that an application uses to manipulate topics.
40///
41/// # Configuration
42///
43/// To configure `TopicAdmin` use the `with_*` methods in the type returned
44/// by [builder()][TopicAdmin::builder]. The default configuration should
45/// work for most applications. Common configuration changes include
46///
47/// * [with_endpoint()]: by default this client uses the global default endpoint
48/// (`https://pubsub.googleapis.com`). Applications using regional
49/// endpoints or running in restricted networks (e.g. a network configured
50/// with [Private Google Access with VPC Service Controls]) may want to
51/// override this default.
52/// * [with_credentials()]: by default this client uses
53/// [Application Default Credentials]. Applications using custom
54/// authentication may need to override this default.
55///
56/// [with_endpoint()]: super::builder::topic_admin::ClientBuilder::with_endpoint
57/// [with_credentials()]: super::builder::topic_admin::ClientBuilder::with_credentials
58/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
59/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
60///
61/// # Pooling and Cloning
62///
63/// `TopicAdmin` holds a connection pool internally, it is advised to
64/// create one and reuse it. You do not need to wrap `TopicAdmin` in
65/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
66/// already uses an `Arc` internally.
67#[derive(Clone, Debug)]
68pub struct TopicAdmin {
69 inner: std::sync::Arc<dyn super::stub::dynamic::TopicAdmin>,
70}
71
72impl TopicAdmin {
73 /// Returns a builder for [TopicAdmin].
74 ///
75 /// ```
76 /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
77 /// # use google_cloud_pubsub::client::TopicAdmin;
78 /// let client = TopicAdmin::builder().build().await?;
79 /// # Ok(()) }
80 /// ```
81 pub fn builder() -> super::builder::topic_admin::ClientBuilder {
82 crate::new_client_builder(super::builder::topic_admin::client::Factory)
83 }
84
85 /// Creates a new client from the provided stub.
86 ///
87 /// The most common case for calling this function is in tests mocking the
88 /// client's behavior.
89 pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
90 where
91 T: super::stub::TopicAdmin + 'static,
92 {
93 Self { inner: stub.into() }
94 }
95
96 pub(crate) async fn new(
97 config: gaxi::options::ClientConfig,
98 ) -> crate::ClientBuilderResult<Self> {
99 let inner = Self::build_inner(config).await?;
100 Ok(Self { inner })
101 }
102
103 async fn build_inner(
104 conf: gaxi::options::ClientConfig,
105 ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::TopicAdmin>> {
106 if gaxi::options::tracing_enabled(&conf) {
107 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
108 }
109 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
110 }
111
112 async fn build_transport(
113 conf: gaxi::options::ClientConfig,
114 ) -> crate::ClientBuilderResult<impl super::stub::TopicAdmin> {
115 super::transport::TopicAdmin::new(conf).await
116 }
117
118 async fn build_with_tracing(
119 conf: gaxi::options::ClientConfig,
120 ) -> crate::ClientBuilderResult<impl super::stub::TopicAdmin> {
121 Self::build_transport(conf)
122 .await
123 .map(super::tracing::TopicAdmin::new)
124 }
125
126 /// Creates the given topic with the given name. See the [resource name rules]
127 /// (<https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names>).
128 ///
129 /// # Example
130 /// ```
131 /// # use google_cloud_pubsub::client::TopicAdmin;
132 /// use google_cloud_pubsub::Result;
133 /// async fn sample(
134 /// client: &TopicAdmin
135 /// ) -> Result<()> {
136 /// let response = client.create_topic()
137 /// /* set fields */
138 /// .send().await?;
139 /// println!("response {:?}", response);
140 /// Ok(())
141 /// }
142 /// ```
143 pub fn create_topic(&self) -> super::builder::topic_admin::CreateTopic {
144 super::builder::topic_admin::CreateTopic::new(self.inner.clone())
145 }
146
147 /// Updates an existing topic by updating the fields specified in the update
148 /// mask. Note that certain properties of a topic are not modifiable.
149 ///
150 /// # Example
151 /// ```
152 /// # use google_cloud_pubsub::client::TopicAdmin;
153 /// # extern crate wkt as google_cloud_wkt;
154 /// use google_cloud_wkt::FieldMask;
155 /// use google_cloud_pubsub::model::Topic;
156 /// use google_cloud_pubsub::Result;
157 /// async fn sample(
158 /// client: &TopicAdmin, project_id: &str, topic_id: &str
159 /// ) -> Result<()> {
160 /// let response = client.update_topic()
161 /// .set_topic(
162 /// Topic::new().set_name(format!("projects/{project_id}/topics/{topic_id}"))/* set fields */
163 /// )
164 /// .set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
165 /// .send().await?;
166 /// println!("response {:?}", response);
167 /// Ok(())
168 /// }
169 /// ```
170 pub fn update_topic(&self) -> super::builder::topic_admin::UpdateTopic {
171 super::builder::topic_admin::UpdateTopic::new(self.inner.clone())
172 }
173
174 /// Gets the configuration of a topic.
175 ///
176 /// # Example
177 /// ```
178 /// # use google_cloud_pubsub::client::TopicAdmin;
179 /// use google_cloud_pubsub::Result;
180 /// async fn sample(
181 /// client: &TopicAdmin, project_id: &str, topic_id: &str
182 /// ) -> Result<()> {
183 /// let response = client.get_topic()
184 /// .set_topic(format!("projects/{project_id}/topics/{topic_id}"))
185 /// .send().await?;
186 /// println!("response {:?}", response);
187 /// Ok(())
188 /// }
189 /// ```
190 pub fn get_topic(&self) -> super::builder::topic_admin::GetTopic {
191 super::builder::topic_admin::GetTopic::new(self.inner.clone())
192 }
193
194 /// Lists matching topics.
195 ///
196 /// # Example
197 /// ```
198 /// # use google_cloud_pubsub::client::TopicAdmin;
199 /// use google_cloud_gax::paginator::ItemPaginator as _;
200 /// use google_cloud_pubsub::Result;
201 /// async fn sample(
202 /// client: &TopicAdmin
203 /// ) -> Result<()> {
204 /// let mut list = client.list_topics()
205 /// /* set fields */
206 /// .by_item();
207 /// while let Some(item) = list.next().await.transpose()? {
208 /// println!("{:?}", item);
209 /// }
210 /// Ok(())
211 /// }
212 /// ```
213 pub fn list_topics(&self) -> super::builder::topic_admin::ListTopics {
214 super::builder::topic_admin::ListTopics::new(self.inner.clone())
215 }
216
217 /// Lists the names of the attached subscriptions on this topic.
218 ///
219 /// # Example
220 /// ```
221 /// # use google_cloud_pubsub::client::TopicAdmin;
222 /// use google_cloud_gax::paginator::ItemPaginator as _;
223 /// use google_cloud_pubsub::Result;
224 /// async fn sample(
225 /// client: &TopicAdmin
226 /// ) -> Result<()> {
227 /// let mut list = client.list_topic_subscriptions()
228 /// /* set fields */
229 /// .by_item();
230 /// while let Some(item) = list.next().await.transpose()? {
231 /// println!("{:?}", item);
232 /// }
233 /// Ok(())
234 /// }
235 /// ```
236 pub fn list_topic_subscriptions(&self) -> super::builder::topic_admin::ListTopicSubscriptions {
237 super::builder::topic_admin::ListTopicSubscriptions::new(self.inner.clone())
238 }
239
240 /// Lists the names of the snapshots on this topic. Snapshots are used in
241 /// [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations,
242 /// which allow you to manage message acknowledgments in bulk. That is, you can
243 /// set the acknowledgment state of messages in an existing subscription to the
244 /// state captured by a snapshot.
245 ///
246 /// # Example
247 /// ```
248 /// # use google_cloud_pubsub::client::TopicAdmin;
249 /// use google_cloud_pubsub::Result;
250 /// async fn sample(
251 /// client: &TopicAdmin
252 /// ) -> Result<()> {
253 /// let response = client.list_topic_snapshots()
254 /// /* set fields */
255 /// .send().await?;
256 /// println!("response {:?}", response);
257 /// Ok(())
258 /// }
259 /// ```
260 pub fn list_topic_snapshots(&self) -> super::builder::topic_admin::ListTopicSnapshots {
261 super::builder::topic_admin::ListTopicSnapshots::new(self.inner.clone())
262 }
263
264 /// Deletes the topic with the given name. Returns `NOT_FOUND` if the topic
265 /// does not exist. After a topic is deleted, a new topic may be created with
266 /// the same name; this is an entirely new topic with none of the old
267 /// configuration or subscriptions. Existing subscriptions to this topic are
268 /// not deleted, but their `topic` field is set to `_deleted-topic_`.
269 ///
270 /// # Example
271 /// ```
272 /// # use google_cloud_pubsub::client::TopicAdmin;
273 /// use google_cloud_pubsub::Result;
274 /// async fn sample(
275 /// client: &TopicAdmin, project_id: &str, topic_id: &str
276 /// ) -> Result<()> {
277 /// client.delete_topic()
278 /// .set_topic(format!("projects/{project_id}/topics/{topic_id}"))
279 /// .send().await?;
280 /// Ok(())
281 /// }
282 /// ```
283 pub fn delete_topic(&self) -> super::builder::topic_admin::DeleteTopic {
284 super::builder::topic_admin::DeleteTopic::new(self.inner.clone())
285 }
286
287 /// Detaches a subscription from this topic. All messages retained in the
288 /// subscription are dropped. Subsequent `Pull` and `StreamingPull` requests
289 /// will return FAILED_PRECONDITION. If the subscription is a push
290 /// subscription, pushes to the endpoint will stop.
291 ///
292 /// # Example
293 /// ```
294 /// # use google_cloud_pubsub::client::TopicAdmin;
295 /// use google_cloud_pubsub::Result;
296 /// async fn sample(
297 /// client: &TopicAdmin
298 /// ) -> Result<()> {
299 /// let response = client.detach_subscription()
300 /// /* set fields */
301 /// .send().await?;
302 /// println!("response {:?}", response);
303 /// Ok(())
304 /// }
305 /// ```
306 pub fn detach_subscription(&self) -> super::builder::topic_admin::DetachSubscription {
307 super::builder::topic_admin::DetachSubscription::new(self.inner.clone())
308 }
309}
310
311/// Implements a client for the Cloud Pub/Sub API.
312///
313/// # Example
314/// ```
315/// # use google_cloud_pubsub::client::SubscriptionAdmin;
316/// async fn sample(
317/// project_id: &str,
318/// subscription_id: &str,
319/// ) -> anyhow::Result<()> {
320/// let client = SubscriptionAdmin::builder().build().await?;
321/// let response = client.get_subscription()
322/// .set_subscription(format!("projects/{project_id}/subscriptions/{subscription_id}"))
323/// .send().await?;
324/// println!("response {:?}", response);
325/// Ok(())
326/// }
327/// ```
328///
329/// # Service Description
330///
331/// The service that an application uses to manipulate subscriptions.
332///
333/// # Configuration
334///
335/// To configure `SubscriptionAdmin` use the `with_*` methods in the type returned
336/// by [builder()][SubscriptionAdmin::builder]. The default configuration should
337/// work for most applications. Common configuration changes include
338///
339/// * [with_endpoint()]: by default this client uses the global default endpoint
340/// (`https://pubsub.googleapis.com`). Applications using regional
341/// endpoints or running in restricted networks (e.g. a network configured
342/// with [Private Google Access with VPC Service Controls]) may want to
343/// override this default.
344/// * [with_credentials()]: by default this client uses
345/// [Application Default Credentials]. Applications using custom
346/// authentication may need to override this default.
347///
348/// [with_endpoint()]: super::builder::subscription_admin::ClientBuilder::with_endpoint
349/// [with_credentials()]: super::builder::subscription_admin::ClientBuilder::with_credentials
350/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
351/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
352///
353/// # Pooling and Cloning
354///
355/// `SubscriptionAdmin` holds a connection pool internally, it is advised to
356/// create one and reuse it. You do not need to wrap `SubscriptionAdmin` in
357/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
358/// already uses an `Arc` internally.
359#[derive(Clone, Debug)]
360pub struct SubscriptionAdmin {
361 inner: std::sync::Arc<dyn super::stub::dynamic::SubscriptionAdmin>,
362}
363
364impl SubscriptionAdmin {
365 /// Returns a builder for [SubscriptionAdmin].
366 ///
367 /// ```
368 /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
369 /// # use google_cloud_pubsub::client::SubscriptionAdmin;
370 /// let client = SubscriptionAdmin::builder().build().await?;
371 /// # Ok(()) }
372 /// ```
373 pub fn builder() -> super::builder::subscription_admin::ClientBuilder {
374 crate::new_client_builder(super::builder::subscription_admin::client::Factory)
375 }
376
377 /// Creates a new client from the provided stub.
378 ///
379 /// The most common case for calling this function is in tests mocking the
380 /// client's behavior.
381 pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
382 where
383 T: super::stub::SubscriptionAdmin + 'static,
384 {
385 Self { inner: stub.into() }
386 }
387
388 pub(crate) async fn new(
389 config: gaxi::options::ClientConfig,
390 ) -> crate::ClientBuilderResult<Self> {
391 let inner = Self::build_inner(config).await?;
392 Ok(Self { inner })
393 }
394
395 async fn build_inner(
396 conf: gaxi::options::ClientConfig,
397 ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::SubscriptionAdmin>>
398 {
399 if gaxi::options::tracing_enabled(&conf) {
400 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
401 }
402 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
403 }
404
405 async fn build_transport(
406 conf: gaxi::options::ClientConfig,
407 ) -> crate::ClientBuilderResult<impl super::stub::SubscriptionAdmin> {
408 super::transport::SubscriptionAdmin::new(conf).await
409 }
410
411 async fn build_with_tracing(
412 conf: gaxi::options::ClientConfig,
413 ) -> crate::ClientBuilderResult<impl super::stub::SubscriptionAdmin> {
414 Self::build_transport(conf)
415 .await
416 .map(super::tracing::SubscriptionAdmin::new)
417 }
418
419 /// Creates a subscription to a given topic. See the [resource name rules]
420 /// (<https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names>).
421 /// If the subscription already exists, returns `ALREADY_EXISTS`.
422 /// If the corresponding topic doesn't exist, returns `NOT_FOUND`.
423 ///
424 /// If the name is not provided in the request, the server will assign a random
425 /// name for this subscription on the same project as the topic, conforming
426 /// to the [resource name format]
427 /// (<https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names>). The
428 /// generated name is populated in the returned Subscription object. Note that
429 /// for REST API requests, you must specify a name in the request.
430 ///
431 /// # Example
432 /// ```
433 /// # use google_cloud_pubsub::client::SubscriptionAdmin;
434 /// use google_cloud_pubsub::Result;
435 /// async fn sample(
436 /// client: &SubscriptionAdmin
437 /// ) -> Result<()> {
438 /// let response = client.create_subscription()
439 /// /* set fields */
440 /// .send().await?;
441 /// println!("response {:?}", response);
442 /// Ok(())
443 /// }
444 /// ```
445 pub fn create_subscription(&self) -> super::builder::subscription_admin::CreateSubscription {
446 super::builder::subscription_admin::CreateSubscription::new(self.inner.clone())
447 }
448
449 /// Gets the configuration details of a subscription.
450 ///
451 /// # Example
452 /// ```
453 /// # use google_cloud_pubsub::client::SubscriptionAdmin;
454 /// use google_cloud_pubsub::Result;
455 /// async fn sample(
456 /// client: &SubscriptionAdmin, project_id: &str, subscription_id: &str
457 /// ) -> Result<()> {
458 /// let response = client.get_subscription()
459 /// .set_subscription(format!("projects/{project_id}/subscriptions/{subscription_id}"))
460 /// .send().await?;
461 /// println!("response {:?}", response);
462 /// Ok(())
463 /// }
464 /// ```
465 pub fn get_subscription(&self) -> super::builder::subscription_admin::GetSubscription {
466 super::builder::subscription_admin::GetSubscription::new(self.inner.clone())
467 }
468
469 /// Updates an existing subscription by updating the fields specified in the
470 /// update mask. Note that certain properties of a subscription, such as its
471 /// topic, are not modifiable.
472 ///
473 /// # Example
474 /// ```
475 /// # use google_cloud_pubsub::client::SubscriptionAdmin;
476 /// # extern crate wkt as google_cloud_wkt;
477 /// use google_cloud_wkt::FieldMask;
478 /// use google_cloud_pubsub::model::Subscription;
479 /// use google_cloud_pubsub::Result;
480 /// async fn sample(
481 /// client: &SubscriptionAdmin, project_id: &str, subscription_id: &str
482 /// ) -> Result<()> {
483 /// let response = client.update_subscription()
484 /// .set_subscription(
485 /// Subscription::new().set_name(format!("projects/{project_id}/subscriptions/{subscription_id}"))/* set fields */
486 /// )
487 /// .set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
488 /// .send().await?;
489 /// println!("response {:?}", response);
490 /// Ok(())
491 /// }
492 /// ```
493 pub fn update_subscription(&self) -> super::builder::subscription_admin::UpdateSubscription {
494 super::builder::subscription_admin::UpdateSubscription::new(self.inner.clone())
495 }
496
497 /// Lists matching subscriptions.
498 ///
499 /// # Example
500 /// ```
501 /// # use google_cloud_pubsub::client::SubscriptionAdmin;
502 /// use google_cloud_gax::paginator::ItemPaginator as _;
503 /// use google_cloud_pubsub::Result;
504 /// async fn sample(
505 /// client: &SubscriptionAdmin
506 /// ) -> Result<()> {
507 /// let mut list = client.list_subscriptions()
508 /// /* set fields */
509 /// .by_item();
510 /// while let Some(item) = list.next().await.transpose()? {
511 /// println!("{:?}", item);
512 /// }
513 /// Ok(())
514 /// }
515 /// ```
516 pub fn list_subscriptions(&self) -> super::builder::subscription_admin::ListSubscriptions {
517 super::builder::subscription_admin::ListSubscriptions::new(self.inner.clone())
518 }
519
520 /// Deletes an existing subscription. All messages retained in the subscription
521 /// are immediately dropped. Calls to `Pull` after deletion will return
522 /// `NOT_FOUND`. After a subscription is deleted, a new one may be created with
523 /// the same name, but the new one has no association with the old
524 /// subscription or its topic unless the same topic is specified.
525 ///
526 /// # Example
527 /// ```
528 /// # use google_cloud_pubsub::client::SubscriptionAdmin;
529 /// use google_cloud_pubsub::Result;
530 /// async fn sample(
531 /// client: &SubscriptionAdmin, project_id: &str, subscription_id: &str
532 /// ) -> Result<()> {
533 /// client.delete_subscription()
534 /// .set_subscription(format!("projects/{project_id}/subscriptions/{subscription_id}"))
535 /// .send().await?;
536 /// Ok(())
537 /// }
538 /// ```
539 pub fn delete_subscription(&self) -> super::builder::subscription_admin::DeleteSubscription {
540 super::builder::subscription_admin::DeleteSubscription::new(self.inner.clone())
541 }
542
543 /// Modifies the `PushConfig` for a specified subscription.
544 ///
545 /// This may be used to change a push subscription to a pull one (signified by
546 /// an empty `PushConfig`) or vice versa, or change the endpoint URL and other
547 /// attributes of a push subscription. Messages will accumulate for delivery
548 /// continuously through the call regardless of changes to the `PushConfig`.
549 ///
550 /// # Example
551 /// ```
552 /// # use google_cloud_pubsub::client::SubscriptionAdmin;
553 /// use google_cloud_pubsub::Result;
554 /// async fn sample(
555 /// client: &SubscriptionAdmin
556 /// ) -> Result<()> {
557 /// client.modify_push_config()
558 /// /* set fields */
559 /// .send().await?;
560 /// Ok(())
561 /// }
562 /// ```
563 pub fn modify_push_config(&self) -> super::builder::subscription_admin::ModifyPushConfig {
564 super::builder::subscription_admin::ModifyPushConfig::new(self.inner.clone())
565 }
566
567 /// Gets the configuration details of a snapshot. Snapshots are used in
568 /// [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations,
569 /// which allow you to manage message acknowledgments in bulk. That is, you can
570 /// set the acknowledgment state of messages in an existing subscription to the
571 /// state captured by a snapshot.
572 ///
573 /// # Example
574 /// ```
575 /// # use google_cloud_pubsub::client::SubscriptionAdmin;
576 /// use google_cloud_pubsub::Result;
577 /// async fn sample(
578 /// client: &SubscriptionAdmin, project_id: &str, snapshot_id: &str
579 /// ) -> Result<()> {
580 /// let response = client.get_snapshot()
581 /// .set_snapshot(format!("projects/{project_id}/snapshots/{snapshot_id}"))
582 /// .send().await?;
583 /// println!("response {:?}", response);
584 /// Ok(())
585 /// }
586 /// ```
587 pub fn get_snapshot(&self) -> super::builder::subscription_admin::GetSnapshot {
588 super::builder::subscription_admin::GetSnapshot::new(self.inner.clone())
589 }
590
591 /// Lists the existing snapshots. Snapshots are used in [Seek](
592 /// <https://cloud.google.com/pubsub/docs/replay-overview>) operations, which
593 /// allow you to manage message acknowledgments in bulk. That is, you can set
594 /// the acknowledgment state of messages in an existing subscription to the
595 /// state captured by a snapshot.
596 ///
597 /// # Example
598 /// ```
599 /// # use google_cloud_pubsub::client::SubscriptionAdmin;
600 /// use google_cloud_gax::paginator::ItemPaginator as _;
601 /// use google_cloud_pubsub::Result;
602 /// async fn sample(
603 /// client: &SubscriptionAdmin
604 /// ) -> Result<()> {
605 /// let mut list = client.list_snapshots()
606 /// /* set fields */
607 /// .by_item();
608 /// while let Some(item) = list.next().await.transpose()? {
609 /// println!("{:?}", item);
610 /// }
611 /// Ok(())
612 /// }
613 /// ```
614 pub fn list_snapshots(&self) -> super::builder::subscription_admin::ListSnapshots {
615 super::builder::subscription_admin::ListSnapshots::new(self.inner.clone())
616 }
617
618 /// Creates a snapshot from the requested subscription. Snapshots are used in
619 /// [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations,
620 /// which allow you to manage message acknowledgments in bulk. That is, you can
621 /// set the acknowledgment state of messages in an existing subscription to the
622 /// state captured by a snapshot.
623 /// If the snapshot already exists, returns `ALREADY_EXISTS`.
624 /// If the requested subscription doesn't exist, returns `NOT_FOUND`.
625 /// If the backlog in the subscription is too old -- and the resulting snapshot
626 /// would expire in less than 1 hour -- then `FAILED_PRECONDITION` is returned.
627 /// See also the `Snapshot.expire_time` field. If the name is not provided in
628 /// the request, the server will assign a random
629 /// name for this snapshot on the same project as the subscription, conforming
630 /// to the [resource name format]
631 /// (<https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names>). The
632 /// generated name is populated in the returned Snapshot object. Note that for
633 /// REST API requests, you must specify a name in the request.
634 ///
635 /// # Example
636 /// ```
637 /// # use google_cloud_pubsub::client::SubscriptionAdmin;
638 /// use google_cloud_pubsub::Result;
639 /// async fn sample(
640 /// client: &SubscriptionAdmin
641 /// ) -> Result<()> {
642 /// let response = client.create_snapshot()
643 /// /* set fields */
644 /// .send().await?;
645 /// println!("response {:?}", response);
646 /// Ok(())
647 /// }
648 /// ```
649 pub fn create_snapshot(&self) -> super::builder::subscription_admin::CreateSnapshot {
650 super::builder::subscription_admin::CreateSnapshot::new(self.inner.clone())
651 }
652
653 /// Updates an existing snapshot by updating the fields specified in the update
654 /// mask. Snapshots are used in
655 /// [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations,
656 /// which allow you to manage message acknowledgments in bulk. That is, you can
657 /// set the acknowledgment state of messages in an existing subscription to the
658 /// state captured by a snapshot.
659 ///
660 /// # Example
661 /// ```
662 /// # use google_cloud_pubsub::client::SubscriptionAdmin;
663 /// # extern crate wkt as google_cloud_wkt;
664 /// use google_cloud_wkt::FieldMask;
665 /// use google_cloud_pubsub::model::Snapshot;
666 /// use google_cloud_pubsub::Result;
667 /// async fn sample(
668 /// client: &SubscriptionAdmin, project_id: &str, snapshot_id: &str
669 /// ) -> Result<()> {
670 /// let response = client.update_snapshot()
671 /// .set_snapshot(
672 /// Snapshot::new().set_name(format!("projects/{project_id}/snapshots/{snapshot_id}"))/* set fields */
673 /// )
674 /// .set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
675 /// .send().await?;
676 /// println!("response {:?}", response);
677 /// Ok(())
678 /// }
679 /// ```
680 pub fn update_snapshot(&self) -> super::builder::subscription_admin::UpdateSnapshot {
681 super::builder::subscription_admin::UpdateSnapshot::new(self.inner.clone())
682 }
683
684 /// Removes an existing snapshot. Snapshots are used in [Seek]
685 /// (<https://cloud.google.com/pubsub/docs/replay-overview>) operations, which
686 /// allow you to manage message acknowledgments in bulk. That is, you can set
687 /// the acknowledgment state of messages in an existing subscription to the
688 /// state captured by a snapshot.
689 /// When the snapshot is deleted, all messages retained in the snapshot
690 /// are immediately dropped. After a snapshot is deleted, a new one may be
691 /// created with the same name, but the new one has no association with the old
692 /// snapshot or its subscription, unless the same subscription is specified.
693 ///
694 /// # Example
695 /// ```
696 /// # use google_cloud_pubsub::client::SubscriptionAdmin;
697 /// use google_cloud_pubsub::Result;
698 /// async fn sample(
699 /// client: &SubscriptionAdmin, project_id: &str, snapshot_id: &str
700 /// ) -> Result<()> {
701 /// client.delete_snapshot()
702 /// .set_snapshot(format!("projects/{project_id}/snapshots/{snapshot_id}"))
703 /// .send().await?;
704 /// Ok(())
705 /// }
706 /// ```
707 pub fn delete_snapshot(&self) -> super::builder::subscription_admin::DeleteSnapshot {
708 super::builder::subscription_admin::DeleteSnapshot::new(self.inner.clone())
709 }
710
711 /// Seeks an existing subscription to a point in time or to a given snapshot,
712 /// whichever is provided in the request. Snapshots are used in [Seek]
713 /// (<https://cloud.google.com/pubsub/docs/replay-overview>) operations, which
714 /// allow you to manage message acknowledgments in bulk. That is, you can set
715 /// the acknowledgment state of messages in an existing subscription to the
716 /// state captured by a snapshot. Note that both the subscription and the
717 /// snapshot must be on the same topic.
718 ///
719 /// # Example
720 /// ```
721 /// # use google_cloud_pubsub::client::SubscriptionAdmin;
722 /// use google_cloud_pubsub::Result;
723 /// async fn sample(
724 /// client: &SubscriptionAdmin
725 /// ) -> Result<()> {
726 /// let response = client.seek()
727 /// /* set fields */
728 /// .send().await?;
729 /// println!("response {:?}", response);
730 /// Ok(())
731 /// }
732 /// ```
733 pub fn seek(&self) -> super::builder::subscription_admin::Seek {
734 super::builder::subscription_admin::Seek::new(self.inner.clone())
735 }
736}
737
738/// Implements a client for the Cloud Pub/Sub API.
739///
740/// # Example
741/// ```
742/// # use google_cloud_pubsub::client::SchemaService;
743/// use google_cloud_gax::paginator::ItemPaginator as _;
744/// async fn sample(
745/// parent: &str,
746/// ) -> anyhow::Result<()> {
747/// let client = SchemaService::builder().build().await?;
748/// let mut list = client.list_schemas()
749/// .set_parent(parent)
750/// .by_item();
751/// while let Some(item) = list.next().await.transpose()? {
752/// println!("{:?}", item);
753/// }
754/// Ok(())
755/// }
756/// ```
757///
758/// # Service Description
759///
760/// Service for doing schema-related operations.
761///
762/// # Configuration
763///
764/// To configure `SchemaService` use the `with_*` methods in the type returned
765/// by [builder()][SchemaService::builder]. The default configuration should
766/// work for most applications. Common configuration changes include
767///
768/// * [with_endpoint()]: by default this client uses the global default endpoint
769/// (`https://pubsub.googleapis.com`). Applications using regional
770/// endpoints or running in restricted networks (e.g. a network configured
771/// with [Private Google Access with VPC Service Controls]) may want to
772/// override this default.
773/// * [with_credentials()]: by default this client uses
774/// [Application Default Credentials]. Applications using custom
775/// authentication may need to override this default.
776///
777/// [with_endpoint()]: super::builder::schema_service::ClientBuilder::with_endpoint
778/// [with_credentials()]: super::builder::schema_service::ClientBuilder::with_credentials
779/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
780/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
781///
782/// # Pooling and Cloning
783///
784/// `SchemaService` holds a connection pool internally, it is advised to
785/// create one and reuse it. You do not need to wrap `SchemaService` in
786/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
787/// already uses an `Arc` internally.
788#[derive(Clone, Debug)]
789pub struct SchemaService {
790 inner: std::sync::Arc<dyn super::stub::dynamic::SchemaService>,
791}
792
793impl SchemaService {
794 /// Returns a builder for [SchemaService].
795 ///
796 /// ```
797 /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
798 /// # use google_cloud_pubsub::client::SchemaService;
799 /// let client = SchemaService::builder().build().await?;
800 /// # Ok(()) }
801 /// ```
802 pub fn builder() -> super::builder::schema_service::ClientBuilder {
803 crate::new_client_builder(super::builder::schema_service::client::Factory)
804 }
805
806 /// Creates a new client from the provided stub.
807 ///
808 /// The most common case for calling this function is in tests mocking the
809 /// client's behavior.
810 pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
811 where
812 T: super::stub::SchemaService + 'static,
813 {
814 Self { inner: stub.into() }
815 }
816
817 pub(crate) async fn new(
818 config: gaxi::options::ClientConfig,
819 ) -> crate::ClientBuilderResult<Self> {
820 let inner = Self::build_inner(config).await?;
821 Ok(Self { inner })
822 }
823
824 async fn build_inner(
825 conf: gaxi::options::ClientConfig,
826 ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::SchemaService>> {
827 if gaxi::options::tracing_enabled(&conf) {
828 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
829 }
830 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
831 }
832
833 async fn build_transport(
834 conf: gaxi::options::ClientConfig,
835 ) -> crate::ClientBuilderResult<impl super::stub::SchemaService> {
836 super::transport::SchemaService::new(conf).await
837 }
838
839 async fn build_with_tracing(
840 conf: gaxi::options::ClientConfig,
841 ) -> crate::ClientBuilderResult<impl super::stub::SchemaService> {
842 Self::build_transport(conf)
843 .await
844 .map(super::tracing::SchemaService::new)
845 }
846
847 /// Creates a schema.
848 ///
849 /// # Example
850 /// ```
851 /// # use google_cloud_pubsub::client::SchemaService;
852 /// use google_cloud_pubsub::model::Schema;
853 /// use google_cloud_pubsub::Result;
854 /// async fn sample(
855 /// client: &SchemaService, project_id: &str
856 /// ) -> Result<()> {
857 /// let response = client.create_schema()
858 /// .set_parent(format!("projects/{project_id}"))
859 /// .set_schema_id("schema_id_value")
860 /// .set_schema(
861 /// Schema::new()/* set fields */
862 /// )
863 /// .send().await?;
864 /// println!("response {:?}", response);
865 /// Ok(())
866 /// }
867 /// ```
868 pub fn create_schema(&self) -> super::builder::schema_service::CreateSchema {
869 super::builder::schema_service::CreateSchema::new(self.inner.clone())
870 }
871
872 /// Gets a schema.
873 ///
874 /// # Example
875 /// ```
876 /// # use google_cloud_pubsub::client::SchemaService;
877 /// use google_cloud_pubsub::Result;
878 /// async fn sample(
879 /// client: &SchemaService, project_id: &str, schema_id: &str
880 /// ) -> Result<()> {
881 /// let response = client.get_schema()
882 /// .set_name(format!("projects/{project_id}/schemas/{schema_id}"))
883 /// .send().await?;
884 /// println!("response {:?}", response);
885 /// Ok(())
886 /// }
887 /// ```
888 pub fn get_schema(&self) -> super::builder::schema_service::GetSchema {
889 super::builder::schema_service::GetSchema::new(self.inner.clone())
890 }
891
892 /// Lists schemas in a project.
893 ///
894 /// # Example
895 /// ```
896 /// # use google_cloud_pubsub::client::SchemaService;
897 /// use google_cloud_gax::paginator::ItemPaginator as _;
898 /// use google_cloud_pubsub::Result;
899 /// async fn sample(
900 /// client: &SchemaService, parent: &str
901 /// ) -> Result<()> {
902 /// let mut list = client.list_schemas()
903 /// .set_parent(parent)
904 /// .by_item();
905 /// while let Some(item) = list.next().await.transpose()? {
906 /// println!("{:?}", item);
907 /// }
908 /// Ok(())
909 /// }
910 /// ```
911 pub fn list_schemas(&self) -> super::builder::schema_service::ListSchemas {
912 super::builder::schema_service::ListSchemas::new(self.inner.clone())
913 }
914
915 /// Lists all schema revisions for the named schema.
916 ///
917 /// # Example
918 /// ```
919 /// # use google_cloud_pubsub::client::SchemaService;
920 /// use google_cloud_gax::paginator::ItemPaginator as _;
921 /// use google_cloud_pubsub::Result;
922 /// async fn sample(
923 /// client: &SchemaService
924 /// ) -> Result<()> {
925 /// let mut list = client.list_schema_revisions()
926 /// /* set fields */
927 /// .by_item();
928 /// while let Some(item) = list.next().await.transpose()? {
929 /// println!("{:?}", item);
930 /// }
931 /// Ok(())
932 /// }
933 /// ```
934 pub fn list_schema_revisions(&self) -> super::builder::schema_service::ListSchemaRevisions {
935 super::builder::schema_service::ListSchemaRevisions::new(self.inner.clone())
936 }
937
938 /// Commits a new schema revision to an existing schema.
939 ///
940 /// # Example
941 /// ```
942 /// # use google_cloud_pubsub::client::SchemaService;
943 /// use google_cloud_pubsub::Result;
944 /// async fn sample(
945 /// client: &SchemaService
946 /// ) -> Result<()> {
947 /// let response = client.commit_schema()
948 /// /* set fields */
949 /// .send().await?;
950 /// println!("response {:?}", response);
951 /// Ok(())
952 /// }
953 /// ```
954 pub fn commit_schema(&self) -> super::builder::schema_service::CommitSchema {
955 super::builder::schema_service::CommitSchema::new(self.inner.clone())
956 }
957
958 /// Creates a new schema revision that is a copy of the provided revision_id.
959 ///
960 /// # Example
961 /// ```
962 /// # use google_cloud_pubsub::client::SchemaService;
963 /// use google_cloud_pubsub::Result;
964 /// async fn sample(
965 /// client: &SchemaService
966 /// ) -> Result<()> {
967 /// let response = client.rollback_schema()
968 /// /* set fields */
969 /// .send().await?;
970 /// println!("response {:?}", response);
971 /// Ok(())
972 /// }
973 /// ```
974 pub fn rollback_schema(&self) -> super::builder::schema_service::RollbackSchema {
975 super::builder::schema_service::RollbackSchema::new(self.inner.clone())
976 }
977
978 /// Deletes a specific schema revision.
979 ///
980 /// # Example
981 /// ```
982 /// # use google_cloud_pubsub::client::SchemaService;
983 /// use google_cloud_pubsub::Result;
984 /// async fn sample(
985 /// client: &SchemaService, project_id: &str, schema_id: &str
986 /// ) -> Result<()> {
987 /// let response = client.delete_schema_revision()
988 /// .set_name(format!("projects/{project_id}/schemas/{schema_id}"))
989 /// .send().await?;
990 /// println!("response {:?}", response);
991 /// Ok(())
992 /// }
993 /// ```
994 pub fn delete_schema_revision(&self) -> super::builder::schema_service::DeleteSchemaRevision {
995 super::builder::schema_service::DeleteSchemaRevision::new(self.inner.clone())
996 }
997
998 /// Deletes a schema.
999 ///
1000 /// # Example
1001 /// ```
1002 /// # use google_cloud_pubsub::client::SchemaService;
1003 /// use google_cloud_pubsub::Result;
1004 /// async fn sample(
1005 /// client: &SchemaService, project_id: &str, schema_id: &str
1006 /// ) -> Result<()> {
1007 /// client.delete_schema()
1008 /// .set_name(format!("projects/{project_id}/schemas/{schema_id}"))
1009 /// .send().await?;
1010 /// Ok(())
1011 /// }
1012 /// ```
1013 pub fn delete_schema(&self) -> super::builder::schema_service::DeleteSchema {
1014 super::builder::schema_service::DeleteSchema::new(self.inner.clone())
1015 }
1016
1017 /// Validates a schema.
1018 ///
1019 /// # Example
1020 /// ```
1021 /// # use google_cloud_pubsub::client::SchemaService;
1022 /// use google_cloud_pubsub::Result;
1023 /// async fn sample(
1024 /// client: &SchemaService
1025 /// ) -> Result<()> {
1026 /// let response = client.validate_schema()
1027 /// /* set fields */
1028 /// .send().await?;
1029 /// println!("response {:?}", response);
1030 /// Ok(())
1031 /// }
1032 /// ```
1033 pub fn validate_schema(&self) -> super::builder::schema_service::ValidateSchema {
1034 super::builder::schema_service::ValidateSchema::new(self.inner.clone())
1035 }
1036
1037 /// Validates a message against a schema.
1038 ///
1039 /// # Example
1040 /// ```
1041 /// # use google_cloud_pubsub::client::SchemaService;
1042 /// use google_cloud_pubsub::Result;
1043 /// async fn sample(
1044 /// client: &SchemaService
1045 /// ) -> Result<()> {
1046 /// let response = client.validate_message()
1047 /// /* set fields */
1048 /// .send().await?;
1049 /// println!("response {:?}", response);
1050 /// Ok(())
1051 /// }
1052 /// ```
1053 pub fn validate_message(&self) -> super::builder::schema_service::ValidateMessage {
1054 super::builder::schema_service::ValidateMessage::new(self.inner.clone())
1055 }
1056
1057 /// Sets the access control policy on the specified resource. Replaces
1058 /// any existing policy.
1059 ///
1060 /// Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED`
1061 /// errors.
1062 ///
1063 /// # Example
1064 /// ```
1065 /// # use google_cloud_pubsub::client::SchemaService;
1066 /// use google_cloud_pubsub::Result;
1067 /// async fn sample(
1068 /// client: &SchemaService
1069 /// ) -> Result<()> {
1070 /// let response = client.set_iam_policy()
1071 /// /* set fields */
1072 /// .send().await?;
1073 /// println!("response {:?}", response);
1074 /// Ok(())
1075 /// }
1076 /// ```
1077 pub fn set_iam_policy(&self) -> super::builder::schema_service::SetIamPolicy {
1078 super::builder::schema_service::SetIamPolicy::new(self.inner.clone())
1079 }
1080
1081 /// Gets the access control policy for a resource. Returns an empty policy
1082 /// if the resource exists and does not have a policy set.
1083 ///
1084 /// # Example
1085 /// ```
1086 /// # use google_cloud_pubsub::client::SchemaService;
1087 /// use google_cloud_pubsub::Result;
1088 /// async fn sample(
1089 /// client: &SchemaService
1090 /// ) -> Result<()> {
1091 /// let response = client.get_iam_policy()
1092 /// /* set fields */
1093 /// .send().await?;
1094 /// println!("response {:?}", response);
1095 /// Ok(())
1096 /// }
1097 /// ```
1098 pub fn get_iam_policy(&self) -> super::builder::schema_service::GetIamPolicy {
1099 super::builder::schema_service::GetIamPolicy::new(self.inner.clone())
1100 }
1101
1102 /// Returns permissions that a caller has on the specified resource. If the
1103 /// resource does not exist, this will return an empty set of
1104 /// permissions, not a `NOT_FOUND` error.
1105 ///
1106 /// Note: This operation is designed to be used for building
1107 /// permission-aware UIs and command-line tools, not for authorization
1108 /// checking. This operation may "fail open" without warning.
1109 ///
1110 /// # Example
1111 /// ```
1112 /// # use google_cloud_pubsub::client::SchemaService;
1113 /// use google_cloud_pubsub::Result;
1114 /// async fn sample(
1115 /// client: &SchemaService
1116 /// ) -> Result<()> {
1117 /// let response = client.test_iam_permissions()
1118 /// /* set fields */
1119 /// .send().await?;
1120 /// println!("response {:?}", response);
1121 /// Ok(())
1122 /// }
1123 /// ```
1124 pub fn test_iam_permissions(&self) -> super::builder::schema_service::TestIamPermissions {
1125 super::builder::schema_service::TestIamPermissions::new(self.inner.clone())
1126 }
1127}