Skip to content
Reference

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.

SettingTypeRequiredDefaultSecretDescription
projectIdstringYesNoGoogle Cloud project that owns the topics and subscriptions.
topicstringNoNoDefault topic a publish step sends to (an id, or projects/<project>/topics/<id>).
subscriptionstringNoNoDefault subscription a pull trigger reads (an id, or projects/<project>/subscriptions/<id>).
authTypeenum: workload-identity, service-account-keyNoworkload-identityNoworkload-identity: the engine's own Google service account (GKE). service-account-key: a stored JSON key.
credentialsobjectNo
credentials.serviceAccountKeystringNoYesService account JSON key (encrypted at rest). Used when authType is service-account-key.
timeoutnumberNo30000NoRequest 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.

ActionWhat it doesStep parametersKeys a message may supply
publishPublish 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.

json
{
  "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. With encoding: "base64", a base64 string is sent as those bytes. Without data, a text step input is the data.
  • attributes: string values only. At most 100, names up to 256 bytes and not starting with goog, 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, or projects/<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 sets ordering: "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's audience, and its serviceAccountEmail (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

  1. 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 = true creates the topic <name>-fhir-changes and wires the store to it, so only the subscription is left to create. By hand:

    bash
    gcloud 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
  2. Grant the engine roles/pubsub.subscriber on the subscription. In Terraform, set pubsub_subscriptions = ["fhir-changes-medhook"].

  3. Create a gcp-pubsub profile with projectId: "demo-health-dev" and subscription: "fhir-changes-medhook".

  4. Give the workflow a Pub/Sub trigger in pull mode on that profile. Each notification's trigger data carries a fhir object:

    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"
    }
  5. The next step reads the resource through a gcp-healthcare-fhir profile on the same store, by fhir.resourceType and fhir.resourceId. A FullResource notification already carries the resource as data. 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.

Reference