How to use gcloud beta pubsub topics publish with pubsub emulator

4,005 views
Skip to first unread message

Atali Daoud

unread,
Jul 10, 2017, 3:40:36 AM7/10/17
to Google Cloud Pub/Sub Discussions
Hello,


I try to use "gcloud pubsub topics publish" with my pubsub emulator

  • I started the emulator :

gcloud beta emulators pubsub start

  • I run my pubsub server in go
 go run ./command.go
Registering topic:  COMMAND.SELLER.CREATE
topic ->  SUBSCRIPTION.COMMAND.SELLER.CREATE
Check if topic  COMMAND.SELLER.CREATE  exists ...
Created Subscription: projects/fake-project/subscriptions/SUBSCRIPTION.COMMAND.SELLER.CREATE


  • Set the env pubsub in the terminal where I will send the command
$(gcloud beta emulators pubsub env-init)

  • Then I push a message through gcloud command 
gcloud beta pubsub topics publish "COMMAND.SELLER.CREATE" "Hello world"
messageIds: '135130600180541'

I got an answer but the Id is coming from the real pubsub and not the emulator. 


Something missing ? Any suggestions will be appreciated .

Alex Mordkovich

unread,
Jul 10, 2017, 10:37:43 AM7/10/17
to Atali Daoud, Google Cloud Pub/Sub Discussions, Haw-Bin Chai
Hi Atali, can you check the value of the PUBSUB_EMULATOR_HOST environment variable? That is, what is the output of:

echo $PUBSUB_EMULATOR_HOST

? Also, what makes you beliee that the answer is coming from the real pubsub and not the emulator?

--
You received this message because you are subscribed to the Google Groups "Google Cloud Pub/Sub Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cloud-pubsub-discuss+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cloud-pubsub-discuss/5a490c49-bf56-45a8-bad8-9d80d648ef47%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Atali Daoud

unread,
Jul 10, 2017, 12:39:50 PM7/10/17
to Google Cloud Pub/Sub Discussions, atali...@gmail.com, hbc...@google.com
Hello Alex,

When I as


This is my golang program running with a correct PUBSUB_EMULATOR_HOST


When I run the gcloud command, this is the result . As you can see, gcloud command doesn't see the topic "COMMAND.SELLER.CREATE"



Listing of topics and subscription through gcloud command




I think the gcloud command doesn't take into account the PUBSUB_EMULATOR_HOST variable.


When I stop the emulator, I stop my golang program and unset PUBSUB_EMULATOR_HOST variable in all terminal, it works :

Gcloud command :



and the message is consumed by my golang program

Alex Mordkovich

unread,
Jul 11, 2017, 12:22:57 PM7/11/17
to Atali Daoud, Google Cloud Pub/Sub Discussions, Haw-Bin Chai
Hi Atali,

Upon a closer read of the instructions at https://cloud.google.com/pubsub/docs/emulator, I see that it says "after following these instructions, the Google Cloud Pub/Sub client libraries in your code call the API running in the local instance instead of the production API." That is, it does not affect the endpoint that 'gcloud beta pubsub' talks to. Could you please file a feature request per https://cloud.google.com/pubsub/docs/support to add support for pointing the gcloud CLI at the local emulator?

Thanks,
Alex

To unsubscribe from this group and stop receiving emails from it, send an email to cloud-pubsub-discuss+unsubscrib...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Cloud Pub/Sub Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cloud-pubsub-discuss+unsub...@googlegroups.com.

Atali Daoud

unread,
Jul 12, 2017, 3:31:15 AM7/12/17
to Alex Mordkovich, Google Cloud Pub/Sub Discussions, Haw-Bin Chai
Hello Alex,

Ok thanks I will create a feature request as suggested.





think big


--
You received this message because you are subscribed to a topic in the Google Groups "Google Cloud Pub/Sub Discussions" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cloud-pubsub-discuss/kaOuqBMENHg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cloud-pubsub-discuss+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cloud-pubsub-discuss/CAFvu0kMEYP9PauGZwyR2hZxX%3DUf8f4yNNf%2Bu8pC8kt3D61W-iw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages