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

Publish and receive messages in Pub/Sub by using the Google Cloud console

This page shows you how to perform basic tasks in Pub/Sub using the Google Cloud console.


For step-by-step guidance for this task directly in the Cloud Shell Editor, click Guide me:

Guide me


The following sections take you through the same steps as clicking 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. Install and initialize the Google Cloud CLI.
  4. 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.

  5. Install and initialize the Google Cloud CLI.

Create a topic

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

    Go to the Pub/Sub topics page

  2. Click Create topic.

    Screenshot that shows the Create topic dialog in the console

  3. In the Topic ID field, provide a unique topic name, such as MyTopic.

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

  1. Click the Subscriptions tab.

  2. Click Create subscription.

  3. In the Subscription ID box, enter a name for the subscription, such as MySub.

    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.

Publish a message to the topic

To publish a message to the topic:

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

    Go to the Pub/Sub topics page

  2. Click the topic ID.

  3. Click the Messages tab near the bottom of the page, then click Publish Message.

  4. Enter Hello World in the Message field.

  5. Click Publish.

Pull the message from the subscription

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

    Go to the Pub/Sub subscriptions page

  2. Click the subscription ID.

  3. Click the Messages tab.

  4. Click Pull.

Clean up

The resources used on this page fall within the free usage limit. Optionally, you can delete them by following these steps.

  1. Go to the Pub/Sub topics page in the Google Cloud console.

    Go to the Pub/Sub topics page

  2. Check the checkbox next to the topic that you created.

  3. Click Delete to permanently delete the topic.

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