What Is Cloud Pub/Sub?
Cloud Pub-Sub is a real-time messaging service offered by Google for applications to publish and subscribe to events.
Google Cloud Pub/Sub provides messaging between applications and 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.
One can publish the message manually or watch the changes in Gmail using Gmail API and notify the user application on a real-time basis.
Core Components of Google Cloud Pub/Sub
- Topic: A named resource (which acts as an alias) to which the publishers send messages.
- Publisher: It is an application that creates and sends a message to a Pub/Sub topic.
- Subscriber: It is an application that registers itself to a specified topic of interest in order to get appropriate messages.
- Subscription: It represents a stream of messages from a single, specific topic, which is delivered to the subscribing application.
- Message: It is a combination of data and other attributes and is delivered to the subscribers at the end, which is sent by a publisher to a topic.
- Message attribute: A key-value pair used by a publisher to define a message.
How does Pub/Sub work?
The diagram below explains the key components in the Google Cloud Pub/Sub messaging system and the flow of messages between publishers and subscribers.
- A publisher application creates a topic in the Publisher/Subscriber service and sends messages to the topic. So, the message comprises a payload and optional attributes describing the payload content.
- The service makes sure that published messages are retained on behalf of the subscriptions.
- The message published is retained for a subscription till it is acknowledged by a subscriber consuming messages from that particular subscription.
- Pub/Sub forwards messages individually from a topic to all of its subscriptions.
- Similarly, a subscriber receives messages either by Pub/Sub pushing them to the subscriber’s chosen endpoint.
- Hence, an acknowledgment is transmitted by the subscriber to the Pub/Sub service for each received message.
- The service then removes acknowledged messages from the subscription’s message queue.
1.) In-order delivery at scale: Optional per-key ordering simplifies state full application logic without sacrificing horizontal scale (i.e., no partitions required).
2.) Stream analytics and connectors: The native Data flow integration allows reliable, expressive, processing and integration of event streams in languages such as Java, Python, and SQL.
3.) Cost-optimised ingestion with Pub/Sub Lite: Pub/Sub Lite aims to be the lowest cost option for high-volume event ingestion. Therefore, it offers zonal storage, and users have control of capacity management.
4.) Google Cloud–native integrations: Take advantage of integrations with multiple services, such as Cloud Storage and Gmail update events and Cloud Functions for server-less event-driven computing.
5.) Dead letter topics: It allows for messages unable to be processed by subscriber applications to be put aside for offline examination and debugging then so that other messages can be processed without any delay.