Here is a simple, clear, step-by-step guide on how to create a Cloud Pub/Sub topic in Google Cloud using the required format:
✅
Cloud Pub/Sub Topic Name Format
Google Cloud Pub/Sub requires a topic name in this format:
projects/{project_id}/topics/{topic_name}
- project_id → Your Google Cloud project ID
- topic_name → The name you want for your topic
Example:
projects/my-app-123/topics/userEvents
📌
How to Create a Pub/Sub Topic (Step-by-Step Guide)
Method 1: Google Cloud Console (Easiest)
1. Open Pub/Sub
Go to:
Google Cloud Console → Pub/Sub → Topics
Direct link (safe):
Search “Google Cloud Pub/Sub Topics” in your browser.
2. Click “Create Topic”
3. Enter Topic Name
In the Topic ID field, write only the topic name:
userEvents
Google Cloud automatically shows you the full resource name:
projects/{project_id}/topics/userEvents
4. Leave default settings OR customize
You can choose:
✔ Message retention
✔ Encryption
✔ Labels
5. Click “Create”
Your topic is created.
Method 2: gcloud CLI (Command Line)
1. Install Google Cloud SDK
(if not installed)
Search: “Google Cloud SDK install”
2. Login
gcloud auth login
3. Set your project
gcloud config set project YOUR_PROJECT_ID
4. Create the topic
gcloud pubsub topics create userEvents
Method 3: REST API
POST request:
POST https://pubsub.googleapis.com/v1/projects/{project_id}/topics/{topic_name}
Example:
POST https://pubsub.googleapis.com/v1/projects/my-app-123/topics/userEvents
📦
Your Final Topic Name Structure
After creation, the topic will always look like this:
projects/my-app-123/topics/userEvents
This is the value used by:
- Cloud Functions triggers
- Cloud Run services
- Pub/Sub subscribers
- APIs & SDKs
❓ Want help creating
Subscriptions
,
Triggering Functions
, or
Publishing messages
?
0 Comments