Checkpoints
Create a Lite Topic
/ 50
Create a Lite Subscription
/ 50
Pub/Sub Lite: Qwik Start
GSP832
Overview
Complementing Pub/Sub, Pub/Sub Lite is a zonal service for messaging systems with predictable traffic patterns. If you publish 1 MiB-1 GiB of messages per second, Pub/Sub Lite is a low cost option for high-volume event ingestion.
Publishers send messages to Lite topics and subscribers receive messages from Lite subscriptions. Lite topics and Lite subscriptions are zonal resources that must be in the same Cloud project and zone. For a list of zones that Pub/Sub Lite supports, refer to Pub/Sub Lite locations.
In this lab you will learn how to:
-
Create Lite topics and Lite subscriptions using the Cloud Console.
-
Send and receive messages using the Pub/Sub Lite client library for Python.
Setup
Before you click the Start Lab button
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you.
This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
- Access to a standard internet browser (Chrome browser recommended).
- Time to complete the lab---remember, once you start, you cannot pause a lab.
How to start your lab and sign in to the Google Cloud Console
-
Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is the Lab Details panel with the following:
- The Open Google Console button
- Time remaining
- The temporary credentials that you must use for this lab
- Other information, if needed, to step through this lab
-
Click Open Google Console. The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
Note: If you see the Choose an account dialog, click Use Another Account. -
If necessary, copy the Username from the Lab Details panel and paste it into the Sign in dialog. Click Next.
-
Copy the Password from the Lab Details panel and paste it into the Welcome dialog. Click Next.
Important: You must use the credentials from the left panel. Do not use your Google Cloud Skills Boost credentials. Note: Using your own Google Cloud account for this lab may incur extra charges. -
Click through the subsequent pages:
- Accept the terms and conditions.
- Do not add recovery options or two-factor authentication (because this is a temporary account).
- Do not sign up for free trials.
After a few moments, the Cloud Console opens in this tab.
Activate Cloud Shell
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. Cloud Shell provides command-line access to your Google Cloud resources.
- Click Activate Cloud Shell
at the top of the Google Cloud console.
When you are connected, you are already authenticated, and the project is set to your PROJECT_ID. The output contains a line that declares the PROJECT_ID for this session:
gcloud
is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
-
(Optional) You can list the active account name with this command:
-
Click Authorize.
-
Your output should now look like this:
Output:
-
(Optional) You can list the project ID with this command:
Output:
Example output:
gcloud
, in Google Cloud, refer to the gcloud CLI overview guide.
Set your project
Enable the Pub/Sub Lite API
- In the Cloud Console, navigate to APIs & Services > Library.
- Start typing "pub/sub" in the Search bar, then select the Pub/Sub Lite tile.
-
Now click the Enable button.
-
In Cloud Shell, run the following to install the the Python client library:
Task 1. Create a Lite Topic
To create a Lite topic with the Cloud Console, follow these steps:
-
In the Cloud Console, go to Navigation menu > Pub/Sub > Lite Topics page.
-
Click Create Lite topic.
-
Select Regional Lite topic to choose the region and then select Zonal Lite topic to choose the zone (this lab uses
), then click Continue. -
In the Name section, enter
my-lite-topic
as the Lite topic ID. The Lite topic name includes the Lite topic ID, the zone, and the project number. -
Click Continue.
-
Make sure to uncheck Attach to a reservation checkbox.
-
Click Create.
Click Check my progress to verify the objective.
Task 2. Create a Lite Subscription
To create a Lite subscription with Cloud Console, follow these steps:
- Click on Lite Subscriptions in the left menu.
- Click Create Lite subscription.
- In the Lite subscription ID field, enter
my-lite-subscription
. - In Select a Lite resources select a Lite topic to receive messages, you created in the last step.
- In the Delivery requirement section, select Deliver messages after stored.
- Click Create.
The Lite subscription is in the same zone as the Lite topic.
Click Check my progress to verify the objective.
Task 3. Send messages
Send messages to the Lite topic using the following publisher application. Using the Cloud Shell Editor or the editor of your choice, create a file called send_messages.py
and add the following script, then:
-
Uncomment all steps in the TODO section.
-
Replace
project_number
with the project number you can see in the Lite topic and subscription name in the Console. -
If you used a different
cloud_region
andzone_id
, update with your information:
The publisher sends 100 messages to a Lite topic and prints the number of messages that the Pub/Sub Lite service receives.
Task 4. Receive messages
Receive messages from the Lite subscription using the following subscriber application. Using the Cloud Shell Editor or the editor of your choice, create a file called receive_messages.py
and add the following script, then
-
Uncomment all steps in the TODO section.
-
Replace
project_number
with the Project number you can see in the Lite topic and subscription name in the Console. -
If you used a different
cloud_region
andzone_id
, update with your information:
After the subscriber receives a message, the subscriber prints the message ID and the message data.
-
Now run both scripts:
You will see output in Cloud Shell that looks like this:
You will also be able to monitor activity on the Lite Topics and Lite Subscriptions pages in the Cloud Console.
Task 5. Clean up
Although all resources will be destroyed when you end this lab, it's good practice to clean up resources you don't need to avoid charges.
-
In the Cloud Console, go to the Lite Topics page.
-
Click my-lite-topic.
-
On the Lite topic details page, click Delete.
-
In the field that appears, type delete to confirm that you want to delete the Lite topic.
-
Click Delete.
Congratulations!
Now you can use Pub/Sub Lite to create topics and subscriptions, and send and receive messages.
Finish your quest
This self-paced lab is part of the Baseline: Infrastructure quest. A quest is a series of related labs that form a learning path. Completing this quest earns you a badge to recognize your achievement. You can make your badge or badges public and link to them in your online resume or social media account. Enroll in this quest and get immediate completion credit if you've taken this lab. Refer to the Google Cloud Skills Boost catalog for all available quests.
Next steps / Learn more
- Choosing Pub/Sub or Pub/Sub Lite
- Pub/Sub Lite documentation
Google Cloud training and certification
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual Last Updated May 12, 2023
Lab Last Tested April 25, 2022
Copyright 2023 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.