Skip to main content

Google

Google Cloud – PUB/SUB: Part 2 – Implementing Pub/Sub

Google Cloud Pub/Sub is a fully managed messaging service on Google Cloud Platform, facilitating asynchronous communication between applications in real time.

Google Cloud Platform serves as the foundation for creating, enabling, and utilizing all Google Cloud services. This includes managing APIs, enabling billing, managing collaborators, and configuring permissions for Google Cloud resources.

Refer to Part 1 – Basic Concepts to get more clarity before implementing Pub/Sub.

Prerequisites for Setting up Pub/Sub on Google Cloud

  • Create a Google account
  • Set up a Cloud Console project

Let’s implement PUB/SUB

Step 1: Create a Project

  • Navigate to the Manage Resources page in the Cloud Console.
  • From the Select Organization drop-down list at the top of the page, select the organization in which you want to create a project. (This list does not appear for a free trial user)
  • Click Create Project.
  • Enter a project name in the New Project window and select a billing account as applicable. A project name can contain only letters, numbers, single quotes, hyphens, spaces, or exclamation points and must be between 4 and 30 characters.
  • In the Location box, specify the parent organization or folder, which will act as the hierarchical parent of the new project.
  • Once all details are entered, click Create.

Step1

Step 2: Create a Topic

  • Go to the Pub/Sub topics page in the Cloud Console.
  • Click Create Topic.

Step2n

  • In the Topic ID field, provide a unique topic name, for example, My_NewTopic
  • Click Save.

Leave the default values for the remaining options or set them as required, and then click Create.

Step2.1

You see the success message: ‘A new topic and subscription have been created successfully’.

That’s it—you’ve just created a Pub/Sub topic!

Step2.2

Step 3: Add a Subscription

Now, create a subscription on the previously created topic

  • Once a Pub/Sub topic is created, add a subscriber to this. Click: Create subscription

Step3

  • Display the menu for the topic you just created and click New Subscription.
  • Type a name for the subscription, such as My_NewTopic-Sub.
  • Leave the delivery type as Pull.
  • Select 7 Days for Message retention duration.
  • Click Create

Step3.1

You see the success message: ‘Subscription successfully added’.

You have just created a topic called My_NewTopic and an associated default subscription, My_NewTopic-sub

Step3.2

Step 4: Publish a Message on the Topic

To publish a message on the topic:

  • Go to the Topic details page for the topic you just created.
  • Click the Messages tab near the bottom of the page, then click Publish Message.

Step4n

  • Enter a suitable message in the Message.
  • You can Add attributes as needed, in terms of parameter -value pair, such as Job-id = 1
  • Click Publish.

Step4.1n

Now, you have successfully published the message.

You see the success message: ‘Message published’.

Step 5: Pull a message from Subscription

  • In the Cloud Console, go to the Pub/Sub subscriptions page.
  • Click the subscription ID.
  • In the Subscription details page, click View messages.
  • Click Pull.

Step5n

After pulling the message, you will see the published message details on the page.

Step5.1n

In essence, Google Cloud Pub/Sub streamlines the establishment and setup of managed message brokers, providing capabilities such as topic organization for data streams and versatile delivery options, including publish and pull methods.

Let’s do some hands-on here.

References

  1. Cloud Pub/Sub
  2. Cloud Pub/Sub – Console

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Hemlata Sahu

Hemlata Sahu is a Technical Consultant at Perficient Nagpur. She is passionate about exploring new technologies and tools in testing. A creative problem solver, she has extensive experience in API automation using the Rest Assured BDD framework, Karate, API testing with POSTMAN, manual testing, and GCloud Pub/Sub testing. Hemlata is dedicated to staying at the forefront of the testing field and sharing her insights with others.

More from this Author

Follow Us