📖 Scenario: You are working on a cloud application that needs to send messages between different parts of the system reliably. Messaging helps different services talk to each other without losing information.
🎯 Goal: Build a simple Google Cloud Pub/Sub setup with a topic and a subscription to understand how messaging works in cloud infrastructure.
📋 What You'll Learn
Create a Pub/Sub topic named my-topic
Create a subscription named my-subscription to my-topic
Configure the subscription to use pull delivery type
Ensure the setup follows Google Cloud best practices for messaging
💡 Why This Matters
🌍 Real World
Messaging systems like Pub/Sub help cloud services communicate reliably without losing messages, even if parts of the system are busy or offline.
💼 Career
Understanding messaging is key for cloud architects and developers to build scalable, decoupled applications that handle data and events efficiently.
Progress0 / 4 steps
1
Create a Pub/Sub topic
Create a Pub/Sub topic named my-topic using the Google Cloud SDK command gcloud pubsub topics create my-topic.
GCP
Hint
Use the gcloud pubsub topics create command followed by the topic name.
2
Create a subscription to the topic
Create a subscription named my-subscription to the topic my-topic using the command gcloud pubsub subscriptions create my-subscription --topic=my-topic --ack-deadline=10.
GCP
Hint
Use gcloud pubsub subscriptions create with the --topic flag to link the subscription.
3
Configure subscription for pull delivery
Ensure the subscription my-subscription is configured for pull delivery by adding the flag --message-retention-duration=600s to the subscription creation command.
GCP
Hint
Add --message-retention-duration=600s to keep messages for 10 minutes.
4
Verify the Pub/Sub setup
List the topics and subscriptions to verify that my-topic and my-subscription exist using gcloud pubsub topics list and gcloud pubsub subscriptions list.
GCP
Hint
Use gcloud pubsub topics list and gcloud pubsub subscriptions list to check your setup.
Practice
(1/5)
1. Why is messaging important in cloud systems like Google Cloud Pub/Sub?
easy
A. It stores large files permanently.
B. It speeds up the internet connection.
C. It replaces the need for databases.
D. It allows different parts of a system to communicate reliably.
Solution
Step 1: Understand messaging role in cloud systems
Messaging enables components to send and receive information without direct connection, ensuring reliable communication.
Step 2: Identify the correct purpose of messaging
Messaging is not about speeding internet, storing files, or replacing databases but about reliable communication.
Final Answer:
It allows different parts of a system to communicate reliably. -> Option D
Quick Check:
Messaging = Reliable communication [OK]
Hint: Messaging means reliable communication between system parts [OK]
Common Mistakes:
Confusing messaging with file storage
Thinking messaging speeds up internet
Assuming messaging replaces databases
2. Which of the following is the correct way to create a Pub/Sub topic using gcloud CLI?
A. The subscriber client is not initialized correctly.
B. The callback function is missing the message.ack() call.
C. The subscription does not exist or is not attached to the topic.
D. The topic name is incorrect in the subscription path.
Solution
Step 1: Check subscription existence and linkage
If the subscription does not exist or is not linked to the topic, no messages will be received.
Step 2: Verify other code parts
The callback acknowledges messages correctly, subscriber client is initialized properly, and subscription path uses correct subscription name.
Final Answer:
The subscription does not exist or is not attached to the topic. -> Option C
Quick Check:
Missing or unlinked subscription = no messages [OK]
Hint: Check subscription exists and links to topic first [OK]
Common Mistakes:
Forgetting to create subscription before subscribing
Assuming callback runs without subscription
Mixing topic and subscription names
5. You want to build a system where multiple services process messages independently but reliably from the same stream of events. Which Pub/Sub feature best supports this?
hard
A. Use Cloud Storage instead of Pub/Sub for message sharing.
B. Create multiple subscriptions on the same topic for each service.
C. Publish messages to different topics for each service.
D. Use a single subscription and share it among all services.
Solution
Step 1: Understand message delivery to multiple consumers
Pub/Sub allows multiple subscriptions on one topic, so each service can get all messages independently.
Step 2: Evaluate options for independent processing
Sharing one subscription means messages are load balanced, not duplicated; publishing to different topics duplicates effort; Cloud Storage is not for messaging.
Final Answer:
Create multiple subscriptions on the same topic for each service. -> Option B