Introduction to Google Cloud Pub/Sub
January is the month of resolutions and if your resolution is to get #googlecertified then Google Cloud Pub/Sub is an interesting service which you can learn about. Let’s understand first what Google Cloud Pub/Sub is.
Google Cloud Pub/Sub is a messaging service for exchanging event data among applications and services. By decoupling senders and receivers, it allows for secure and highly available communication between independently written applications. Google Cloud Pub/Sub delivers low-latency/durable messaging, and is commonly used by developers in implementing asynchronous workflows, distributing event notifications, and streaming data from various processes or devices.
If you’re curious and you need to see how Google Pub/Sub functions Google Cloud Pub/Sub: Qwik Start — Command Line is the right lab for you. Let us have a look at this lab and look at the objectives which you will be achieving here
Objectives of the Lab
Set up and Requirements
The set up of this lab is quite simple. Make sure you are performing the lab in an incognito window and using the latest version of Google Chrome. Follow the lab instructions to get into the Google Console. You can read through the instructions to be ready for the further steps in this lab.
The Pub/Sub basics
Have a look at the diagram below to take a look at the terms which you will be hearing often when you are dealing with this service.
Let’s now head to the first task of this lab which is to create a Pub/Sub topic. This task can be easily completed by executing the command which is given in the lab instructions. Once you have run this command successfully click on the Check my Progress button to see your score.
After completing the first task you have to create two more topics named as Test1 and Test2. Once you have successfully created these topics you will see a screen similar to this
You can also check the topics created with the command gcloud pubsub topics list
Moving on, you will now have to delete the topics which you created. This can be done simply by running the command which is mentioned in the lab instructions. Your screen will look like this once the topics have been deleted.
Now it is time to work with subscriptions. You will follow the same process which you followed above for the creation of topics. All you have to run is two commands
- To Create a subscription — gcloud pubsub subscriptions create — topic myTopic mySubscription
- To delete a subscription — gcloud pubsub subscriptions delete Test1
Pub/Sub Publishing and Pulling a Single Message
In this section you will publish and pull a single message on Pub/Sub. All you need to do is follow the instructions given carefully and fill in the blanks wherever necessary. Refer to the example screenshot for your reference
Instead of Qwiklabs you can mention your name. Similarly in the next message you can add your favorite Food in the message.
Then you have to run the command to pull the messages. Once you run the pull command, you will notice that only one message is pulled. Don’t worry we got you covered. In the next section of this lab, you will learn to pull multiple messages.
Pub/Sub pulling all messages from subscriptions
In the above section you saw how to pull a single message. Now, you will see how you can pull multiple messages from subscriptions. You have to run an additional command after you pull all your messages. Here is the command
gcloud pubsub subscriptions pull mySubscription — auto-ack — limit=3
In the command if you change the limit to four, you will see four messages in the output. You can set the limit as per your convenience. With this last step, you have successfully completed this lab.
Similarly you can take other interesting labs from the quest Baseline: Infrastructure to get a headstart for preparing for #googlecloudcertification. Enter code 1q-certify-34 to get 3 free credits to complete this quest (valid through January 13th).