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.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- 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.
- Create a topic.
- From the main navigation, go to Pub/Sub.
- Click Create a topic.
- Enter a name for the topic.
- Click Create.
- Create a subscription.
- Drill down into the topic just created and choose Subscriptions.
- Enter a name for the subscription.
- Set Delivery Type to Pull.
- Click Create.
- Publish a message.
- From the Topic details page, click Publish Message.
- Enter a message in the Message field.
- Click Publish.
- Retrieve message.
Activate the Cloud Shell by clicking its icon in the top row.
In the Cloud Shell, enter the following command:
gcloud pubsub subscriptions pull <SUBSCRIPTION_NAME> –auto-ackConfirm the message displayed is the same as published.
Repeat the command again.
Confirm no messages are found.
- Publish multiple messages.
- From the Topic details page, click Publish Message.
- Enter a message in the Message field.
- Click Publish.
- Repeat steps 1-3 two more times.
- Retrieve multiple messages.
Activate the Cloud Shell by clicking its icon in the top row.
In the Cloud Shell, enter the following command:
gcloud pubsub subscriptions pull <SUBSCRIPTION_NAME> –auto-ack –limit=3Confirm all messages displayed are the same as were published.