Intrigued by the art of cloud architecture? Discover how to design, develop, and manage robust, secure, scalable, and dynamic solutions on Google Cloud as you prepare for the Professional Cloud Architect exam!
Prepare and test your skills
Prepare and test your skills
Worked example. The correct answer is already marked and every option is explained below, so there is nothing to select here. To answer questions yourself, start the free trial.
Keep the momentum going with these hand-picked practice scenarios
Want more questions like this?
Get a free certification question every week.
Last updated
A development team is building a microservice that publishes messages to Google Cloud Pub/Sub. To reduce cloud consumption costs and ensure functional testing can occur offline on local workstations, developers need to test the application locally without modifying the production application code or changing how the Google Cloud client libraries are initialized.
Which sequence of actions should the team perform to install, start, and redirect client traffic to a local Pub/Sub emulator?
Install the emulator using gcloud components install pubsub-emulator, start it with gcloud beta emulators pubsub start, and set the PUBSUB_EMULATOR_HOST environment variable using $(gcloud beta emulators pubsub env-init).
Update gcloud config set api_endpoint_overrides/pubsub to point to localhost:8085 and grant the roles/pubsub.admin IAM role to the Compute Engine default service account.
Create an instance template in Compute Engine configured with startup scripts to launch a mock server, and configure an external Application Load Balancer with URL map routing.
Deploy a Cloud Run service running a Pub/Sub container image, configure VPC firewall rules to allow local traffic, and export GOOGLE_APPLICATION_CREDENTIALS on the workstation.
Install the emulator using gcloud components install pubsub-emulator, start it with gcloud beta emulators pubsub start, and set the PUBSUB_EMULATOR_HOST environment variable using $(gcloud beta emulators pubsub env-init).
env-init Solution IsThe Google Cloud Pub/Sub emulator is a local, in-memory implementation of the Cloud Pub/Sub service provided via the Google Cloud CLI (gcloud). It provides local emulation of the Cloud Pub/Sub service APIs, allowing developers to test publishing and subscription workflows locally and within continuous integration (CI) pipelines without generating cloud usage costs or requiring internet access.
gcloud components install pubsub-emulator.gcloud beta emulators pubsub start starts the emulator process on a local socket (by default localhost:8085).$(gcloud beta emulators pubsub env-init) evaluates and exports the PUBSUB_EMULATOR_HOST variable (e.g., PUBSUB_EMULATOR_HOST=localhost:8085), which instructs client libraries to redirect all calls to the local emulator without requiring any changes to the source code or client initialization logic.PUBSUB_EMULATOR_HOST environment variable and switch from production endpoints to the local mock instance.env-init command automatically handles host and port configuration for shell sessions.This approach aligns with Google Cloud development best practices for local emulation by leveraging the built-in gcloud component manager and native client library hooks, providing functional equivalence without requiring custom endpoint routing logic in the application code.
Update gcloud config set api_endpoint_overrides/pubsub to point to localhost:8085 and grant the roles/pubsub.admin IAM role to the Compute Engine default service account.
Create an instance template in Compute Engine configured with startup scripts to launch a mock server, and configure an external Application Load Balancer with URL map routing.
Deploy a Cloud Run service running a Pub/Sub container image, configure VPC firewall rules to allow local traffic, and export GOOGLE_APPLICATION_CREDENTIALS on the workstation.