pub struct Publisher { /* private fields */ }Expand description
A Publisher sends messages to a specific topic. It manages message batching
and sending in a background task.
Publishers are created via a Client.
let client = Client::builder().build().await?;
let publisher = client.publisher("projects/my-project/topics/my-topic").build();
let message_id = publisher.publish(PubsubMessage::new().set_data("Hello, World"));Implementations§
Source§impl Publisher
impl Publisher
Sourcepub fn publish(&self, msg: PubsubMessage) -> PublishHandle ⓘ
pub fn publish(&self, msg: PubsubMessage) -> PublishHandle ⓘ
Publishes a message to the topic.
let message_id = publisher.publish(PubsubMessage::new().set_data("Hello, World")).await?;Sourcepub async fn flush(&self)
pub async fn flush(&self)
Flushes all outstanding messages.
This method sends any messages that have been published but not yet sent,
regardless of the configured batching options (delay_threshold, etc.).
This method is async and returns only after all publish attempts for the
messages in the snapshot have completed. A “completed” attempt means the
message has either been successfully sent, or has failed permanently after
exhausting any applicable retry policies.
After flush()` returns, the final result of each individual publish operation (i.e., a success with a message ID or a terminal error) will be available on its corresponding PublishHandle.
Messages published after flush() is called will be buffered for a
subsequent batch and are not included in this flush operation.
§Example
// Publish some messages. They will be buffered according to batching options.
let handle1 = publisher.publish(PubsubMessage::new().set_data("foo".to_string()));
let handle2 = publisher.publish(PubsubMessage::new().set_data("bar".to_string()));
// Flush ensures that these messages are sent immediately and waits for
// the send to complete.
publisher.flush().await;
// The results for handle1 and handle2 are available.
let id1 = handle1.await?;
let id2 = handle2.await?;Trait Implementations§
Auto Trait Implementations§
impl Freeze for Publisher
impl RefUnwindSafe for Publisher
impl Send for Publisher
impl Sync for Publisher
impl Unpin for Publisher
impl UnwindSafe for Publisher
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request