Pub/Sub Hands On

Length: 00:18:24

Lesson Summary:

It is now time to jump into a hands-on demonstration of Cloud Pub/Sub using both the web console and gcloud command line. For your reference, the steps we took in the demonstration are also below to follow along.

Simple Demonstration:

  1. Create a topic called my-topic:

    • gcloud pubsub topics create my-topic
  2. Create a subscription to topic my-topic:

    • gcloud pubsub subscriptions create --topic my-topic mySub1
  3. Publish a message to your topic:

    • gcloud pubsub topics publish my-topic --message "hello"
  4. Retrieve message with your subscription, acknowledge receipt and remove message from the queue:

    • gcloud pubsub subscriptions pull --auto-ack mySub1
  5. Cancel subscription:

    • gcloud pubsub subscriptions delete mySub1
  6. Simulated traffic ingest:

    • Clone GitHub data to Cloud Shell (or other SDK environments), and browse to the publish folder:

    • cd ~ git clone https://github.com/linuxacademy/googledataengineer

    • cd ~/googledataengineer/courses/streaming/publish

  7. Create a topic called sandiego:

    • gcloud pubsub topics create sandiego
  8. Create a subscription to topic sandiego:

    • gcloud pubsub subscriptions create --topic sandiego mySub1
  9. Run script to download sensor data:

    • ./download_data.sh

    (Optional). If you need to authenticate a shell to ensure we have the right permissions:

    • gcloud auth application-default login
  10. View script info:

    • vim ./send_sensor_data.py or use viewer of your choice
  11. Run python script to simulate one hour of data per minute:

    • ./send_sensor_data.py --speedFactor=60 --project=YOUR-PROJECT-ID

    If you receive an error: google.cloud.pubsub cannot be found OR ‘ImportError: No module named iterator’, run the below pip command to install components then try again:

    • sudo pip install -U google-cloud-pubsub
  12. Open new Cloud Shell tab (using + symbol):

    • Pull the message using the subscription mySub1

      • gcloud pubsub subscriptions pull --auto-ack mySub1
  13. Create a new subscription and pull messages with it:

    • gcloud pubsub subscriptions create --topic sandiego mySub2

    • gcloud pubsub subscriptions pull --auto-ack mySub2


This lesson is only available to Linux Academy members.

Sign Up To View This Lesson
Or Log In

Looking For Team Training?

Learn More