You publish messages to Pub/Sub from a web app and want fast local tests of Pub/Sub integration for each local build. How should you configure local testing?
Choose an answer
Tap an option to check your answer.
Correct answer: Install the Pub/Sub emulator via gcloud, start it for a valid Google Project ID, and configure the app locally to use the emulator (e.g., run gcloud beta emulators pubsub env-init)..
Why this is the answer
The Pub/Sub emulator provides a local, in-memory version of the Pub/Sub service, allowing for fast, isolated testing without incurring costs or relying on network connectivity to Google Cloud. The gcloud beta emulators pubsub env-init command (or manually setting PUBSUBEMULATORHOST) configures your local environment to direct Pub/Sub client libraries to the emulator instead of the production service. Calling pubsub.googleapis.com when running locally (whether or not Cloud Code is installed or the API is enabled) would connect to the actual Google Cloud Pub/Sub service, which is slow for local development, incurs costs, and isn't isolated for testing. While exporting PUBSUBEMULATORHOST is a valid way to configure the app, the env-init command is often preferred as it handles the environment variable setup for common client libraries.
Pass your exam — without the endless answer hunt
Get every verified question and explanation for this exam in one place, and save hours of prep. 1,000+ certifications · 20+ languages · free to start.
Pass your exam faster → No card needed