Google Professional Cloud Developer Question 210
Select 3Google Cloud PlatformYou are developing an application that uses Google Cloud Pub/Sub for messaging and you want to test your code locally without incurring costs or requiring an active internet connection. Which steps should you take to emulate Pub/Sub locally?
- A
Use the Google Cloud SDK to start the Pub/Sub emulator on your local machine.
- B
Configure your application to point to the Pub/Sub emulator using the GOOGLE_CLOUD_PROJECT environment variable.
- C
Install and use a third-party library to simulate Pub/Sub instead of using Google's emulator.
- D
Run the Pub/Sub emulator in a Docker container if you do not want to install it directly on your machine.
- E
Ensure your application uses the Cloud Pub/Sub production endpoint for local testing.
Show answer and explanation
Correct answers: A, B, D
Explanation
The Google Cloud Pub/Sub emulator allows developers to test their applications locally without using the production Pub/Sub service. This approach avoids costs and eliminates the dependency on an active internet connection. The emulator can be started via the Google Cloud SDK or run in a Docker container. Applications must be configured to point to the emulator instead of the production service, typically by setting specific environment variables like GOOGLE_CLOUD_PROJECT. Using third-party libraries or production endpoints for local testing is not recommended.
- A. Correct.
Correct: The Google Cloud SDK includes a Pub/Sub emulator for local testing. You can start the emulator on your machine to simulate Pub/Sub functionality.
- B. Correct.
Correct: When using the emulator, you need to configure your application to connect to the emulator instead of the production Pub/Sub service. Setting the GOOGLE_CLOUD_PROJECT environment variable is a typical step.
- C. Incorrect.
Incorrect: While third-party libraries may offer similar functionality, the official Pub/Sub emulator provided by Google is the recommended tool for local development.
- D. Correct.
Correct: Running the Pub/Sub emulator in a Docker container is a valid approach if you want to avoid installing it directly on your development machine.
- E. Incorrect.
Incorrect: Using the production endpoint for local testing defeats the purpose of emulating Pub/Sub services and may incur costs.