arrow_back

Google Cloud Pub/Sub - Console

Join Sign in

Google Cloud Pub/Sub - Console

30 minutes 5 Credits

Overview

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

What you'll do

  • Set up a topic to hold data.

  • Subscribe to a topic to access the data.

  • Publish and then consume messages with a pull subscriber.

Setup and requirements

For each lab, you get a new GCP project and set of resources for a fixed time at no cost.

  1. Make sure you signed into Qwiklabs using an incognito window.

  2. Note the lab's access time (for example, img/time.png and make sure you can finish in that time block.

  1. When ready, click img/start_lab.png.

  2. Note your lab credentials. You will use them to sign in to Cloud Platform Console. img/open_google_console.png

  3. Click Open Google Console.

  4. Click Use another account and copy/paste credentials for this lab into the prompts.

  1. Accept the terms and skip the recovery resource page.

Now that you've started your lab, you'll log in to the Google Cloud Shell console, then launch the command line tool.

Activate Google Cloud Shell

Google Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud.

Google Cloud Shell provides command-line access to your Google Cloud resources.

  1. In Cloud console, on the top right toolbar, click the Open Cloud Shell button.

    Highlighted Cloud Shell icon

  2. Click Continue.

It takes a few moments to provision and connect to the environment. When you are connected, you are already authenticated, and the project is set to your PROJECT_ID. For example:

Project ID highlighted in the Cloud Shell Terminal

gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.

  • You can list the active account name with this command:
gcloud auth list

Output:

Credentialed accounts: - @.com (active)

Example output:

Credentialed accounts: - google1623327_student@qwiklabs.net
  • You can list the project ID with this command:
gcloud config list project

Output:

[core] project =

Example output:

[core] project = qwiklabs-gcp-44776a13dea667a6 Note: Full documentation of gcloud is available in the gcloud CLI overview guide .

Task 1. Setting up Pub/Sub

You can use the Google Cloud Shell console to perform operations in 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.

The naviagtion path to the Topics option is highlighted

  1. Click Create topic.

  2. The topic must have a unique ID. For this lab, name your topic MyTopic in the Create a topic dialog, then click CREATE TOPIC.

You've created a topic.

Test completed task

Click Check my progress to verify your performed task. If you have completed the task successfully you will be granted an assessment score.

Create a Pub/Sub topic.

Task 2. Add a subscription

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

  1. In the Topics dialog, for the topic you just made click the three dot icon (More icon) > Create subscription.

  2. Type the subscription ID, such as MySub, set the Delivery Type to Pull, then click Create.

Test completed task

Click Check my progress to verify your performed task. If you have completed the task successfully you will be granted an assessment score.

Add a subscription.

Task 3. Test your understanding

Below are multiple choice questions to reinforce your understanding of this lab's concepts. Answer them to the best of your abilities.

Task 4. Publish a message to the topic

  1. Click on the Topic you just made. In the topic details page, navigate to Messages and then click on Publish Message at the bottom.

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

Task 5. 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 the command line:

gcloud pubsub subscriptions pull --auto-ack MySub

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

student_03_47a223a4e648@cloudshell:~ (qwiklabs-gcp-04-37e2ea565261)& gcloud pubsub subscriptions pull --auto-ack MySub DATA: Hello World MESSAGE_ID: 3880838673527294 ORDERING_KEY: ATTRIBUTES: DELIVERY_ATTEMPT:

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

End your lab

When you have completed your lab, click End Lab. Google Cloud Skills Boost removes the resources you’ve used and cleans the account for you.

You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.

The number of stars indicates the following:

  • 1 star = Very dissatisfied
  • 2 stars = Dissatisfied
  • 3 stars = Neutral
  • 4 stars = Satisfied
  • 5 stars = Very satisfied

You can close the dialog box if you don't want to provide feedback.

For feedback, suggestions, or corrections, please use the Support tab.

Copyright 2022 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.