Soru

Zorluk: KolayCloud Emulators and Development Testing Frameworks

A software development team is building a service that publishes and consumes messages using Google Cloud Pub/Sub. To facilitate fast offline testing without incurring cloud resource charges, a developer starts the Pub/Sub emulator locally using the command `gcloud beta emulators pubsub start`. Which environment variable must be set in the local application environment to ensure the Google Cloud Client Libraries automatically route requests to the local emulator instead of live GCP endpoints?

  1. PUBSUB_EMULATOR_HOST set to the host and port of the running emulator (e.g., localhost:8085)Cevap
  2. B
    GOOGLE_APPLICATION_CREDENTIALS set to a local service account JSON key file
  3. C
    TERRAFORM_STATE_BACKEND set to local file storage mode
  4. D
    GKE_CLUSTER_ENDPOINT set to a local Minikube cluster address

Cevap

The environment variable PUBSUB_EMULATOR_HOST must be set to the emulator's host and port address (for example, localhost:8085).
Google Cloud Pub/Sub client libraries automatically check for the presence of the PUBSUB_EMULATOR_HOST environment variable upon instantiation. When this variable contains a host and port (such as localhost:8085), the SDK routes all publisher and subscriber calls to the local emulator, bypassing authentication requirements and remote API calls.

Adım Adım Çözüm

1
Identify the mechanism used by Google Cloud Client Libraries to detect local emulators.
Google Cloud Client Libraries for Pub/Sub check for specific host environment variables during initialization.
Emulators mimic GCP service endpoints locally so applications can run integration tests without internet access or GCP credentials.
2
Select the correct environment variable for the Cloud Pub/Sub emulator.
The standard variable name defined by GCP SDKs is PUBSUB_EMULATOR_HOST.
Defining PUBSUB_EMULATOR_HOST forces the client library to substitute production API endpoints with the specified local host and port.

Anahtar Kavram

Configuring Cloud Emulators for Local Testing
Tahmini Süre:45s
Bu soruyu puanla