Pub/Sub APIs overview

Pub/Sub surfaces JSON/HTTP (commonly associated with RESTful systems) and gRPC interfaces.

If you don't want to use our client libraries to access the Pub/Sub API, you have the option of writing your own client libraries that use its REST or gRPC API surface. We recommend this approach only if your programming language or other needs are not met by the provided client libraries.

gRPC interface

You can generate your own gRPC client libraries in any gRPC-supported language for the Pub/Sub API from its .proto service definition using these resources:

JSON/HTTP interface

If you prefer working with the JSON/HTTP interface, you can use these resources:

Pub/Sub endpoints

An endpoint, in the context of publish-subscribe messaging systems such as Pub/Sub, refers to a location or address where a publisher client can publish messages or where a subscriber client can receive messages.

Pub/Sub has global and locational service endpoints.

  • The global HTTP endpoint for JSON/HTTP is https://pubsub.googleapis.com.
  • The global endpoint for gRPC is pubsub.googleapis.com:443.

Global endpoints

Requests to the global endpoint originating from within Google Cloud are routed to the Pub/Sub in the region where they originate. Examples of origins considered within Google Cloud include clients running on Compute Engine or App Engine. Requests to the global endpoint made over Interconnect are routed similarly to requests originating in the region associated with the interconnection. In case Pub/Sub becomes unavailable in a region, requests originating within the same Google Cloud region are not load balanced to a different region.

Requests sent to the global endpoint from outside of Google Cloud are routed to a nearby available region. The requests may be routed to a region with insufficient project quota for the request type. The region is also not guaranteed to be the closest geographically.

Locational endpoints

We recommend using locational endpoints as an alternative to the global one in the following cases:

  • High volume applications running outside of Google Cloud that require sufficient quota in all regions where traffic might be routed.
  • Applications where the publishers or subscribers run outside of Google Cloud and are not geographically close to each other. In such cases, you can reduce Google Cloud outbound message costs by configuring the applications outside of Google Cloud to use the locational endpoint corresponding to the region used by the application inside of Google Cloud. If both publishers and subscribers are outside of Google Cloud, configure them to use the same locational endpoint.
  • Applications which require that data be processed in a specific region.
  • When publishing with ordering.
  • When subscribing with exactly-once delivery.

Set a locational endpoint override

You can set a locational endpoint override for any Pub/Sub operation that calls a Pub/Sub endpoint (JSON/HTTP or gRPC).

gcloud

To set a locational endpoint override, use the CLOUDSDK_API_ENDPOINT_OVERRIDES_PUBSUB environment variable with the applicable gcloud pubsub ... command. The following example uses a locational override to publish to a topic.

CLOUDSDK_API_ENDPOINT_OVERRIDES_PUBSUB=ENDPOINT_OVERRIDE \
gcloud pubsub topics publish TOPIC_ID \
--message=MESSAGE_DATA

Replace the following:

  • ENDPOINT_OVERRIDE: the locational endpoint override. Must be an absolute URI that begins with https:// and ends with a trailing /. For example, https://us-west1-pubsub.googleapis.com/.
  • TOPIC_ID: the ID of the topic.
  • MESSAGE_DATA: a string with the message data.

You can also set the a global CLOUDSDK_API_ENDPOINT_OVERRIDES_PUBSUB environment variable. If you do this, all your following Google Cloud CLI commands use the override, without requiring you to prefix the command. For example:

export CLOUDSDK_API_ENDPOINT_OVERRIDES_PUBSUB=ENDPOINT_OVERRIDE

List of locational endpoints

To send requests directly to a region, use the following locational Pub/Sub endpoints:

