Test and monitoring in PubSub

Monitoring

The Google Cloud Pub/Sub API exportsusage metricsthat can be monitored programmatically or accessed viaStackdriver Monitoring. You can create dashboards, set up alerts, and set up anautoscalerto manage publisher or message processing (subscriber) instances running on Compute Engine. Note that while Google Cloud Pub/Sub itself is scaled automatically, you are responsible for managing your Pub/Sub quota.

Google Cloud Pub/Sub Emulator

To develop and test your application locally, you can use the Google Cloud Pub/Sub emulator, which provides local emulation of the production Google Cloud Pub/Sub environment. You can start the Google Cloud Pub/Sub emulator using thegcloudcommand-line tool. However, you need to do a small amount of configuration before running your application against the emulator, such as starting the emulator and setting environment variables.

Starting the Google Cloud Pub/Sub emulator

You start the emulator by invokingpubsub startfrom a command prompt:

gcloud beta emulators pubsub start [options]

One of the options you can supply is --data-dir=<directory>, where <directory>is the directory you want to use.

After you start the emulator, you can confirm it is running by seeing a message similar to:

...
[pubsub] This is the Google Pub/Sub fake.
[pubsub] Implementation may be incomplete or differ from the real system.
...
[pubsub] INFO: Server started, listening on 8538

Setting environment variables

Run theenv-initcommand to determine and set the environment variables used by the emulator. Note that after following these instructions, the Google Cloud Pub/Sub client libraries in your code call the API running in the local instance instead of the production API.

To automatically set the variables, run theenv-initcommand using command substitution:

$ (gcloud beta emulators pubsub env-init)

To manually set the variables, run theenv-initcommand and then create the environment variables and values by executing the commands in the output of the env-init command.

results matching ""

    No results matching ""