Utilizing Google Cloud Pub/Sub

30 minutes
  • 7 Learning Objectives

About this Hands-on Lab

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.
  1. From the main console navigation, go to APIs and Services > Library.
  2. Search for Pub/Sub.
  3. Select the Cloud Pub/Sub card.
  4. Click Enable, if displayed.
Create a topic.
  1. From the main navigation, go to Pub/Sub.
  2. Click Create a topic.
  3. Enter a name for the topic.
  4. Click Create.
Create a subscription.
  1. Drill down into the topic just created and choose Subscriptions.
  2. Enter a name for the subscription.
  3. Set Delivery Type to Pull.
  4. Click Create.
Publish a message.
  1. From the Topic details page, click Publish Message.
  2. Enter a message in the Message field.
  3. Click Publish.
Retrieve message.
  1. Activate the Cloud Shell by clicking its icon in the top row.

  2. In the Cloud Shell, enter the following command:
    gcloud pubsub subscriptions pull <SUBSCRIPTION_NAME> –auto-ack

  3. Confirm the message displayed is the same as published.

  4. Repeat the command again.

  5. Confirm no messages are found.

Publish multiple messages.
  1. From the Topic details page, click Publish Message.
  2. Enter a message in the Message field.
  3. Click Publish.
  4. Repeat steps 1-3 two more times.
Retrieve multiple messages.
  1. Activate the Cloud Shell by clicking its icon in the top row.

  2. In the Cloud Shell, enter the following command:
    gcloud pubsub subscriptions pull <SUBSCRIPTION_NAME> –auto-ack –limit=3

  3. Confirm all messages displayed are the same as were published.

Additional Resources

You’ve been asked to head up the new Cloud Pub/Sub team, responsible for incorporating the messaging service into various apps deployed across the Google Cloud platform. In order to understand how the system works, you’ll need to create a Cloud Pub/Sub topic, subscriber, and multiple messages. You’ll also need to retrieve the messages from the command line using the pertinent gcloud commands.

To accomplish this task, you’ll need to complete the following steps:

  1. Enable the appropriate APIs.
  2. Create a Cloud Pub/Sub topic.
  3. Create a Cloud Pub/Sub subscription.
  4. Publish a message.
  5. Retrieve the message.
  6. Publish multiple messages.
  7. Retrieve all messages.

What are Hands-on Labs

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.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?