cloud-pubsub icon indicating copy to clipboard operation
cloud-pubsub copied to clipboard

Add documentation about using the emulator

Open kayleg opened this issue 4 years ago • 14 comments

https://cloud.google.com/sdk/gcloud/reference/beta/emulators/pubsub

kayleg avatar Jun 04 '20 13:06 kayleg

happy to do it, should have done this part of my pr sorry :-)

sync avatar Jul 01 '20 11:07 sync

Yeah, that would be nice. I assume that requires a fake service account? I have an issue running ci tests currently, so I'm guessing I'll need this too

ruseinov avatar Jul 08 '20 15:07 ruseinov

I'm curious how this should be done as cloud_pubsub does seem to expect a service account, which means I'll need to create a fake one, right?

ruseinov avatar Jul 08 '20 15:07 ruseinov

@ruseinov The package does so I'm guessing you would need one from that aspect. But I've never used the emulator so not sure if it actually needs to be a valid one or if the emulator can create a fake one for emulator purpose only.

kayleg avatar Jul 08 '20 15:07 kayleg

Actually I don't know, I just know that the crate won't work without a somewhat valid service account. I'll check it out.

ruseinov avatar Jul 08 '20 16:07 ruseinov

@kayleg it looks like the official libraries are happy without any credentials: https://cloud.google.com/pubsub/docs/emulator . I guess we need a way to construct the client without credentials and look at the env variables (project_id, emulator_host) to decide whether to fail or not. We could make the credentials Optional and the make this decision based on whether the Option is Some or None + the existence of environment variables.

ruseinov avatar Jul 08 '20 16:07 ruseinov

Hey folks, any updates on the documentation on how to use the Emulator ?

IMFIL avatar Jul 20 '20 00:07 IMFIL

I was supposed to do it but have been caught up on other things, anything that isn't working for you?

https://cloud.google.com/pubsub/docs/emulator was good enough for me to get going with it. I kept passing the same credentials and everything worked.

The only thing that surprised me at first was that I had to recreate subscriptions every time I would restart the emulator and was using the pythons scripts provided from the linked documentation.

sync avatar Jul 20 '20 00:07 sync

@ruseinov An idea would be to create a dummy service account that has access to nothing on GCP. That way in your tests, virtually nothing changes but having the emulator host env var and reading from the dummy service account (which can also be injected via an env var).

IMFIL avatar Jul 20 '20 00:07 IMFIL

@sync do you just set the project id and the emulator host as env vars and the lib knows what to do on it's own ?

IMFIL avatar Jul 20 '20 00:07 IMFIL

I run $(gcloud beta emulators pubsub env-init) in the same terminal where I run cargo

sync avatar Jul 20 '20 00:07 sync

@sync awesome. I typically use docker-compose up -d in development. There I have a pubsub emulator running.

IMFIL avatar Jul 20 '20 02:07 IMFIL

cool on OS X docker is always slow sadly I would if on Linux

sync avatar Jul 20 '20 03:07 sync

@IMFIL thanks for sharing the docker compose docker image, I was just looking for one!

sync avatar Jul 22 '20 21:07 sync