
Answer-first summary for fast verification
Answer: Install the Pub/Sub emulator using gcloud, and start the emulator with a valid Google Project ID. When developing locally, configure your applicat.cn to use the local emulator by exporting the PUBSUB_EMULATOR_HOST variable.
Option B is the correct choice for local testing of Pub/Sub integration because it involves using the Pub/Sub emulator, which is specifically designed for local development and testing. This approach allows developers to test their applications without incurring costs or affecting production environments. The emulator mimics the behavior of the live Pub/Sub service, providing a realistic testing environment. Configuring the application to use the local emulator by setting the PUBSUB_EMULATOR_HOST environment variable ensures that all Pub/Sub operations are performed locally. Options A and D suggest using the actual Pub/Sub API, which is not suitable for isolated local testing. Option C proposes an incorrect method by attempting to override the API endpoint with a non-existent emulator URL, which is not a valid or recommended practice.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
No comments yet.
How can you configure local testing for a web application that publishes messages to Pub/Sub when developing and testing new versions locally?
A
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.
B
Install the Pub/Sub emulator using gcloud, and start the emulator with a valid Google Project ID. When developing locally, configure your applicat.cn to use the local emulator by exporting the PUBSUB_EMULATOR_HOST variable.
C
Run the gcloud config set api_endpoint_overrides/pubsub https://pubsubemulator.googleapis.com.com/ command to change the Pub/Sub endpoint prior to starting the application.
D
Install Cloud Code on the integrated development environment (IDE). Navigate to Cloud APIs, and enable Pub/Sub against a valid Google Project IWhen developing locally, configure your application to call pubsub.googleapis.com.