MLLP and ACKs
How the MLLP listener frames messages, which ACK it sends and when, how resends are dropped, and how outbound sends read ACKs.
On this page
The MLLP listener receives HL7v2 messages over TCP and answers each one with an ACK. It runs as its own container and passes every message to the engine. The engine decides the ACK code, and the listener builds the reply.
sequenceDiagram
participant Sender as Sender (test system)
participant Listener as MLLP listener
participant Engine as MedHook engine
Sender->>Listener: VT, ADT^A01, FS, CR
Listener->>Engine: POST /api/triggers/mllp
Engine->>Engine: Match triggers, write a pending execution
Engine-->>Listener: ack AA
Listener-->>Sender: VT, ACK (MSA AA), FS, CR
Engine->>Engine: Run the workflowListeners
The listener default is on MLLP_PORT. Your deployment can declare more listeners in Helm mllp.listeners, for example one port per sending system, or a TLS port. Each MLLP trigger names the listener it takes messages from (listener, default default), so a message that arrives on one port never runs a workflow whose trigger is on another.
A TLS listener serves TLS 1.2 or later from a Kubernetes Secret, and can require a client certificate. If its certificate files cannot be read, the listener does not start. It never falls back to plaintext.
ackMode | What the sender gets |
|---|---|
original (default) | AA, AE or AR, whatever MSH-15 says. Epic and most senders expect this, even when they set MSH-15 to AL. |
msh15 | A message that sets MSH-15 gets a commit ACK, CA, CE or CR, sent only as MSH-15 asks: AL always, NE never, ER only for CE/CR, SU only for CA. A message with an empty MSH-15 gets an original-mode ACK. |
MSH-16 (application acknowledgment) is ignored. The listener never sends a separate application ACK, because that needs a connection back to the sender.
Framing
A message is framed as a start byte 0x0B, the message, then 0x1C 0x0D. The listener buffers bytes on a connection until it sees a full frame, so a message can arrive in pieces, and one packet can hold several messages. Bytes that arrive before a start byte are dropped.
The listener handles the frames of one connection one at a time, in the order they arrive, and sends the ACK for each before it forwards the next. An A08 cannot overtake the A01 before it. It closes a connection that has been idle for 5 minutes.
| Setting | Default | What it does |
|---|---|---|
MLLP_PORT | 2575 | The TCP port senders connect to. |
MLLP_HOST | 0.0.0.0 | The interface the listener binds to. |
MLLP_TIMEOUT | 30000 | Milliseconds the listener waits for the engine before it answers AE. |
MLLP_MAX_FRAME_BYTES | 10485760 (10 MiB) | The largest message accepted in one frame. A bad value falls back to the default, with a warning in the log. |
ENGINE_URL | the engine service | Where the listener sends messages. |
MLLP_ENGINE_TOKEN | none | The token the engine requires from the listener. At least 32 characters. |
HEALTH_PORT | 8080 | The listener's health endpoint. |
Bad and oversized frames
The AR for a bad frame and the frame cap start with 1.0.0-rc.14.
The listener always answers. It never leaves a sender waiting.
- A frame with no usable MSH (garbage, an empty frame, an MSH without its field separator, or an empty MSH-9) gets
ARwithin a second. MSA-2 holds the control ID when one can be read, and MSA-3 holds a short reason such as "Message has no valid MSH segment".ARis final, so the sender stops resending a message that will never parse. - A frame larger than
MLLP_MAX_FRAME_BYTESgetsARwhen its MSH can be read from the start of the frame. The listener then closes the connection.
The listener logs the sender's address and the reason only, never the message.
ACK codes
The ACK carries the code in MSA-1 and the original message's MSH-10 in MSA-2. For AE and AR, MSA-3 holds a short reason that never contains message content.
| Code | Means | The engine sends it when | The sender should |
|---|---|---|---|
AA | Accepted | Every matched workflow has a durable pending execution. Or the message is a resend of an MSH-10 the engine already accepted. | Treat it as delivered. |
AE | A temporary error | The engine could not record the message: the database is down, the engine is shutting down, or the first delivery of this MSH-10 is still being recorded. Or the only workflows that take it are deployed but turned off: MSA-3 is Receiving application is paused; resend later. The listener also sends AE when the engine is unreachable, does not answer within MLLP_TIMEOUT, or answers with an error status. | Send it again later. |
AR | Rejected for good | No trigger takes this message type, sender or filter: MSA-3 is No matching triggers for message type …. A draft that was never deployed takes no messages, so it gets this answer too. Or every matched workflow is blocked, for example by PHI enforcement. | Not resend. It will get the same answer. |
AA means the engine has the message safely. It does not mean the workflow has finished. The workflow runs after the ACK, so a later failure shows on Messages › Needs action, not in the ACK.
A workflow that was deployed and is now turned off is paused: it answers AE, so the sender keeps the message and resends it, and messages it already accepted wait and run when it is turned back on. A draft never deployed is different: it has no trigger route yet, and a message only it would take is AR No matching triggers. Imported Mirth channels arrive as such drafts, so they take no traffic until you deploy them.
If some matched workflows accept and others are skipped, the answer is AA and the skipped ones are listed as warnings in the engine's reply.
ACK from the destination
By default the engine answers AA as soon as it has recorded the message. A sender that wants to know the message was delivered can get that instead: set ackMode: "destination" on the trigger. The engine still records the message first, then waits for the workflow's destinations, up to ackTimeoutMs (20 seconds by default, and never longer than MLLP_TIMEOUT minus 5 seconds):
| Destinations | ACK | MSA-3 |
|---|---|---|
| Every one completed | AA | |
One rejected the message for good (for example AR) | AR | Destination rejected the message |
An hl7-validate step rejected it: segments or type | AR | HL7 conformance: SEGMENT_MISSING PV1 |
An hl7-validate step rejected it: a field rule | AE | HL7 conformance: FIELD_REQUIRED PID-5 |
| Any other failure | AE | Destination failed; retry |
| Not finished in time (retrying, or the lane is held) | AE | Destination did not finish in time; retry |
When the sender resends a message whose delivery failed, the engine replays it once and waits on the replay. Two resends that arrive together still start only one replay. The destination's own ACK is not passed through, because its MSA-2 and MSH-3 to MSH-6 name another message and other systems.
One connection handles one message at a time, so while a destination is slow, that sender waits too. That is the point: it slows the sender down. A held lane always answers AE at the deadline, so the sender keeps resending until you clear the hold on Messages › Needs action. Watch Needs action and the AE rate while a destination is down.
A message with MSH-15 set that arrives on an msh15 listener gets its commit ACK without waiting. On an original listener the wait happens whatever MSH-15 says, so a sender that sets MSH-15 to AL still gets the destination's outcome.
ACK from a Respond step
To answer with your own ACK, as Mirth's Respond from a destination or a Rhapsody custom ACK does, set ackMode: "respond" on the trigger and put a Respond step in the workflow. The engine records the message first, then waits for the run as in destination mode, up to ackTimeoutMs, and sends the ACK the Respond step built.
The Respond step's input is the ACK:
- Text that starts with
MSH: the whole ACK, sent as built. - Other segments, such as
MSA|AE||Unknown patientand anERRsegment: the listener puts its own MSH before them. They must contain an MSA; an empty MSA-2 gets the inbound control id. - An object
{ code, text, errors }: the MSA and ERR segments are built with the sender's separators, every value escaped.
| The run | What the sender gets |
|---|---|
| Its Respond step built an ACK | That ACK, even when a later step failed. With ackOnFailure: "AE", a run that failed answers AE. |
| It finished with no usable Respond output | The outcome ACK, as in destination mode. |
It did not finish within ackTimeoutMs | ackTimeoutCode: AE (default, the sender resends) or AR (the sender gives up; the run still runs). |
| The message matched more than one workflow | The outcome ACK: there is no single Respond step to answer with. |
The ACK sent is stored with the run, sealed like message content, and shown in the run view and on Needs action. As in destination mode, each sender connection waits for its message's run, so a slow workflow slows that sender. The Mirth importer maps a TCP Listener's Respond from to respond or destination, and the exporter writes it back.
MSH-11 echo
The ACK echoes the processing ID of the message it answers. A test feed (T) gets a test ACK, and a debug feed (D) gets a debug ACK. A processing mode after a caret, as in T^A, is kept. If MSH-11 is empty or is anything else, the ACK says P. The ACK also swaps the sending and receiving application and facility, sets MSH-9 to ACK, uses a new control ID, and repeats the sender's version in MSH-12 (2.5.1 if absent).
Resends and MSH-10
Senders resend a message when they miss the ACK. The engine drops the repeat so a patient is not handled twice.
- The key is the workflow, the sending application and facility (MSH-3 and MSH-4), and MSH-10.
- A repeat is the same message: the engine compares a SHA-256 of the message, leaving out MSH-7 (the message time, which some senders re-stamp on a resend) and line endings. A repeat gets
AAwithduplicate: trueand the original execution ids. Nothing runs again. - A different message that reuses an MSH-10 (many senders reuse control IDs after a restart or when the counter rolls over) is a new message: it runs, and the engine logs
dedup_key_reusedand counts it inmedhook_inbound_dedup_key_reused_total. Resends answered without running count inmedhook_inbound_dedup_hits_total. - A repeat that arrives while the first is still being recorded gets
AE, so the sender tries again. - A message with no MSH-10 is never treated as a repeat.
- The engine remembers keys for
INBOUND_DEDUP_TTL_HOURS(24 by default). It stores identifiers and the one-way hash, never the message. - A trigger turns this off with
deduplicate: false. If the receipt table cannot be reached, the engine processes the message, because losing one is worse than a rare duplicate.
Batches
With splitBatches: true on the trigger, a frame that holds an HL7 batch (FHS and BHS headers, or more than one MSH) becomes one execution per message, in batch order, in each message's sending-facility lane. Each message is matched against the trigger on its own (message type, MSH-3, MSH-4, filter) and deduplicated on its own MSH-10. A message that appears twice in one batch runs once. ACK messages inside a batch are skipped. All the messages are recorded together, or none are.
An HL7 batch is acknowledged with a batch (HL7 v2.5.1 section 2.10.3), so the listener answers in one frame:
| Segment | What it holds |
|---|---|
| FHS | Sent only when the inbound batch had an FHS. Sender and receiver swapped. |
| BHS | A new BHS-11, and BHS-12 set to the inbound BHS-11 so the sender can match the reply to its batch. |
| MSH/MSA | One ACK per message, every message, not only errors. MSA-2 is that message's MSH-10. |
| BTS | BTS-1 is the number of ACKs in the batch. |
| FTS | Sent only when the inbound batch had an FHS. |
Each message's code is decided on its own:
| Code | When |
|---|---|
| AA | Recorded, or a resend of one already recorded. |
| AR | No trigger takes that message type (a never-deployed draft takes none), its workflow is blocked, or the message is malformed (MSA-3 says why, never the content). |
| AE | The engine could not record the batch. Every message gets AE, and the sender resends the batch. Messages already recorded are dropped as duplicates. A message whose only workflow is deployed but turned off also gets AE (paused). |
On a listener in msh15 mode, each message's own MSH-15 decides whether its ACK is sent and with which commit code. When no message asks for an ACK, nothing is sent.
A batch of more than 500 messages is refused with AR for the frame. splitBatches cannot be combined with ackMode: "destination" or "respond": a batch is ACKed once it is recorded, and a save with both is refused. Without splitBatches, a batch frame is one execution and gets one ACK, for its first MSH.
A listener image older than this release ignores the per-message outcomes and sends a single ACK with the worst code (AE before AR before AA). AE makes the sender resend, and the messages already recorded are dropped as duplicates.
Character sets
The listener forwards every frame as it came. A trigger's charset decides how the bytes are decoded before anything parses them:
charset | Decoding |
|---|---|
utf-8 (default) | UTF-8. |
iso-8859-1 | ISO-8859-1 (Latin-1): every byte is the character with that code. |
windows-1252 | Windows-1252. It differs from ISO-8859-1 in 0x80 to 0x9F, where it has € and typographic quotes. |
ascii | ASCII. A byte above 0x7F is read as ISO-8859-1, so nothing is lost. |
msh-18 | The message's MSH-18: 8859/1 is ISO-8859-1, UNICODE UTF-8 is UTF-8, ASCII is ASCII. Empty is UTF-8. |
An MSH-18 value MedHook does not support is read as UTF-8, and the message is still processed. Filters, mappings and the stored message all see the decoded text, so a name such as ZZTEST^Zoë reaches the workflow intact.
The ACK is ASCII text. Its MSH-3 to MSH-6 echo the sender's: a non-ASCII character there is sent back as a replacement character.
Failures after the ACK
The engine writes a pending execution before it ACKs. Any engine replica runs it, so a restart loses nothing: another replica picks it up.
Messages from one sending facility (MSH-4) through one trigger run one at a time, in arrival order, across every replica. Set onError: "hold" on the trigger to stop that facility's messages after a failed one, until a retry or a replay of it succeeds or you skip it on Messages › Needs action. The default, "continue", runs the next message.
Outbound sends
The MLLP adapter sends one message and reads the ACK. The message is the step's message, or the step's input when that is HL7 text, such as the output of an fhir-to-hl7v2 or template step. It keeps up to 10 connections per host:port, and TLS and plain connections are never shared.
| Reply or event | What the step does |
|---|---|
AA whose MSA-2 is the MSH-10 sent | Succeeds. The result holds sent, ackType and the receiver's message id. |
AE | Fails, and the step's retry setting may send it again. |
AR | Fails and is not retried automatically. The receiver refused it for good. |
No reply within ackTimeoutMs (else timeout) | Fails as uncertain. The receiver may already have the message, so the engine does not resend it on its own. |
No connection within connectTimeoutMs (else timeout) | Fails as not sent. The step's retry setting may try again. |
CA, CE or CR, an ACK with no MSA or an unknown code | Fails as "delivery uncertain" and is never resent automatically. A commit ACK does not say what the application did. |
| An ACK whose MSA-2 names another message | Fails as "delivery uncertain", is never resent, and the connection is dropped because it is out of step. |
| The message has no MSH-10 | Refused before anything is written: no ACK could be matched to it. Not sent. |
Settings on the profile:
expectAck: falseis for receivers that never answer. The step succeeds once the frame is written, and the result hasackType: null. A failure after the write started is uncertain and is never resent.- TLS. Set
tlsEnabled, then either pin the receiver's certificate withtlsFingerprint256(its SHA-256 fingerprint,AA:BB:...) or give the CA that signed it intlsCaPem. A pinned certificate is checked before any byte of the message is sent. With a CA, the host name must match too (tlsServernamesets the name to check). With neither, the system CA store is used. AddtlsClientCertPemandtlsClientKeyPemwhen the receiver wants a client certificate. There is no setting that turns verification off. A profile that sets any of these withouttlsEnabledis refused when it is saved and when it sends, so a message never goes out in plaintext to a receiver the profile pins. encodingis the character set of the bytes sent and of the ACK:utf-8(default),iso-8859-1,windows-1252,ascii, ormsh-18to follow the outgoing message's MSH-18. A message with a character the encoding cannot carry fails before anything is written, as not sent, and the error names only the position.sendingApplication/sendingFacilityoverwrite MSH-3 and MSH-4 of every message, for receivers that route on them. MSH-10 does not change, so ACK matching is the same.
A failed send leaves the execution failed. After the receiver is fixed, replay it. See Executions and replay.
Test it
Send this synthetic message to the listener with a tool that frames MLLP, such as nc or mllp-send. See Send test messages over MLLP. The T in MSH-11 marks it as a test.
MSH|^~\&|EHR_A|FACILITY_A|ENGINE|MEDHOOK|20260101120000||ADT^A01|MSG0001|T|2.5.1
PID|1||MRN0001||TESTPATIENT^SAMPLE
PV1|1|IWith an enabled workflow whose MLLP trigger takes ADT^A01, the ACK looks like this:
MSH|^~\&|ENGINE|MEDHOOK|EHR_A|FACILITY_A|20260101120001||ACK|ACK...|T|2.5.1
MSA|AA|MSG0001|Send the same message again and you get AA again, with no second execution. Send an ORU^R01 to a trigger that takes only ADT and you get AR with No matching triggers for message type ORU^R01 in MSA-3.
Troubleshooting
- The sender gets
AEand nothing runs. The engine is down or slow. CheckGET /api/healthand the listener'sMLLP_TIMEOUT. - The sender gets
AR. No trigger matches. Check the message types, sending facility, sending application and filter. A workflow never deployed (an imported Mirth draft, for example) takes no messages until you deploy it. A workflow blocked by PHI enforcement also answersAR. - The sender gets
AE"Receiving application is paused; resend later". The workflow that takes the message was deployed and is turned off. Turn it back on; the sender's resends then go through. - A message shows
AAbut its workflow failed. The ACK only confirms receipt. Open the message in Messages, then replay it. - The sender reports a timeout. The listener waits up to
MLLP_TIMEOUTfor the engine. Keep your sender's reply timeout longer than that.