~ 3 min read
How to create a new Pub/Sub Topic on Google Cloud
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:
Login to Google Cloud console https://console.cloud.google.com/
Once logged in, navigate to https://console.cloud.google.com/cloudpubsub/topic/list
Click on the “Create Topic” button
A pop up to Create a topic will appear. Add the Topic ID here
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
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 customized Subscription after the Topic has been created. The steps are as follows:
Navigate to https://console.cloud.google.com/cloudpubsub/subscription/list/ and click on the “Create Subscription” button
Once the subscription window opens then provide a Subscription Name and select the Topic ID for which you want to create the Subscription
Dead-lettering settings allow you to store the messages to a dead letter topic when it cannot be delivered
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.
Pub/Subs allow for asynchronous messaging and is widely used with many applications. In this article we took a look at Google Cloud 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.