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:

Guide me


Before you begin

  1. 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.
  2. Set up a Google Cloud console project.

    Set up a 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.

  3. Set up a Google Cloud console project.

    Set up a 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

  1. In the Google Cloud console, go to the Pub/Sub page.

    Go to Pub/Sub

  2. In the Topics page, click Create topic.

  3. 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 subscription MyTopic-sub.

Add a second subscription

To add a second subscription to the topic you just created, complete these steps:

  1. Click Subscriptions.

  2. In the Subscriptions page, click Create subscription.

  3. Enter MySub in the Subscription ID field.

  4. For Select a Cloud Pub/Sub topic, select the MyTopic topic from the drop-down menu.

  5. Leave the default values for the remaining options.

  6. Click Create.

    You see the success message: Subscription successfully added.

  7. Click the Topics page and click MyTopic.

    The MySub subscription is now attached to the topic MyTopic. Pub/Sub delivers all messages sent to MyTopic to the MySub and MyTopic-sub subscriptions.

Publish a message to the topic

  1. In the Google Cloud console, go to the Pub/Sub topics page.

    Go to Topics

  2. Click the MyTopic topic.

  1. In the MyTopic page, click the Messages tab.

  2. Click Publish message.

  3. In the Message body window, enter Hello World.

  4. 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

  1. In the Google Cloud console, go to the Pub/Sub subscriptions page.

    Go to Subscriptions

  2. 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:

  1. Go to the Topics page.

  2. Check the checkbox next to MyTopic and click Delete.

  3. Complete the steps in the confirmation window to permanently delete the topic.

Or you can delete the project that you created.

What's next