Google Cloud Pub/Sub is a messaging service for exchanging event data among applications and services. A producer of data publishes a messages to a Cloud Pub/Sub topic. A consumer creates a subscription to that topic. Subscribers either pull messages from a subscription or are configured as webhooks for push subscriptions. Every subscriber must acknowledge each message within a configurable window of time.
This page shows how to publish and consume messages with a pull subscriber.
Before you begin
gcloud command-line tool
You can use the
gcloud command-line tool to perform operations in Cloud Pub/Sub.
gcloud command-line tool is included in the Cloud SDK you installed in
Before you begin.
See the gcloud pubsub section in the
gcloud reference for a complete list
of Cloud Pub/Sub
This self-contained example, meant to run in bash, shows the steps required to create a topic, subscribe to it, publish a message to it, and receive the message:
gcloud init gcloud components install beta gcloud beta pubsub topics create myTopic gcloud beta pubsub subscriptions create --topic myTopic mySubscription gcloud beta pubsub topics publish myTopic "hello" gcloud beta pubsub subscriptions pull --auto-ack mySubscription
This example uses a pull subscription. Cloud Pub/Sub also supports push subscriptions, as described in the Subscriber guide.
You can perform all administrative operations through the API, and most through
gcloud tool and Cloud Platform Console UI.
Get started with Cloud Pub/Sub in your language of choice at Cloud Pub/Sub Client Libraries.
See Quickstart: Using Client Libraries for a walkthrough of how to use client library APIs to perform basic Cloud Pub/Sub tasks.
For a detailed overview of Cloud Pub/Sub, see What is Google Cloud Pub/Sub?