Publish and receive messages in Pub/Sub by using the console
This page shows you how to perform basic tasks in Pub/Sub using the Google Cloud console.
For step-by-step guidance on this task directly in Cloud Shell Editor, click Guide me:
The following sections take you through the same steps as clicking Guide me.
Before you begin
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
Set up a console project.
Click to:
- Create or select a project.
- Enable the Pub/Sub API for that project.
You can view and manage these resources at any time in the console.
- Install and initialize the Google Cloud CLI.
-
Set up a console project.
Click to:
- Create or select a project.
- Enable the Pub/Sub API for that project.
You can view and manage these resources at any time in the console.
- Install and initialize the Google Cloud CLI.
Create a topic
In the console, go to the Pub/Sub topics page.
Click Create topic.
In the Topic ID field, provide a unique topic name, such as
MyTopic
.Click Create topic.
That's it—you've just created a Pub/Sub topic!
Add a subscription
To add a subscription to the topic you just created:
Click the Subscriptions tab.
Click Create subscription.
In the Subscription ID box, enter a name for the subscription, such as
MySub
.Leave the default values for the remaining options.
Click Create.
Publish a message to the topic
To publish a message to the topic:
In the console, go to the Pub/Sub topics page.
Click the topic ID.
Click the Messages tab near the bottom of the page, then click Publish Message.
Enter
Hello World
in the Message field.Click Publish.
Pull the message from the subscription
In the console, go to the Pub/Sub subscriptions page.
Click the subscription ID.
Click the Messages tab.
Click Pull.
Clean up
To avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.
Go to the Pub/Sub topics page in the console.
Check the checkbox next to the topic that you created.
Click Delete to permanently delete the topic.
Delete any remaining subscriptions by displaying each subscription and clicking its trash can icon.
What's next
Get started with Pub/Sub in your language of choice at Pub/Sub Client Libraries.
See the Publisher and Subscriber guides to learn more about the concepts discussed in this page.
For a detailed overview of Pub/Sub, see What is Pub/Sub?