#
google_cloud_pubsub/generated/gapic_dataplane/
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#[derive(Clone, Debug)]
    21pub struct Publisher {
    22    inner: std::sync::Arc<dyn super::stub::dynamic::Publisher>,
    23}
    24
    25impl Publisher {
    26    /// Creates a new client from the provided stub.
    27    ///
    28    /// The most common case for calling this function is in tests mocking the
    29    /// client's behavior.
    30    pub fn from_stub<T>(stub: T) -> Self
    31    where
    32        T: super::stub::Publisher + 'static,
    33    {
    34        Self {
    35            inner: std::sync::Arc::new(stub),
    36        }
    37    }
    38
    39    pub(crate) async fn new(
    40        config: gaxi::options::ClientConfig,
    41    ) -> gax::client_builder::Result<Self> {
    42        let inner = Self::build_inner(config).await?;
    43        Ok(Self { inner })
    44    }
    45
    46    async fn build_inner(
    47        conf: gaxi::options::ClientConfig,
    48    ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::Publisher>> {
    49        if gaxi::options::tracing_enabled(&conf) {
    50            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
    51        }
    52        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
    53    }
    54
    55    async fn build_transport(
    56        conf: gaxi::options::ClientConfig,
    57    ) -> gax::client_builder::Result<impl super::stub::Publisher> {
    58        super::transport::Publisher::new(conf).await
    59    }
    60
    61    async fn build_with_tracing(
    62        conf: gaxi::options::ClientConfig,
    63    ) -> gax::client_builder::Result<impl super::stub::Publisher> {
    64        Self::build_transport(conf)
    65            .await
    66            .map(super::tracing::Publisher::new)
    67    }
    68
    69    /// Adds one or more messages to the topic. Returns `NOT_FOUND` if the topic
    70    /// does not exist.
    71    pub fn publish(&self) -> super::builder::publisher::Publish {
    72        super::builder::publisher::Publish::new(self.inner.clone())
    73    }
    74}
    75
    76/// Implements a client for the Cloud Pub/Sub API.
    77#[derive(Clone, Debug)]
    78pub struct Subscriber {
    79    inner: std::sync::Arc<dyn super::stub::dynamic::Subscriber>,
    80}
    81
    82impl Subscriber {
    83    /// Creates a new client from the provided stub.
    84    ///
    85    /// The most common case for calling this function is in tests mocking the
    86    /// client's behavior.
    87    pub fn from_stub<T>(stub: T) -> Self
    88    where
    89        T: super::stub::Subscriber + 'static,
    90    {
    91        Self {
    92            inner: std::sync::Arc::new(stub),
    93        }
    94    }
    95
    96    pub(crate) async fn new(
    97        config: gaxi::options::ClientConfig,
    98    ) -> gax::client_builder::Result<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    ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::Subscriber>> {
    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    ) -> gax::client_builder::Result<impl super::stub::Subscriber> {
    115        super::transport::Subscriber::new(conf).await
    116    }
    117
    118    async fn build_with_tracing(
    119        conf: gaxi::options::ClientConfig,
    120    ) -> gax::client_builder::Result<impl super::stub::Subscriber> {
    121        Self::build_transport(conf)
    122            .await
    123            .map(super::tracing::Subscriber::new)
    124    }
    125
    126    /// Modifies the ack deadline for a specific message. This method is useful
    127    /// to indicate that more time is needed to process a message by the
    128    /// subscriber, or to make the message available for redelivery if the
    129    /// processing was interrupted. Note that this does not modify the
    130    /// subscription-level `ackDeadlineSeconds` used for subsequent messages.
    131    pub fn modify_ack_deadline(&self) -> super::builder::subscriber::ModifyAckDeadline {
    132        super::builder::subscriber::ModifyAckDeadline::new(self.inner.clone())
    133    }
    134
    135    /// Acknowledges the messages associated with the `ack_ids` in the
    136    /// `AcknowledgeRequest`. The Pub/Sub system can remove the relevant messages
    137    /// from the subscription.
    138    ///
    139    /// Acknowledging a message whose ack deadline has expired may succeed,
    140    /// but such a message may be redelivered later. Acknowledging a message more
    141    /// than once will not result in an error.
    142    pub fn acknowledge(&self) -> super::builder::subscriber::Acknowledge {
    143        super::builder::subscriber::Acknowledge::new(self.inner.clone())
    144    }
    145}