Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pubsub: add publish_messages methods #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion google-cloud/src/pubsub/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ mod client;
mod message;
mod subscription;
mod topic;
mod api {

/// API proto structures
#[allow(missing_docs)]
pub mod api {
include!("api/google.pubsub.v1.rs");
}

Expand Down
27 changes: 19 additions & 8 deletions google-cloud/src/pubsub/topic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,34 @@ impl Topic {
}

/// Publish a message onto this topic.
pub async fn publish(&mut self, data: impl Into<Vec<u8>>) -> Result<(), Error> {
pub async fn publish_message(&mut self, msg: api::PubsubMessage) -> Result<(), Error> {
self.publish_messages(vec![msg]).await
}

/// Publish a message onto this topic.
pub async fn publish_messages(
&mut self,
messages: Vec<api::PubsubMessage>,
) -> Result<(), Error> {
let request = api::PublishRequest {
topic: self.name.clone(),
messages: vec![api::PubsubMessage {
data: data.into(),
attributes: HashMap::new(),
message_id: String::new(),
ordering_key: String::new(),
publish_time: None,
}],
messages,
};
let request = self.client.construct_request(request).await?;
self.client.publisher.publish(request).await?;

Ok(())
}

/// Publish a message onto this topic.
pub async fn publish(&mut self, data: impl Into<Vec<u8>>) -> Result<(), Error> {
self.publish_message(api::PubsubMessage {
data: data.into(),
..Default::default()
})
.await
}

/// Delete the topic.
pub async fn delete(mut self) -> Result<(), Error> {
let request = api::DeleteTopicRequest {
Expand Down