RegionJSON/HTTP endpointgRPC Service
africa-south1https://africa-south1-pubsub.googleapis.comafrica-south1-pubsub.googleapis.com:443
asia-east1https://asia-east1-pubsub.googleapis.comasia-east1-pubsub.googleapis.com:443
asia-east2https://asia-east2-pubsub.googleapis.comasia-east2-pubsub.googleapis.com:443
asia-northeast1https://asia-northeast1-pubsub.googleapis.comasia-northeast1-pubsub.googleapis.com:443
asia-northeast2https://asia-northeast2-pubsub.googleapis.comasia-northeast2-pubsub.googleapis.com:443
asia-northeast3https://asia-northeast3-pubsub.googleapis.comasia-northeast3-pubsub.googleapis.com:443
asia-south1https://asia-south1-pubsub.googleapis.comasia-south1-pubsub.googleapis.com:443
asia-south2https://asia-south2-pubsub.googleapis.comasia-south2-pubsub.googleapis.com:443
asia-southeast1https://asia-southeast1-pubsub.googleapis.comasia-southeast1-pubsub.googleapis.com:443
asia-southeast2https://asia-southeast2-pubsub.googleapis.comasia-southeast2-pubsub.googleapis.com:443
australia-southeast1https://australia-southeast1-pubsub.googleapis.comaustralia-southeast1-pubsub.googleapis.com:443
australia-southeast2https://australia-southeast2-pubsub.googleapis.comaustralia-southeast2-pubsub.googleapis.com:443
europe-central2https://europe-central2-pubsub.googleapis.comeurope-central2-pubsub.googleapis.com:443
europe-north1https://europe-north1-pubsub.googleapis.comeurope-north1-pubsub.googleapis.com:443
europe-north2https://europe-north2-pubsub.googleapis.comeurope-north2-pubsub.googleapis.com:443
europe-southwest1https://europe-southwest1-pubsub.googleapis.comeurope-southwest1-pubsub.googleapis.com:443
europe-west1https://europe-west1-pubsub.googleapis.comeurope-west1-pubsub.googleapis.com:443
europe-west10https://europe-west10-pubsub.googleapis.comeurope-west10-pubsub.googleapis.com:443
europe-west12https://europe-west12-pubsub.googleapis.comeurope-west12-pubsub.googleapis.com:443
europe-west2https://europe-west2-pubsub.googleapis.comeurope-west2-pubsub.googleapis.com:443
europe-west3https://europe-west3-pubsub.googleapis.comeurope-west3-pubsub.googleapis.com:443
europe-west4https://europe-west4-pubsub.googleapis.comeurope-west4-pubsub.googleapis.com:443
europe-west6https://europe-west6-pubsub.googleapis.comeurope-west6-pubsub.googleapis.com:443
europe-west8https://europe-west8-pubsub.googleapis.comeurope-west8-pubsub.googleapis.com:443
europe-west9https://europe-west9-pubsub.googleapis.comeurope-west9-pubsub.googleapis.com:443
me-central1https://me-central1-pubsub.googleapis.comme-central1-pubsub.googleapis.com:443
me-central2https://me-central2-pubsub.googleapis.comme-central2-pubsub.googleapis.com:443
me-west1https://me-west1-pubsub.googleapis.comme-west1-pubsub.googleapis.com:443
northamerica-northeast1https://northamerica-northeast1-pubsub.googleapis.comnorthamerica-northeast1-pubsub.googleapis.com:443
northamerica-northeast2https://northamerica-northeast2-pubsub.googleapis.comnorthamerica-northeast2-pubsub.googleapis.com:443
northamerica-south1https://northamerica-south1-pubsub.googleapis.comnorthamerica-south1-pubsub.googleapis.com:443
southamerica-east1https://southamerica-east1-pubsub.googleapis.comsouthamerica-east1-pubsub.googleapis.com:443
southamerica-west1https://southamerica-west1-pubsub.googleapis.comsouthamerica-west1-pubsub.googleapis.com:443
us-central1https://us-central1-pubsub.googleapis.comus-central1-pubsub.googleapis.com:443
us-east1https://us-east1-pubsub.googleapis.comus-east1-pubsub.googleapis.com:443
us-east4https://us-east4-pubsub.googleapis.comus-east4-pubsub.googleapis.com:443
us-east5https://us-east5-pubsub.googleapis.comus-east5-pubsub.googleapis.com:443
us-south1https://us-south1-pubsub.googleapis.comus-south1-pubsub.googleapis.com:443
us-west1https://us-west1-pubsub.googleapis.comus-west1-pubsub.googleapis.com:443
us-west2https://us-west2-pubsub.googleapis.comus-west2-pubsub.googleapis.com:443
us-west3https://us-west3-pubsub.googleapis.comus-west3-pubsub.googleapis.com:443
us-west4https://us-west4-pubsub.googleapis.comus-west4-pubsub.googleapis.com:443