Publish and receive messages in Pub/Sub using the Google Cloud console
This page shows you how to perform basic tasks in Pub/Sub using the Google Cloud console.
To follow step-by-step guidance for this task directly in the Google Cloud console, click 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 Google Cloud 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 Google Cloud console.
-
Set up a Google Cloud 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 Google Cloud console.
Create a topic
In the Google Cloud console, go to the Pub/Sub page.
In the Topics page, click
Create topic .In the window that opens, enter
MyTopic
in the Topic ID field.Leave the default values for the remaining options, and then click Create.
You see the success message:
A new topic and a new subscription have been successfully created.
You have just created a topic called
MyTopic
and an associated default subscriptionMyTopic-sub
.
Add a second subscription
To add a second subscription to the topic you just created, complete these steps:
Click Subscriptions.
In the Subscriptions page, click Create subscription.
Enter
MySub
in theSubscription ID field.For Select a Cloud Pub/Sub topic, select the
MyTopic
topic from the drop-down menu.Leave the default values for the remaining options.
Click
Create .You see the success message:
Subscription successfully added.
Click the
Topics page and clickMyTopic
.The
MySub
subscription is now attached to the topicMyTopic
. Pub/Sub delivers all messages sent toMyTopic
to theMySub
andMyTopic-sub
subscriptions.
Publish a message to the topic
In the Google Cloud console, go to the Pub/Sub topics page.
Click the
MyTopic
topic.
In the
MyTopic
page, click theMessages tab.Click
Publish message .In the
Message body window, enterHello World
.Click
Publish . A message displays at the bottom of the page that says "Message published" if the publish was successful.
Pull the messages from the subscription
In the Google Cloud console, go to the Pub/Sub subscriptions page.
In the Messages tab, click Pull.
You should see the message that you just published. The message has
the data, Hello World
, and the time when the message was
published.
When using the Google Cloud console, an individual pull for a low message volume can often return zero messages. If you do not see messages, click Pull multiple times to issue multiple pull requests. This is not an issue with the Pub/Sub Client Libraries.
Clean up
To avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.
If you no longer need the topic and subscription you created, you can delete them.
To delete the topic and subscription, complete these steps:
Go to the
Topics page.Check the checkbox next to
MyTopic
and clickDelete .Complete the steps in the confirmation window to permanently delete the topic.
Or you can delete the project that you created.
What's next
Learn more about the Pub/Sub concepts discussed in this page.
Read the basics of the Pub/Sub service.
Work through an end-to-end example of a Pub/Sub system.
Try another Pub/Sub quickstart that uses client libraries or the gCloud CLI.
Learn more about Pub/Sub APIs.