Google Cloud: Introduction to Cloud Pub/Sub

Share At:


Google Cloud Pub/Sub is a messaging service for exchanging event data among applications and services. A producer of data publishes 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.

Lab Objective

  • Set up a topic to hold data.
  • Subscribe to a topic to access the data.
  • Publish and then consume messages with a pull subscriber.

Setting up Pub/Sub

You can use the Google Cloud Shell console to perform operations in Google Cloud Pub/Sub.

To use a Pub/Sub, you create a topic to hold data and a subscription to access data published to the topic.

  1. Click Navigation menu > Pub/Sub > Topics.

2. Click Create topic.

3. The topic must have a unique name. For this lab, name your topic MyTopic. In the Create a topic dialog:

  • For Topic ID, type MyTopic.
  • Leave Encryption at the default value.

You’ve created a topic.

Add a subscription

Now you’ll make a subscription to access the topic.

  1. Click Topics in the left panel to return to the Topics page. For the topic you just made click the three dot icon > Create subscription.

2. In the Add subscription to topic dialog:

  • Type a name for the subscription, such as MySub
  • Set the Delivery Type to Pull.
  • Leave all other options at the default values.
  • Click Create.

Your subscription is listed in the Subscription list.

Publish a message to the topic

  1. At the top of the Topics details dialog, click PUBLISH MESSAGE.

2. Enter Hello World in the Message field and click Publish.

View the message

To view the message you’ll use the subscription (MySub) to pull the message (Hello World) from the topic (MyTopic).

Enter the following command in command line.

gcloud pubsub subscriptions pull --auto-ack MySub

The message appears in the DATA field of the command output.

Congratulations !!!

You created a Pub/Sub topic, published to the topic, created a subscription, then used the subscription to pull data from the topic.

Happy Learning !!!

Share At:
0 0 votes
Article Rating
Notify of
1 Comment
Oldest Most Voted
Inline Feedbacks
View all comments
Dhiraj Kulkarni
Dhiraj Kulkarni
1 year ago

Very nicely explained. Content is also organised in a professional manner. Lot of options for quick navigation and search. Covers most of the hot topics in the market today.
I will certainly refer this blog site frequently.

Back To Top

Contact Us