~ 3 min read

How to create a new Pub/Sub Topic on Google Cloud

Pub/Subs are popularly used for asynchronous communication between applications. This article is a quick walkthrough of how you can create a Pub/Sub Topic on Google Cloud.

Table of Contents


Creating a Pub/Sub Topic

     Add a default subscription

     Use a schema

     Set message retention duration



Pub/Sub helps with messaging in between applications. A Cloud Pub/Sub is designed to provide reliable, many-to-many asynchronous messaging between applications. Publisher applications can send messages to a Topic and other applications can Subscribe to that Topic to receive the messages.

In Google Cloud, Pub/Sub allows applications and services to communicate asynchronously. It delivers low-latency/durable messaging in between application and services, it is commonly used by developers in implementing asynchronous workflows, distributing event notifications, and streaming data from various processes or devices.

Creating a Pub/Sub Topic

Following are the steps to create Pub/Sub Topic on Google Cloud:

  1. Login to Google Cloud console
  2. Once logged in, navigate to https://console.cloud.google.com/cloudpubsub/topic/list
  3. Click on the “Create Topic” button

Create topic

  1. A pop up to Create a topic will appear. Add the Topic ID here.

Create a topic and add topic id

  1. Under the Topic ID you can see three options, “Add a default subscription”, “Use a schema”, and “Set message retention duration”. Select the option that is applicable to your use case

In the following sections, all three options have been covered

  1. Finally, click on the “Create Topic” button

Add a default Subscription

To add a default Subscription just select the option and by default it will provide the following features:

  • Pull delivery type
  • 7 days message retention duration
  • Expire after 31 days of inactivity
  • 10 seconds acknowledgment deadline
  • Immediate retry policy

We can also create a customised Subscription after the Topic has been created. The steps are as follows:

  1. Navigate to https://console.cloud.google.com/cloudpubsub/subscription/list/ and click on the “Create Subscription” button

Create subcription

  1. Once the subscription window opens then provide a Subscription Name and select the Topic ID for which you want to create the Subscription

create subscription3. Dead-lettering settings allow you to store the messages to a dead letter topic when it cannot be delivered

dead letterng4. Leaving other options as default, select create.

Use a schema

A schema is a format that messages from a topic must follow. When creating a topic you can choose to create a new schema to assign to it, or assign it an existing schema. Select the Pub/Sub schema and then the message encoding language

Set message retention duration

When Set message retention duration is enabled, it retains the messages on the Topic for up to 31 days. This is a paid feature.

message retention duration## Conclusion

Pub/Subs allow for asynchronous messaging and is widely used with many applications. In this article we took a look at Pub/Sub and covered the steps for creating a new Topic. We also looked into various options that are available to us while creating a Topic. This article is a quick walkthrough for those getting started with Google Cloud Pub/Sub.


This article is brought to you by Kloudle Academy, a free e-resource compilation, created and curated by Kloudle. Kloudle is a cloud security management platform that uses the power of automation and simplifies human requirements in cloud security. Receive alerts for Academy by subscribing here.