HL7v2.MLLP.Client (HL7v2 v3.10.1)

Copy Markdown View Source

MLLP TCP client for sending HL7v2 messages.

Maintains a persistent TCP connection and provides synchronous send-and-receive for HL7v2 messages over MLLP.

Examples

{:ok, client} = HL7v2.MLLP.Client.start_link(host: "localhost", port: 2575)

{:ok, ack} = HL7v2.MLLP.Client.send_message(client, hl7_message)

:ok = HL7v2.MLLP.Client.close(client)

TLS

{:ok, client} = HL7v2.MLLP.Client.start_link(
  host: "remote.host",
  port: 2576,
  tls: [verify: :verify_peer, cacertfile: "ca.pem"]
)

Summary

Functions

Returns a specification to start this module under a supervisor.

Closes the client connection.

Sends an HL7v2 message and waits for the response.

Starts a client connection.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

close(client)

@spec close(GenServer.server()) :: :ok

Closes the client connection.

send_message(client, message, opts \\ [])

@spec send_message(GenServer.server(), binary(), keyword()) ::
  {:ok, binary()} | {:error, term()}

Sends an HL7v2 message and waits for the response.

MLLP is strictly request/response — one message sent, one ACK received. Terminal errors that close the connection and stop the client:

  • {:error, :protocol_desync} — stale bytes from a previous exchange
  • {:error, :message_too_large} — response exceeded :max_message_size

After either error the caller must start a new client to continue.

The message is MLLP-framed before sending. The response is returned with MLLP framing stripped.

Options

  • :timeout — override the default timeout for this call.

start_link(opts)

@spec start_link(keyword()) :: GenServer.on_start()

Starts a client connection.

Options

  • :host (required) — hostname or IP address to connect to.
  • :port (required) — TCP port to connect to.
  • :timeout — send/receive timeout in milliseconds (default: 30_000).
  • :max_message_size — maximum response size in bytes (default: 10_485_760 — 10 MB). Returns {:error, :message_too_large} if the response buffer exceeds this limit.
  • :tls — keyword list of :ssl options. When present, connects via TLS.