google-cloud-pubsub 0.31.0-preview

Google Cloud Client Libraries for Rust - Pub/Sub
Documentation
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by sidekick. DO NOT EDIT.

#![allow(rustdoc::redundant_explicit_links)]
#![allow(rustdoc::broken_intra_doc_links)]

mod debug;
mod deserialize;
mod serialize;

/// A message that is published by publishers and consumed by subscribers. The
/// message must contain either a non-empty data field or at least one attribute.
/// Note that client libraries represent this object differently
/// depending on the language. See the corresponding [client library
/// documentation](https://cloud.google.com/pubsub/docs/reference/libraries) for
/// more information. See [quotas and limits]
/// (<https://cloud.google.com/pubsub/quotas>) for more information about message
/// limits.
#[derive(Clone, Default, PartialEq)]
#[non_exhaustive]
pub struct PubsubMessage {
    /// Optional. The message data field. If this field is empty, the message must
    /// contain at least one attribute.
    pub data: ::bytes::Bytes,

    /// Optional. Attributes for this message. If this field is empty, the message
    /// must contain non-empty data. This can be used to filter messages on the
    /// subscription.
    pub attributes: std::collections::HashMap<std::string::String, std::string::String>,

    /// ID of this message, assigned by the server when the message is published.
    /// Guaranteed to be unique within the topic. This value may be read by a
    /// subscriber that receives a `PubsubMessage` via a `Pull` call or a push
    /// delivery. It must not be populated by the publisher in a `Publish` call.
    pub message_id: std::string::String,

    /// The time at which the message was published, populated by the server when
    /// it receives the `Publish` call. It must not be populated by the
    /// publisher in a `Publish` call.
    pub publish_time: std::option::Option<wkt::Timestamp>,

    /// Optional. If non-empty, identifies related messages for which publish order
    /// should be respected. If a `Subscription` has `enable_message_ordering` set
    /// to `true`, messages published with the same non-empty `ordering_key` value
    /// will be delivered to subscribers in the order in which they are received by
    /// the Pub/Sub system. All `PubsubMessage`s published in a given
    /// `PublishRequest` must specify the same `ordering_key` value. For more
    /// information, see [ordering
    /// messages](https://cloud.google.com/pubsub/docs/ordering).
    pub ordering_key: std::string::String,

    pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
}

impl PubsubMessage {
    pub fn new() -> Self {
        std::default::Default::default()
    }

    /// Sets the value of [data][crate::model::PubsubMessage::data].
    pub fn set_data<T: std::convert::Into<::bytes::Bytes>>(mut self, v: T) -> Self {
        self.data = v.into();
        self
    }

    /// Sets the value of [attributes][crate::model::PubsubMessage::attributes].
    pub fn set_attributes<T, K, V>(mut self, v: T) -> Self
    where
        T: std::iter::IntoIterator<Item = (K, V)>,
        K: std::convert::Into<std::string::String>,
        V: std::convert::Into<std::string::String>,
    {
        use std::iter::Iterator;
        self.attributes = v.into_iter().map(|(k, v)| (k.into(), v.into())).collect();
        self
    }

    /// Sets the value of [message_id][crate::model::PubsubMessage::message_id].
    pub fn set_message_id<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.message_id = v.into();
        self
    }

    /// Sets the value of [publish_time][crate::model::PubsubMessage::publish_time].
    pub fn set_publish_time<T>(mut self, v: T) -> Self
    where
        T: std::convert::Into<wkt::Timestamp>,
    {
        self.publish_time = std::option::Option::Some(v.into());
        self
    }

    /// Sets or clears the value of [publish_time][crate::model::PubsubMessage::publish_time].
    pub fn set_or_clear_publish_time<T>(mut self, v: std::option::Option<T>) -> Self
    where
        T: std::convert::Into<wkt::Timestamp>,
    {
        self.publish_time = v.map(|x| x.into());
        self
    }

    /// Sets the value of [ordering_key][crate::model::PubsubMessage::ordering_key].
    pub fn set_ordering_key<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.ordering_key = v.into();
        self
    }
}

impl wkt::message::Message for PubsubMessage {
    fn typename() -> &'static str {
        "type.googleapis.com/google.pubsub.v1.PubsubMessage"
    }
}

/// Request for the Publish method.
#[derive(Clone, Default, PartialEq)]
#[non_exhaustive]
pub struct PublishRequest {
    /// Required. The messages in the request will be published on this topic.
    /// Format is `projects/{project}/topics/{topic}`.
    pub topic: std::string::String,

    /// Required. The messages to publish.
    pub messages: std::vec::Vec<crate::model::PubsubMessage>,

    pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
}

impl PublishRequest {
    pub fn new() -> Self {
        std::default::Default::default()
    }

    /// Sets the value of [topic][crate::model::PublishRequest::topic].
    pub fn set_topic<T: std::convert::Into<std::string::String>>(mut self, v: T) -> Self {
        self.topic = v.into();
        self
    }

    /// Sets the value of [messages][crate::model::PublishRequest::messages].
    pub fn set_messages<T, V>(mut self, v: T) -> Self
    where
        T: std::iter::IntoIterator<Item = V>,
        V: std::convert::Into<crate::model::PubsubMessage>,
    {
        use std::iter::Iterator;
        self.messages = v.into_iter().map(|i| i.into()).collect();
        self
    }
}

impl wkt::message::Message for PublishRequest {
    fn typename() -> &'static str {
        "type.googleapis.com/google.pubsub.v1.PublishRequest"
    }
}

/// Response for the `Publish` method.
#[derive(Clone, Default, PartialEq)]
#[non_exhaustive]
pub struct PublishResponse {
    /// Optional. The server-assigned ID of each published message, in the same
    /// order as the messages in the request. IDs are guaranteed to be unique
    /// within the topic.
    pub message_ids: std::vec::Vec<std::string::String>,

    pub(crate) _unknown_fields: serde_json::Map<std::string::String, serde_json::Value>,
}

impl PublishResponse {
    pub fn new() -> Self {
        std::default::Default::default()
    }

    /// Sets the value of [message_ids][crate::model::PublishResponse::message_ids].
    pub fn set_message_ids<T, V>(mut self, v: T) -> Self
    where
        T: std::iter::IntoIterator<Item = V>,
        V: std::convert::Into<std::string::String>,
    {
        use std::iter::Iterator;
        self.message_ids = v.into_iter().map(|i| i.into()).collect();
        self
    }
}

impl wkt::message::Message for PublishResponse {
    fn typename() -> &'static str {
        "type.googleapis.com/google.pubsub.v1.PublishResponse"
    }
}