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

An SQS queue as a message source
(`Alternera.Plugin.Provisional.Source`), which a source trigger
reads: the proxy's runner polls it, runs a pipeline once per message and
settles each message by how its run ended.

Its settings are the queue's and the credentials': `queue_url`,
`region` (needed unless an AWS queue URL's host names it),
`access_key_id` and `secret_access_key`, one tenant secret reference
revealed when the source opens. A source stands in no pipeline, so no
Configuration step fills them: each is set here, and a tenant variable
(`{{NAME}}`) fills a plain one when the source opens. How long a poll
waits, how long a message stays hidden and how many come at once are the
runner's, not settings.

The calls (`Sqs.Client` signs and reads them):

  * receive: `ReceiveMessage` with `MaxNumberOfMessages` the runner's
    free slots (at most 10), `WaitTimeSeconds` the runner's wait (at most
    20) and `VisibilityTimeout` the hold in seconds, rounded up, with
    every message and system attribute; the call may take the wait and
    5 000 ms more;
  * settle: an ack is a `DeleteMessageBatch`, a retry (and a reject,
    which the queue's redrive policy moves on) a
    `ChangeMessageVisibilityBatch` with the delay in seconds, rounded
    up, at most 43 200; ten entries a call, each handle answered on its
    own from the batch's `Successful` and `Failed`. A handle whose hold
    lapsed is refused by SQS, and answers `sqs_failure`;
  * extend: a hold kept alive (`extend_hold`) is a
    `ChangeMessageVisibilityBatch` with the new hold in seconds, rounded
    up, which SQS counts from the call. SQS caps a message's hold at
    12 hours from its first receipt whatever is extended; the proxy never
    asks past the hold it would have received with.

A message's `id` is its `MessageId`, its `handle` its `ReceiptHandle`,
`receive_count` its `ApproximateReceiveCount` and `sent_at` its
`SentTimestamp`. Its attributes are its String and Number message
attributes as text; a Binary one is left out.

Every call goes through `Plugin.Provisional.Outbound` as the trigger's
proxy user, its `Authorization` redacted, as a step's does. The trigger's
`record_source_calls` says which the proxy records; `empty_receive?/2`
tells it a receive that brought nothing.

---

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