Lab - Google's Cloud Pub\Sub - Publish messsage


Google's Cloud Pub\Sub - Lab


  • Create some Pub/Sup topics and subscriptions
  • See how to publish messages and consume them.
Pub/Sup topics and subscriptions GCP

Implementation tool:

  • In the Cloud Console,
  • In the gcloud command line tool.

pub Sub  Implementation tool:


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.

GCP pub sub engineering data

  • 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.
Let's create a subscription in pub/sub

  • 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

That message is now queued up in our Pub/Sub topic.

  • 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.
This isn't something you'd normally do in a production environment
  • 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.
enable ACK messages or acknowledgement messages.  Pub sub

  • 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.
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, there are no more messages 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. And 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 subscription?
    • 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:
Write comments

Please do not enter spam links

Meet US


More Services