Google's Cloud Pub\Sub - Lab
Objective:
- Create some Pub/Sup topics and subscriptions
- See how to publish messages and consume them.
Implementation tool:
- In the Cloud Console,
- In the gcloud command line tool.
Steps
Step 1: Open your GCP project and go to GCP Cloud Console.
- Let's practice interacting with Pub/Sub through this interface first before we tackle the command line.
- First, select Pub/Sub from the burger menu under the Big Data section.
- Click Create Topic.
- And we can see the full path to the topic here, which includes our project name.
- We'll let Google manage the encryption keys and click, Create Topic.
- Step 2: Let's create a subscription.
- First, go back to the list of topics and click the 3 dots here to access some further options.
- Then, click Create Subscription. We'll leave the delivery type as Pull and accept all the other default settings. Scroll down and click Create.
- Step 3: Let's create a message.
- Go back to the topics page into topic and click Publish Message.
- You can type anything you want in here. Then click publish.
- That message is now queued up in our Pub/Sub topic.
Note: If you are not able to find publish message, please use command line
- Set Project in Command line
- Syntax: gcloud config set project [Project-ID]
- Command: gcloud config set project playground-s-11-1bcdfc2d
- Send message to subscription from topic
- Syntax: gcloud pubsub topics publish test1topic --message "messagae"
- Command: gcloud pubsub topics publish test1topic --message "messaga1-send"
- We can view it by clicking View Messages, which will let us act as a subscriber, right inside the Cloud Console.
- First, select the subscription that we just created. Then click, And there's the message that we just published.
- Notice, we didn't select this checkbox to enable ACK messages or acknowledgement messages.
- And now, the deadline has been exceeded for us to acknowledge the receipt of the message.
- This means the message stays in the queue because Pub/Sub doesn't know for sure that we definitely received it.
- Now we'll retry and enable ACK messages. Now we can see our message and quickly click ACK to acknowledge it.
- This is how a production Pub/Sub client would operate. The message has been received successfully, so we acknowledge that, which pops it off the top of the queue of our topic.
- If we try to pull one more time, we'll see, no more messages are waiting for our subscription.
- Let's try one more thing to prove the delivery wants promise.
- Go back to the topics list and copy the full path of the topic by clicking this link here.
- We'll go to subscriptions and create a new one. let's go back to our topic and publish another message.
- Click Create Message. And type anything you like here. Click Publish Message.
- Now, we'll view that message by clicking View Messages.
- Select the first subscription we created. Tick Enable ACK Messages and then Pull. As soon as you see the message, click the link to acknowledge it. Now, let's click Pull again and you can see that this subscriber no longer has any messages.
- For other subscriptions?
- Click Pull again and there's our message. And we'll quickly acknowledge it.
- Each subscriber is guaranteed to get each message once.
- This is an example of the one-to-many pattern.
No comments:
Post a Comment