Skip to main content

Utilizing Google Cloud Pub/Sub

Hands-On Lab

 

Photo of Joseph Lowery

Joseph Lowery

Google Cloud Training Architect II in Content

Length

00:30:00

Difficulty

Beginner

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.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Utilizing Google Cloud Pub/Sub

In this hands-on lab, we'll get practical experience working with the necessary components of Cloud Pub/Sub: topics, subscriptions, and messages.

How to Log in to Google Lab Accounts

On the lab page, right-click Open GCP Console and select the option to open it in a new private browser window (this option will read differently depending on your browser — e.g., in Chrome, it says "Open Link in Incognito Window"). Then, sign in to Google Cloud Platform using the credentials provided on the lab page.

On the Welcome to your new account screen, review the text, and click Accept. In the "Welcome L.A.!" pop-up once you're signed in, check to agree to the terms of service, choose your country of residence, and click Agree and Continue.

Utilizing Google Cloud Pub/Sub

Now, on to the lab!

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 > Topics.
  2. Click Create a topic.
  3. Enter a name for the topic (e.g., "la-topic-1").
  4. Click Create.

Create a subscription.

  1. Drill down into the topic just created and choose Subscriptions.
  2. Click the icon in the Topic details navigation bar to create a subscription.
  3. Enter a name for the subscription (e.g., "la-sub-1").
  4. Set Delivery Type to Pull.
  5. Leave the rest of the settings at their defaults.
  6. 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.

Conclusion

Congratulations on completing this lab!