Adapter: Google Cloud Pub/Sub
Publish messages to a Pub/Sub topic with an ordering key and attributes, and receive them with a pull or push Pub/Sub trigger, including GCP Healthcare FHIR store change notifications.
On this page
Purpose
Publish messages to Google Cloud Pub/Sub topics from a destination step, and start workflows from Pub/Sub subscriptions with the Pub/Sub trigger. Google Cloud Healthcare FHIR store change notifications only arrive over Pub/Sub, so this is how a FHIR store write starts a workflow.
Auth
workload-identity(default): the engine's own Google service account on GKE, no stored key.service-account-key: a stored JSON key, encrypted at rest.
The Terraform module can grant the engine's service account roles/pubsub.publisher on named topics (pubsub_publish_topics) and roles/pubsub.subscriber on named subscriptions (pubsub_subscriptions). Both lists are empty by default. The connection test calls testIamPermissions, so no viewer role is needed.
Settings
Auth is chosen with authType: workload-identity, service-account-key (default workload-identity). Dotted names are fields inside an object setting. Secret settings are encrypted at rest, never returned by a read, and shown masked in the console and in exports; their defaults are not shown.
| Setting | Type | Required | Default | Secret | Description |
|---|---|---|---|---|---|
projectId | string | Yes | No | Google Cloud project that owns the topics and subscriptions. | |
topic | string | No | No | Default topic a publish step sends to (an id, or projects/<project>/topics/<id>). | |
subscription | string | No | No | Default subscription a pull trigger reads (an id, or projects/<project>/subscriptions/<id>). | |
authType | enum: workload-identity, service-account-key | No | workload-identity | No | workload-identity: the engine's own Google service account (GKE). service-account-key: a stored JSON key. |
credentials | object | No | |||
credentials.serviceAccountKey | string | No | Yes | Service account JSON key (encrypted at rest). Used when authType is service-account-key. | |
timeout | number | No | 30000 | No | Request timeout in milliseconds. |
Actions
A trailing ? marks an optional step parameter. A message can supply only the keys in the last column; everything else comes from the step.
| Action | What it does | Step parameters | Keys a message may supply |
|---|---|---|---|
publish | Publish one message: data (text, JSON or base64), attributes and an ordering key. | topic?, data, attributes?, orderingKey?, encoding? | data |
Minimal example
The smallest profile the engine accepts: the required settings only, with synthetic values. Create it with POST /api/adapter-profiles, then test it with POST /api/adapter-profiles/{id}/test.
{
"name": "Google Cloud Pub/Sub (example)",
"adapterType": "gcp-pubsub",
"config": {
"projectId": "demo-health-dev"
}
}Publishing
A destination step with the publish action (or the builder's default write) sends one message:
data: a string is sent as UTF-8, an object as JSON. Withencoding: "base64", a base64 string is sent as those bytes. Withoutdata, a text step input is the data.attributes: string values only. At most 100, names up to 256 bytes and not starting withgoog, values up to 1024 bytes.orderingKey: up to 1024 bytes. Messages with one key are delivered in order to subscriptions that have message ordering on.topic: overrides the profile's topic. It takes an id, orprojects/<project>/topics/<id>in the profile's project.
The step returns { topic, messageId }. A 4xx answer, other than 408, 425 or 429, fails the step without a retry. A request that was sent but got no answer is never resent, because Pub/Sub may already have the message.
Limits
- A message is at most 10 MB, with at most 100 attributes.
- A step only publishes. Receiving goes through the Pub/Sub trigger, so a message is never acknowledged before its run is recorded.
- A pull trigger runs on one engine replica at a time (a lease). Another replica takes it over when the lease lapses.
The Pub/Sub trigger
A pubsub trigger has two modes:
- pull: one engine replica holds the trigger's lease and pulls the subscription, up to
maxMessages(default 10) at a time. The subscription comes from the trigger, else from the profile.pullers(1-16, default 1) runs that many pull loops on the replica for more throughput. More than one is refused unless the trigger setsordering: "none", because messages then run out of order. - push: Pub/Sub posts each message to
POST /api/triggers/pubsub/<pushId>. Configure the push subscription with OIDC authentication. The route verifies the Google-signed token: the issuer, the trigger'saudience, and itsserviceAccountEmail(with a verified email). Pub/Sub's addresses are exempt from the IP allowlist for this path, as webhooks are.
In both modes a message is acknowledged only after its run is recorded as a pending execution, the same accept-then-process intake MLLP and webhooks use. Pull mode acknowledges after recording and nacks (ack deadline 0) anything it could not record. Push mode answers 2xx only after recording, and 503 otherwise. A message the trigger filter drops is acknowledged. A redelivered message is deduplicated by its message id within its subscription.
The run's trigger data has messageId, publishTime, orderingKey, attributes, subscription, deliveryAttempt and data. payloadFormat chooses how data is decoded: auto (the default) gives JSON when it parses and text otherwise, text always gives text, and base64 keeps the bytes as sent. With ordering: "fifo", runs share one lane per ordering key.
Recipe: FHIR store write → workflow
-
Create the notification topic and point the FHIR store at it, with the full resource or the name only. With the Terraform module's own store,
fhir_store_pubsub_enabled = truecreates the topic<name>-fhir-changesand wires the store to it, so only the subscription is left to create. By hand:bashgcloud pubsub topics create fhir-changes --project demo-health-dev gcloud healthcare fhir-stores update main --dataset demo --location us-central1 \ --pubsub-topic projects/demo-health-dev/topics/fhir-changes gcloud pubsub subscriptions create fhir-changes-medhook \ --topic fhir-changes --project demo-health-dev --enable-message-ordering -
Grant the engine
roles/pubsub.subscriberon the subscription. In Terraform, setpubsub_subscriptions = ["fhir-changes-medhook"]. -
Create a
gcp-pubsubprofile withprojectId: "demo-health-dev"andsubscription: "fhir-changes-medhook". -
Give the workflow a Pub/Sub trigger in pull mode on that profile. Each notification's trigger data carries a
fhirobject:json{ "action": "CreateResource", "resourceType": "Patient", "resourceId": "TESTPATIENT-1", "resourceName": "projects/demo-health-dev/locations/us-central1/datasets/demo/fhirStores/main/fhir/Patient/TESTPATIENT-1", "payloadType": "NameOnly", "storeName": "projects/demo-health-dev/locations/us-central1/datasets/demo/fhirStores/main" } -
The next step reads the resource through a
gcp-healthcare-fhirprofile on the same store, byfhir.resourceTypeandfhir.resourceId. AFullResourcenotification already carries the resource asdata. Then map it and send it on, for example to BigQuery or to an MLLP destination.
For push delivery instead, create a push subscription with --push-endpoint https://<engine>/api/triggers/pubsub/fhir-changes --push-auth-service-account <push SA>. Set the trigger's pushId to fhir-changes, its audience to the endpoint URL (or the subscription's --push-auth-token-audience), and its serviceAccountEmail to the push service account.
Mirth and Rhapsody
A Mirth or Rhapsody JMS channel that ran against a broker maps to a JMS profile and the JMS Listener on the same broker. Moving that traffic to Pub/Sub is a design change, not a one-to-one import, so the importer does not rewrite JMS connectors to Pub/Sub.
A Rhapsody Google Pub/Sub communication point does import: an input becomes a pull Pub/Sub trigger on its subscription, an output a publish step to its topic, each on a Pub/Sub profile with the point's project. See Migrating from Rhapsody.