- Lab
- A Cloud Guru
Utilizing Google Cloud Pub/Sub
Cloud Pub/Sub is Google Cloud's central fully managed messaging service. Being central, it is consequently incorporated in a lot of different workflows. Pub/Sub can be used to stream data to BigQuery, Cloud Functions, Stackdriver, Cloud IoT Core, and numerous other services. This hands-on lab will provide you with practical experience working with the necessary components of Cloud Pub/Sub: topics, subscriptions, and messages.
Path Info
Table of Contents
-
Challenge
Enable APIs
- From the main console navigation, go to APIs and Services > Library.
- Search for Pub/Sub.
- Select the Cloud Pub/Sub card.
- Click Enable, if displayed.
-
Challenge
Create a Topic
- From the main navigation, go to Pub/Sub > Topics.
- Click Create a topic.
- Enter a name for the topic (e.g., "acg-topic-1").
- Deselect Create a default subscription.
- Click Create.
-
Challenge
Create a Subscription
- Drill down into the topic just created and choose Subscriptions.
- Click the icon in the Topic details navigation bar to create a subscription.
- Enter a name for the subscription (e.g., "acg-sub-1").
- Set Delivery Type to Pull.
- Leave the rest of the settings at their defaults.
- Click Create.
-
Challenge
Publish a Message
- From the Topic details page, click Publish Message.
- Enter a message in the Message field.
- Click Publish.
-
Challenge
Retrieve Message
-
Activate the Cloud Shell by clicking its icon in the top row.
-
If the Cloud Shell does not display the current project ID in yellow, open the Project panel by clicking the project name in the upper-left.
-
Copy the current project ID.
-
In the Cloud Shell, enter the following command:
gcloud config set project <PROJECT_ID>
-
To retrieve a message, enter the following command:
gcloud pubsub subscriptions pull <SUBSCRIPTION_NAME> --auto-ack
-
Confirm the message displayed is the same as published.
-
Repeat the command again.
-
Confirm zero messages are found.
-
-
Challenge
Publish Multiple Messages
- From the Topic details page, click Publish Message.
- Enter a message in the Message field.
- Click Publish.
- Repeat steps 1-3 twice more.
-
Challenge
Retrieve Multiple Messages
-
In the Cloud Shell, enter the following command:
gcloud pubsub subscriptions pull <SUBSCRIPTION_NAME> --auto-ack --limit=3
-
Confirm all messages displayed are the same as were published.
-
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.