As official partners of the Google Cloud Platform, Nisum offers reflections on what we have learned and to consider key takeaways and some basic walk-throughs and guides to help get you started.
One of our rising talents, Nasir Hussain, a Sr. DevOps Intern, will dig into one of the products that he has found to be quite high “on the awesome scale,” called Pub/Sub.
Pub/Sub (Publish/Subscribe) Messaging is an asynchronous messaging service that decouples services and produces events from services that process events.
As the name suggests, Pub/Sub works in a Publisher / Subscriber model and uses event-driven applications. This means you can have applications publishing and subscribing to events that are available as messages. Simply put, a Publisher publishes a message, and the Subscriber acknowledges that message.
Here are some key points according to Google:
Some salient questions should come to mind. The first was - How do we make sure that the Publisher publishes to the right place and the Subscriber is listening to the right place? We’ll demonstrate how this works below.
First here are some key terms explained:
Now that we called out the Core components, let’s run through an example of how the Pub/Sub Model Works:
The diagram below demonstrates a pictorial view of the logic model used in this blog.
First, you will need two things for this demo:
USE CASE: You are the owner/operator of a Coffee Shop. Your customers can push messages or order their beverage to a topic or queue.
At each barista station, subscribed baristas can pull one message (order) at a time and confirm it to start up the espresso machine.
Create the topic in pub/sub using gcloud CLI.
```code```
$ gcloud pubsub topics create coffee-shop
With the topic created as coffee-shop, the barista needs to join as a subscriber.
```code```
$ gcloud pubsub subscriptions create --topic coffee-shop barista
We're creating a subscription as a barista that subscribes to the topic created in step 1.
And there we have it. You are done with Pub/Sub setup - easy, right? Now let's integrate it with our applications as subscribers and publishers.
Let's assume we've got a customer that wants an add-on to their espresso- a dash of cinnamon.
For the barista to take coffee orders, they use their subscription to consume the messages.
We'll use gcloud CLI as well.
$ gcloud pubsub subscriptions pull barista --limit=1 --auto-ack
NOTE: We're using the --limit flag to ensure we only receive one message from the topic.
NOTE: For the --auto-ack flag to automatically acknowledge the message.
The notes above make sure consumers receive a message successfully by acknowledging its receipt.
We can also manually acknowledge the messages.
See how easy this was? This is a good reason to get excited about Pub/Sub and the Google Cloud Platform in general. For more information on Quickstarts, Samples, and How to Guides, please visit cloud.google.com/pubsub.
While the Pub/Sub concept is easy to understand, keep in mind that every coding and programming language handles things differently, so make sure to check before running into challenging learning curves across other platforms.
Nisum utilizes Google Cloud to provide Cloud Development and Integration services to its clients and Cloud migration services. See how Nisum’s Digital Services covers all aspects of digital transformation journeys. From DevOps to cloud development, Nisum is here to help guide you as you start your Google Cloud Platform journey.
Contact us to learn more about how Nisum can develop your GCP practice and implement best practices across teams, programs, and portfolios for your organization.