Stay organized with collections Save and categorize content based on your preferences.

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. Click Create topic.

    Screenshot that shows the Create topic dialog in the console

  3. In the window that opens, enter MyTopic in the Topic ID field, and then click Create topic.

Add a subscription

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

  1. Click the Subscriptions tab.

  2. Click Create subscription.

  3. Enter MySub in the Subscription ID field.

    Shows the new subscription dialog and typing your subscription
          name in the Subscription name field.

  4. Leave the default values for the remaining options.

  5. Click Create.

  6. Return to the Topics page and click MyTopic.

    The MySub subscription is now attached to the topic MyTopic. Pub/Sub will deliver all messages sent to MyTopic to this subscription.

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. Click the Messages tab.

  2. Click Publish message.

  3. In the Message 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

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?