Topics
Typed publish and subscribe between workflows. One workflow publishes an event, every subscribing workflow gets its own durable copy, with ordering, retries, dead letters and replay.
On this page
A topic connects workflows the way services connect. One workflow publishes an event to a named topic, such as adt.admit. Every workflow with a Topic trigger on that topic gets the event, each as its own durable run. The publisher does not wait for them, and a subscriber that fails never holds the others back.
How it works
A Publish to topic step checks the message against the topic's schema, records the event, and writes one pending execution for each subscriber, all in one database transaction. The work runner then runs each delivery on any engine replica, like any other queued run. There is no separate message broker: the engine's own durable work table carries every delivery, so a restart loses nothing.
sequenceDiagram
participant ADT as ADT intake workflow
participant Engine as MedHook engine
participant FHIR as FHIR store workflow
participant BQ as BigQuery workflow
participant Notify as Notifications workflow
ADT->>Engine: Publish to topic adt.admit
Engine->>Engine: Check the schema, record the event and three deliveries
Engine->>FHIR: Delivery 1
Engine->>BQ: Delivery 2
Engine->>Notify: Delivery 3 (fails, retried, then a dead letter)Delivery is at least once, and deduplicated by event id. The event id comes from the publishing run, the step, the message and, inside a loop, the item's position, so a retried step, a workflow retry or a recovered run publishes the same event again and nothing new is delivered, while two identical items of one loop are two events. A subscriber added after the event was first published gets it the next time the event is published.
Publishers and subscribers are the workflows as deployed. Saving a workflow that adds, changes or removes a Topic trigger or a Publish step changes nothing for production traffic until the workflow is deployed, like every other trigger.
Topic settings
Create topics on Workflows → Topics. The name is the topic's key in the workspace and cannot be changed.
| Setting | What it does |
|---|---|
| Name | Lower-case letters, digits, - and _, in parts separated by dots: adt.admit, lab.result-final. At most 100 characters. |
| Description | Shown on the Topics page. |
| Event schema | Optional JSON Schema every event must match. Empty takes any event. |
| Ordering key | Optional field path read from each event, such as MSH.4 (the sending facility) or $.facility. Events with the same value reach each subscriber one at a time, in publish order, even when several runs publish at once. |
| Retries before a dead letter | 0 to 10, default 3. A subscriber workflow's own retry setting wins when it is higher. Each delivery keeps the retries the topic had when the event was published. |
| First retry after | Seconds before the first retry, default 30. Later retries back off, up to 30 minutes. |
| When an ordered delivery fails | With an ordering key: go on with the key's next event (default), or hold that subscriber's events for the key until the failed one succeeds or is skipped on Messages › Needs action. |
Event schema
MedHook checks events against this part of JSON Schema. Saving a topic refuses any other keyword, so what the schema says is what a publish enforces.
| Keyword | Checks |
|---|---|
type | string, number, integer, boolean, object, array, null, or a list of them. |
properties, required | Named fields and which must be present. |
additionalProperties | false refuses fields not in properties; a schema checks them. |
items, minItems, maxItems | Every item of a list, and how many there are. |
enum, const | One of a fixed set of values, or one fixed value. |
minimum, maximum | Number bounds. |
minLength, maxLength | Text length. |
title, description, $schema, $id | Documentation only. |
A message that does not match fails the Publish step and is not retried: it would fail the same way. The error names each field and the rule, never the value, because events are often PHI.
A raw HL7 v2 message is published as text: give the topic { "type": "string" }, or no schema. To publish a structured event, map the message first with a Data map or JavaScript output.
Publish to topic
In the steps view, open a destination and set Send to to a topic, then pick the topic. The destination's filter and output steps run first, as for any destination. In the graph view, add Publish to topic from Add node.
The step's output is the message with topicEventId and topic added. The run does not wait for the subscribers. A dry run (Run with sample) checks the topic and the schema and lists the subscribers it would reach, and writes nothing.
Topic trigger
Set a workflow's trigger to Topic and pick the topic. The workflow then runs once for every event. Its input is the event as published. A chain of workflows that publish to each other stops at five levels, so a topic loop cannot run forever.
The Topic page
Each topic has a page under Workflows → Topics.
| Section | Shows |
|---|---|
| Publishers | Workflows with a Publish step on the topic. |
| Subscribers | Workflows with a Topic trigger on it, with lag (deliveries waiting and the oldest one's age) and dead letters. |
| Recent events | The 50 newest events, who published each, and every subscriber's delivery state. View message shows the event's content. |
| Dead letters | Deliveries of the last 7 days that ran out of retries, with the last error, Open run and Replay. |
| Schema and settings | The topic's settings, editable. Saving a change that reaches deployed workflows asks first (see below). |
A delivery's state is the state of its newest attempt:
| State | Meaning |
|---|---|
| Waiting | Queued, not started yet. |
| Running | A replica is running it. |
| Retrying | An attempt failed and a retry is queued. |
| Delivered | The subscriber's run completed. |
| Dead letter | It failed and has no retries left. Replay it from the Topic page. |
| Cancelled | Someone cancelled the run. |
| Removed by retention | The runs were removed by execution retention. |
Replay queues the dead letter again in its delivery, keeping its place in an ordered lane, so the Topic page counts it as the next attempt.
Changing a topic in use
A topic is a shared interface: a change to its schema, ordering key or retries applies at once to every deployed publisher and subscriber. So Save changes checks first and, when a deployed workflow uses the topic, asks you to confirm. The confirmation lists:
- the publishing and subscribing workflows, as deployed;
- for a new schema, how many of the last 50 events it would now reject, and why (by field, never by value). Their publishers' steps fail until they send what the schema asks for;
- for a new ordering key, that ordering restarts: events already waiting finish in their old order, and new events are ordered by the new key;
- for new retries, that they apply to new events only.
The same check is available to API clients as POST /api/topics/{name}/impact.
PHI and audit
The Topics and Topic pages show ids, names, states, timings and errors, never message content, so viewers can use them. View message returns the event's content only to operators and admins, and every read is audited as topic.event_viewed. Creating, changing and deleting a topic are audited (topic.created, topic.updated, topic.deleted). A subscriber that handles PHI is checked against the engine's license like every other entry point; when it is refused, that subscriber is skipped, the refusal is audited as topic.phi_blocked, and the other subscribers still get the event. As on the other entry points, the check applies on a PHI-only deployment (MEDHOOK_PHI_ALL=true), where every workflow is treated as handling PHI.
An ordered lane's name carries a keyed hash of the ordering key's value (an HMAC with the engine's secret), never the value, so an MRN used as the key cannot be recovered from lane names. Rotating ENCRYPTION_MASTER_KEY starts new lanes; deliveries already waiting finish in their old ones.