MLLP.Receiver (mllp v0.9.4)
A simple MLLP server. Minimal Lower Layer Protocol (MLLP) is an application level protocol which merely defines header and trailer delimiters for HL7 messages utilized in the healthcare industry for data interchange.
Options
The following options are required for starting an MLLP receiver either via start/1
or indirectly via
child_spec/1
:
:port
- The tcp port the receiver will listen on.:dispatcher
- Callback module messages ingested by the receiver will be passed to. This library ships with an echo only example dispatch module,MLLP.EchoDispatcher
for example purposes, which can be provided as a value for this parameter. Optional parameters::packet_framer
- Callback module for received packets. Defaults toMLLP.DefaultPacketFramer
:transport_opts
- A map of parameters given to ranch as transport options. See Ranch Documentation for all transport options that can be provided. The defaulttransport_opts
are%{num_acceptors: 100, max_connections: 20_000}
if none are provided.:context
- A map which will be kept in receiver. This state is also honored byMLLP.FramingContext
and made available toMLLP.Dispatcher
implementations as:receiver_context
onMLLP.FramingContext.t()
.
Link to this section Summary
Functions
A function which can be used to embed an MLLP.Receiver under Elixir v1.5+ supervisors.
Unlike start/1
, start/2
, or start/3
this function takes two additional options : ref
and transport_opts
.
Note that if a ref
option is not supplied a reference will be created for you using make_ref/0
.
Starts an MLLP.Receiver.
Link to this section Types
dispatcher()
Specs
dispatcher() :: any()
options()
Specs
options() :: [ port: pos_integer(), dispatcher: module(), packet_framer: module(), transport_opts: :ranch.opts(), context: map(), ref: term() ]
Specs
t() :: %MLLP.Receiver{ buffer: String.t(), context: map(), dispatcher_module: dispatcher(), socket: any(), transport: any() }
Link to this section Functions
child_spec(init_arg)
Specs
child_spec(options()) :: Supervisor.child_spec()
A function which can be used to embed an MLLP.Receiver under Elixir v1.5+ supervisors.
Unlike start/1
, start/2
, or start/3
this function takes two additional options : ref
and transport_opts
.
Note that if a ref
option is not supplied a reference will be created for you using make_ref/0
.
children = [{MLLP.Receiver, [
ref: MyRef,
port: 4090,
dispatcher: MLLP.EchoDispatcher,
packet_framer: MLLP.DefaultPacketFramer,
transport_opts: %{num_acceptors: 25, max_connections: 20_000}
]}
]
Supervisor.init(children, strategy: :one_for_one)
See Options for details on required and optiomal parameters.
Examples
iex(1)> opts = [ref: MyRef, port: 4090, dispatcher: MLLP.EchoDispatcher, packet_framer: MLLP.DefaultPacketFramer]
[
ref: MyRef,
port: 4090,
dispatcher: MLLP.EchoDispatcher,
packet_framer: MLLP.DefaultPacketFramer
]
iex(2)> MLLP.Receiver.child_spec(opts)
%{
id: {:ranch_listener_sup, MyRef},
start: {:ranch_listener_sup, :start_link,
[
MyRef,
:ranch_tcp,
%{socket_opts: [port: 4090], num_acceptors: 100, max_connections: 20_000},
MLLP.Receiver,
%{
packet_framer_module: MLLP.DefaultPacketFramer,
dispatcher_module: MLLP.EchoDispatcher,
context: %{},
allowed_clients: %{},
verify: nil
}
]},
type: :supervisor,
modules: [:ranch_listener_sup],
restart: :permanent,
shutdown: :infinity
}
normalize_ip(ip)
start(opts)
Specs
Starts an MLLP.Receiver.
{:ok, info_map} = MLLP.Receiver.start(port: 4090, dispatcher: MLLP.EchoDispatcher)
If successful it will return a map containing the pid of the listener, the port it's listening on, and the
receiver_id (ref) created, otherwise an error tuple.
Note that this function is in constrast with child_spec/1
which can be used to embed MLLP.Receiver in your
application or within a supervision tree as part of your application.
This function is useful for starting an MLLP.Receiver from within a GenServer or for development and testing
purposes.
See Options for details on required and optiomal parameters.
stop(port)
Specs
stop(any()) :: :ok | {:error, :not_found}