Alternera.Plugins.Camel.Inbox (alternera_plugin_camel v0.9.0)

Copy Markdown View Source

Where a pushing Camel source's messages wait on the proxy until the trigger's runner takes them (Plugins.Camel.Source, delivery push).

The host sends each delivery to the sink its open named, in a messages frame (PluginHosts.Host.subscribe/3), while fewer than the open's prefetch are held; the inbox queues them, and a receive takes up to its max, waiting up to its wait for the first (take/3). So nothing polls the host: an idle source costs one frame every @beat_ms.

A pushed delivery is held on the host for hold_ms/0 from its push. Every @beat_ms the inbox extends what is still queued by that hold again, in one extend frame, which also tells the host the session is in use (an empty one included): without it an idle session closes after the host's SESSION_IDLE_MS. A handle the extend answers gone lapsed and leaves the queue. Once taken, a message's hold is the runner's.

The session is lost when the host says so ("closed", or host_down when its process ended), when an extend answers unknown_session, or when the Host process goes: a take answers session_lost and the runner opens the source again. An inbox whose session nobody used for @idle_ms (no take, and no settle or extend through touch/1: a runner whose every slot runs a long message takes nothing, but extends their holds) belongs to a runner that went away without closing it: it closes the session and stops.

Summary

Functions

Returns a specification to start this module under a supervisor.

How long the host holds a pushed delivery before the inbox extends it.

The session the open answered: the inbox starts holding its messages for it.

Starts an inbox for source on the Host host under the sink sink, subscribed before the open is sent, so no message finds no sink. Its beat starts at once, so an inbox whose open never answered (its opener crashed between the two) still closes as idle. opts are for tests: :beat_ms and :idle_ms.

Stops the inbox, its sink dropped; what it still queued lapses back to the host.

Up to max messages as the host sent them, waiting up to wait_ms for the first: {:ok, messages} ([] when none came) or {:error, "session_lost", message}.

The session is in use: a settle or an extend of what the runner holds.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

hold_ms()

How long the host holds a pushed delivery before the inbox extends it.

opened(inbox, session)

@spec opened(pid(), String.t()) :: :ok

The session the open answered: the inbox starts holding its messages for it.

start(host, source, sink, codec, opts \\ [])

@spec start(pid(), String.t(), String.t(), :json | :msgpack, keyword()) ::
  {:ok, pid()} | {:error, term()}

Starts an inbox for source on the Host host under the sink sink, subscribed before the open is sent, so no message finds no sink. Its beat starts at once, so an inbox whose open never answered (its opener crashed between the two) still closes as idle. opts are for tests: :beat_ms and :idle_ms.

start_link(args)

stop(inbox)

@spec stop(pid()) :: :ok

Stops the inbox, its sink dropped; what it still queued lapses back to the host.

take(inbox, max, wait_ms)

@spec take(pid(), pos_integer(), non_neg_integer()) ::
  {:ok, [map()]} | {:error, String.t(), String.t()}

Up to max messages as the host sent them, waiting up to wait_ms for the first: {:ok, messages} ([] when none came) or {:error, "session_lost", message}.

touch(inbox)

@spec touch(pid()) :: :ok

The session is in use: a settle or an extend of what the runner holds.