kayleg / cloud-pubsub

Google Cloud PubSub client in rust
MIT License
31 stars 21 forks source link

Add documentation about using the emulator #8

Open kayleg opened 4 years ago

kayleg commented 4 years ago

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

sync commented 4 years ago

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

ruseinov commented 4 years ago

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 commented 4 years ago

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?

kayleg commented 4 years ago

@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.

ruseinov commented 4 years ago

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 commented 4 years ago

@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.

IMFIL commented 4 years ago

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

sync commented 4 years ago

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.

IMFIL commented 4 years ago

@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 commented 4 years ago

@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 ?

sync commented 4 years ago

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

IMFIL commented 4 years ago

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

sync commented 4 years ago

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

sync commented 4 years ago

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