You have a web application that publishes messages to Pub/Sub. You plan to build new versions of the application locally and want to quickly test Pub/Sub integration for each new build. How should you configure local testing?
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.
I will go with B. PUBSUB_EMULATOR_HOST is additional option if local emulator and app is running in different machine. It can also be used on same machine. But if it is same localhost, gcloud beta emulators pubsub env-init is the easy approach. https://cloud.google.com/pubsub/docs/emulator
Here we have only single machine, so just using the terminal command is OK, no need to export ENV variables
https://cloud.google.com/pubsub/docs/emulator#automatically_setting_the_variables
Alternative B is correct. Link: https://cloud.google.com/pubsub/docs/emulator#env
Executing "gcloud beta emulators pubsub env-init" is required for local testing when the application and the emulator run either on the same machine or on different machines. The export of the PUBSUB_EMULATOR_HOST variable is an additional step required only in the latter case (when the application and the emulator run on different machines).
Based on the common steps for implementing the Pub/Sub emulator, the best choice for configuring local testing of your web application's Pub/Sub integration would be:
Option 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}.
This option covers the essential steps for both scenarios (same machine or different machines) and provides a clear path for setting up and utilizing the Pub/Sub emulator effectively for local development and testing.
This approach allows you to test your application’s integration with Pub/Sub without making actual calls to the Pub/Sub service, which can be time-consuming and may incur costs. Instead, your application interacts with the local emulator, which mimics the behavior of the actual Pub/Sub service. This makes it a fast and cost-effective solution for local testing. Remember to set the PUBSUB_EMULATOR_HOST environment variable to point your application to the local emulator.
https://cloud.google.com/pubsub/docs/emulator#automatically_setting_the_variables
If your application and the emulator run on the same machine, you can set the environment variables automatically with:
1) $(gcloud beta emulators pubsub env-init)
If your application and the emulator run on different machines, set the environment variables manually with:
1) Run the env-init command: gcloud beta emulators pubsub env-init
2) On the machine that runs your application, set the PUBSUB_EMULATOR_HOST
I agree with B as the correct answer.
https://cloud.google.com/pubsub/docs/emulator#automatically_setting_the_variables
You can run gcloud beta emulators pubsub env-init in your own localhost within if your application and the emulator run on the same machine
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
GCP001
4 months, 1 week agoalpha_canary
6 months, 3 weeks agoexamprof
11 months agoplutonians123
11 months ago__rajan__
1 year, 1 month ago[Removed]
1 year, 4 months agosbonessi
1 year, 5 months agoWriter
1 year, 6 months agoWriter
1 year, 6 months agocloser89
1 year, 6 months agocloser89
1 year, 6 months ago