#google-cloud-platform #pub-sub #client #messages #publish #topic

gcp-pubsub

A surf-based Google Cloud Platform PubSub client

1 unstable release

0.1.0 Oct 21, 2019

#11 in #google-cloud-platform

MIT license

21KB
365 lines

gcp-pubsub

A crate that acts as a HTTP client to publish and read messages from Google Cloud Platform's PubSub.

Usage

Create a client

Authentication is provided by rust-goauth, which expects a path to the file containing your Google Cloud service account JSON key.

let google_credentials = std::env::var("GOOGLE_PUBSUB_CREDENTIALS").unwrap();
let mut client = gcp_pubsub::Client::new(credentials);

Create a topic

let topic = client.create_topic("my-topic").await;

Publish a message

#[derive(Serialize, Default)]
struct Foo {
  pub a: String,
}

let result: Result<(), Error> = topic.publish(Foo::default()).await;

Read messages

let subscription = topic.create_subscription().await.unwrap();
let messages : Result<Vec<gcp_pubsub::Message>, Error> = subscription.pull().await;

Dependencies

~25MB
~532K SLoC