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