Featured resource
2025 Tech Upskilling Playbook
Tech Upskilling Playbook

Build future-ready tech teams and hit key business milestones with seven proven plays from industry leaders.

Check it out
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • Cloud
Labs

Handling Streaming Messages with Cloud Pub/Sub

One of the primary benefits of Cloud Pub/Sub is its ability to handle streaming data, as well as occasional and batch data. Streaming data could come from many sources, including multiple Internet of Things devices. In this hands-on lab, we’ll learn how to set up a Cloud Pub/Sub topic and subscription, simulate streaming data from traffic sensors, and pull multiple records of data from the subscription.

Lab platform
Lab Info
Level
Beginner
Last updated
Sep 20, 2025
Duration
30m

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
Table of Contents
  1. Challenge

    Create a Topic
    1. From the main navigation menu, select Pub/Sub > Topics.
    2. Click Create a topic.
    3. Enter a name for the topic, such as "la-streaming-topic".
    4. Keep the Encryption option at its default setting.
    5. Click Create Topic.
  2. Challenge

    Create a Subscription
    1. Drill down into the topic we just created and choose Create Subscription from the bottom of the page in the Subscriptions section.
    2. Enter a name for the subscription, such as "la-streaming-subscription".
    3. The Cloud Pub/Sub topic must be selected
    4. Set Delivery Type to Pull.
    5. Under Retain acknowledged messages, click the Enable option.
    6. Leave all the other options as their defaults.
    7. Click Create.
  3. Challenge

    Retrieve the Files
    1. From the top navigation, click Activate Cloud Shell.
    2. In the Cloud Shell, enter the following command to clone the GitHub repository: git clone https://github.com/ACloudGuru-Resources/training-data-analyst.git
    3. Change to the training-data-analyst/courses/streaming/publish directory: cd training-data-analyst/courses/streaming/publish
    4. Copy the data file from a Cloud Storage bucket: gsutil cp gs://cloud-training-demos/sandiego/sensor_obs2008.csv.gz .
    5. Open the Cloud Shell code editor.
    6. Review the file send_sensor_data.py in the training-data-analyst/courses/streaming/publish folder.
    7. On line 26, change the TOPIC variable from sandiego to the last part of your topic name (following the final '/').
    8. Save the file.
  4. Challenge

    Stream Data and Confirm Operation
    1. Enable the Resource Manager API gcloud services enable cloudresourcemanager.googleapis.com
    2. Authenticate the shell with the following code: gcloud auth application-default login --no-launch-browser
    3. Click the generated link to confirm the authentication.
    4. Execute the following command to install the Google Cloud Pub/Sub library: sudo pip3 install google-cloud-pubsub
    5. Execute the following code to simulate streaming data: ./send_sensor_data.py --speedFactor=60 --project=[PROJECT_ID]
    6. Create a new Cloud Shell instance by clicking the plus (+) icon.
    7. Change directory to the working folder: cd training-data-analyst/courses/streaming/publish
    8. Pull the messages from the subscription with the following command: gcloud pubsub subscriptions pull --auto-ack [SUBSCRIPTION_NAME] --limit=25
About the author

Pluralsight Skills gives leaders confidence they have the skills needed to execute technology strategy. Technology teams can benchmark expertise across roles, speed up release cycles and build reliable, secure products. By leveraging our expert content, skill assessments and one-of-a-kind analytics, keep up with the pace of change, put the right people on the right projects and boost productivity. It's the most effective path to developing tech skills at scale.

Real skill practice before real-world application

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.

Learn by doing

Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.

Follow your guide

All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.

Turn time into mastery

On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.

Get started with Pluralsight