Google Cloud Pub/Sub (Publisher / Subscriber)
Pub/Sub is a communication mechanism that facilitates the exchange of messages between services in an asynchronous manner.
A publisher sends the message and the subscriber receives the message.
In a fully managed Pub/Sub system, the provider manages all the underlying infrastructure and operational aspects. This includes provisioning servers, monitoring, scaling, backups, and security updates. Users can focus on developing their applications and rely on the provider to handle the operational burden.
Pub/Sub is often referred to as a real-time messaging service that allows to sends & receives messages between two independent applications.
The messages can be Files, Batch Data, or streaming data.
Publisher application creates & sends messages to Topic which is retained for Max 7 Days.
It supports 01 million + messages per second.
The message Order may differ. For example:
The publisher sent two messages: “Hi” and “How are you?” and The message are received in the order of “How are you?” followed by “Hi.”.
Let’s create a pub/sub and publish the messages. Make sure you have a Billing account enabled
- Search for the Pub/sub in the search bar.
- Click on the Create Topic.
3. Enter the topic name. It can be anything
4. Click on CREATE button.
5. As you can see, we have selected the “Add a default subscription” checkbox, so it will create a subscription as well.
6. If we are not selecting the “Add a default subscription ” checkbox, then need to create the subscription manually and link it to our Topic.
7. Now our next step is to publish and receives the message. This can be achieved using “publish” and “pull”.
gcloud pubsub topics publish [topic-name] --message="hello"
gcloud pubsub subscriptions pull [ubscriptions-name] --auto-ack
8. We will execute these commands in our Google Cloud shell.