-
Create a Directory and move in that directory
mkdir gcf_hello
cd gcf_hello
nano index.js
gsutil mb -p [Project ID] gs://{bucket name}
-
Deploy the function to a pub/sub topic named hello_world
gcloud functions deploy helloWorld \
--stage-bucket [BUCKET_NAME] \
--trigger-topic hello_world \
--runtime nodejs8
gcloud functions describe helloWorld
-
Create a message test of the function.
DATA=$(printf 'Hello World!'|base64) && gcloud functions call helloWorld --data '{"data":"'$DATA'"}'
gcloud functions logs read helloWorld
-
Create a pub/sub Topic called Arish
gcloud pubsub topics create Arish
To see the topicsgcloud pubsub topics list
Deleting Topics Arishgcloud pubsub topics delete Arish
-
Create a subscription called mySubscription
gcloud pubsub subscriptions create --topic Arish mySubscription
cmd to list all the subscriptionsgcloud pubsub topics list-subscriptions Arish
Delete mySubscriptionsgcloud pubsub subscriptions delete mySubscriptions
-
Publish the Message "Hello" to the topic you created previously(Arish)
- Using the pull command without any flags will output only one message, even if you are subscribed to a topic that has more held in it.
gcloud pubsub topics publish Arish --message "Hello"
to pull the messages you just published from the Pub/Sub topicgcloud pubsub subscriptions pull mySubscription --auto-ack
Now you can publish more messages and then pull them. But on pulling only one message will be output.
-
Add message to your Topic
gcloud pubsub topics publish Arish --message "Try1"
gcloud pubsub topics publish Arish --message "Try2"
Add a flag to your command so you can output all two messages in one request. You may have not noticed, but you have actually been using a flag this entire time: the --auto-ack part of the pull command is a flag that has been formatting your messages into the neat boxes that you see your pulled messages in.limit is another flag that sets an upper limit on the number of messages to pull.
Wait a minute to let the topics get created. Run the pull command with the limit flag:
gcloud pubsub subscriptions pull mySubscription --auto-ack --limit=2