Overview
A client-mode connector that moves broker data in and out of Google Cloud Pub/Sub over the REST v1 API. Use it to stream plant telemetry into Google Cloud (Dataflow, BigQuery subscriptions, Cloud Run, Vertex AI) or to pull commands and results back into MQTT, without running a gRPC client.
Default
BASE_ADDRESS is https://pubsub.googleapis.com (no trailing slash). project_id, topic and subscription are short ids taken from the MQTT payload. Topics use data/google-cloud-pub-sub/<object>/<verb>; replies land on <topic>/response.
See the base guide: REST API Connectors.
Auth:
Authorization: Bearer {value.json.access_token}, an OAuth 2.0 access token minted from a service account with scope https://www.googleapis.com/auth/pubsub (or cloud-platform). Grant roles/pubsub.publisher to publish and roles/pubsub.subscriber to pull and acknowledge; creating topics and subscriptions needs roles/pubsub.editor. Keep the key in Hub secrets (suggested name GCP_PUBSUB_ACCESS_TOKEN) and refresh the token upstream (tokens last about one hour). Never commit keys into the .lot.Base64 is your job. Pub/Sub requires
data to be base64. The connector forwards the payload as-is and does not encode, so encode upstream (for example in a Python script called from an action; base64 is available) or have the device publish base64. Pulled messages come back base64-encoded too. This template has been smoke-tested against the Pub/Sub emulator only, not yet against a live Google Cloud project.Basic Syntax
MQTT examples
Publish (data/google-cloud-pub-sub/messages/publish), expect 200 {"messageIds":["..."]}:
data above is base64 of {"DeviceId":"press-01","temp":37.2}. Up to 1000 messages and 10 MB per request.
Pull (data/google-cloud-pub-sub/messages/pull), expect 200 with receivedMessages (or {} when nothing is waiting):
data/google-cloud-pub-sub/messages/ack), expect 200 {}:
data/google-cloud-pub-sub/messages/ack-deadline), expect 200 {}. Use 0 to nack so the message is redelivered right away:
data/google-cloud-pub-sub/topics/create), expect 200 with the topic resource:
data/google-cloud-pub-sub/subscriptions/create), expect 200 with the subscription resource:
data/google-cloud-pub-sub/topics/list): {"project_id": "my-plant-project", "page_size": "50", "access_token": "ya29.<service-account-access-token>"}.
body becomes the HTTP body, so control fields (project_id, topic, subscription, access_token, page_size) are never sent to Google.
Getting an access token
For a quick test, with the service account active in the Google Cloud CLI:https://oauth2.googleapis.com/token) in a helper that reads the key from Hub secrets, and refresh it before the one-hour expiry.
Push subscriptions (companion, not packaged)
Pub/Sub can also push messages to an HTTPS endpoint (pushConfig.pushEndpoint on CreateSubscription). Each delivery is a POST with a JSON envelope {"message": {"data", "attributes", "messageId", "publishTime", "orderingKey"}, "subscription": "projects/.../subscriptions/..."}, and a 200, 201, 202, 204 or 102 reply acknowledges it. Receiving pushes needs a separate ENABLE_SERVER REST API connector on a publicly reachable HTTPS address (optionally verifying the OIDC token Pub/Sub adds to Authorization). That companion connector is not part of this template.
Notes
- Strict ordering by
orderingKeyneedsenableMessageOrderingon the subscription and publishing through one regional endpoint (for examplehttps://europe-west1-pubsub.googleapis.com). - Pull can hold the request open for a bounded time when the subscription is empty, so
REQUEST_TIMEOUTis120.returnImmediatelyis deprecated. - The emulator (
gcloud beta emulators pubsub start) speaks the same REST API onhttp://localhost:8085, ignores auth, and is handy for local tests. SetUSE_SSL "false"and pointBASE_ADDRESSat it. - Not covered: deletes, seek and snapshots, schemas, IAM policy calls, StreamingPull (gRPC only).
- Suggested branches:
feat/rest-api-route-google-cloud-pub-sub,feat/docs-rest-api-google-cloud-pub-sub(Hugo pushes).

