# `Alternera.Plugins.Camel.Source`
[🔗](https://github.com/10e-ab/alternera-camel/blob/v0.9.0/alternera_plugin_camel/lib/alternera/plugins/camel/source.ex#L1)

A Camel consumer route as a message source
(`Alternera.Plugin.Provisional.Source`), which a source trigger
reads: a route on one of the tenant's Camel hosts that ends at
`alternera:source:<name>` parks each delivery its consumer gets, and the
trigger's runner takes them, runs a pipeline once per message and settles
each by how its run ended. The host's side is `Sources` in its runtime
(`host_runtime`). A RabbitMQ (`spring-rabbitmq`) delivery is settled on its
channel; any other consumer's by how its exchange completes (`GenericSource`
there): done for an ack, failed for a reject, a retry or a give-back, the
route's own error handling deciding.

Its settings: `host`, the Camel host, `source`, the name its route ends
at, and `delivery`, how the messages reach the proxy:

  * `push` (the default): the host sends each delivery as it comes, over
    the host's frame channel, to an inbox on the proxy
    (`Plugins.Camel.Inbox`), while fewer than the trigger's prefetch are
    held; a receive takes from the inbox and polls nothing. The open,
    settle, extend and close are `source` frames (`Host.source/3`) to the
    member the source opened on, so any host protocol serves, and they are
    not recorded (`record_source_calls` has nothing to record);
  * `pull`: the runner long-polls the host over its HTTP channel, so the
    host's `protocol` must serve HTTP (`:http1`, `:http2`, `:https1` or
    `:https2`).

How long a poll waits, how long a message is held and how many come at
once are the runner's.

A pulled source's calls go over the host's HTTP channel (`PluginHosts.Endpoint`), each
through `Plugin.Provisional.Outbound` with the host as its upstream, as a
Camel step's calls do, so the trigger's `record_source_calls` records
them; they are the plugin's calls, made as no proxy user:

  * open: `POST /sources/<name>/open` with the trigger's `prefetch`, the
    messages it may hold at once (`max_messages` of the context), which a
    route's `prefetchCount={{alternera:source:prefetch}}` takes. The
    host checks the route, starts it and answers a session. The source
    keeps the member it opened on (its process, port and token) for the
    session: the deliveries are parked in that member's memory, so every
    later call goes to it. A member that restarted has another port and
    token: its calls fail, a receive's as `session_lost` (the runner opens
    the source again), a settle's as `gone` for each handle (the broker
    has delivered it again);
  * receive: `POST /sources/<name>/receive`, a long poll of up to the
    runner's wait;
  * settle and extend: `POST /sources/<name>/settle` and `…/extend`,
    every handle answered on its own;
  * close: `POST /sources/<name>/close`: the host gives back what it
    holds and stops the route.

A `{:retry, delay}` is kept by the host for the delay, then requeued: the
broker (RabbitMQ) redelivers a requeued message at once, so a member that
dies during the delay has it delivered again sooner.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
