
Answer-first summary for fast verification
Answer: Install the Pub/Sub emulator using gcloud, and start the emulator with a valid Google Project IWhen developing locally, configure your application to use the local emulator by exporting the PUBSUB_EMULATOR_HOST variable.
The correct approach for local testing of Pub/Sub integration is to use the Pub/Sub emulator. This allows for isolated testing without affecting production environments. Option B and D both correctly suggest installing the Pub/Sub emulator using gcloud and configuring the application to use the local emulator. However, Option B incorrectly formats the command substitution syntax, making Option D the more accurate choice. Option D correctly mentions exporting the PUBSUB_EMULATOR_HOST variable, which is essential for the application to communicate with the local emulator. Options A and C suggest using the production Pub/Sub API, which is not suitable for local testing purposes.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
No comments yet.
How can you set up local testing for a web application that publishes messages to Pub/Sub when developing new versions locally and needing to verify Pub/Sub integration for each build?
A
Install Cloud Code on the integrated development environment (IDE). Navigate to Cloud APIs, and enable Pub/Sub against a valid Google Project ID. When developing locally, configure your application to call pubsub.googleapis.com.
B
Install the Pub/Sub emulator using gcloud, and start the emulator with a valid Google Project ID. When developing locally, configure your application to use the local emulator with ${gcloud beta emulators pubsub env-init}.
C
In the Google Cloud console, navigate to the API Library, and enable the Pub/Sub API. When developing locally, configure your application to call pubsub.googleapis.com.
D
Install the Pub/Sub emulator using gcloud, and start the emulator with a valid Google Project IWhen developing locally, configure your application to use the local emulator by exporting the PUBSUB_EMULATOR_HOST variable.