An Anypoint MQ 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 name the queue: broker_url, organization_id,
environment_id and destination. A source stands in no pipeline, so no
Configuration step fills them: each is set here, and a tenant variable
({{NAME}}) fills one when the source opens. The broker's token is the
tenant's auth profile for the broker's host, as for the step
(Wire.token/3): an OAuth2 client credentials profile whose token URL is
the broker's /authorize. How long a poll waits, how long a message
stays locked and how many come at once are the runner's, not settings.
The calls, under
<broker_url>/organizations/<org>/environments/<env>/destinations/<destination>:
- receive:
GET …/messageswithbatchSizethe runner's free slots (at most 10),pollingTimethe runner's wait (at most 20 000 ms) andlockTtlthe hold (at most 43 200 000 ms,max_hold_ms, since the runner's retry delays are counted within it);204, or an empty answer, is none; the call may take the wait and 5 000 ms more, and reads up toWire.receive_cap/0of the answer, room for one of the broker's largest messages; a larger answer isresponse_too_large, on which the runner asks for fewer; - settle, ten entries a call: an ack is
DELETE …/messageswith[{messageId, lockId}];{:retry, delay}sets the lock's time to live to the delay,PATCH …/messages/lockswith[{messageId, lockId, ttl}], so the lock lapses and the broker delivers the message again then;{:retry, 0}and:rejectrelease the lock,DELETE …/messages/locks, so it comes back at once. The proxy's runner settles a reject as a retry with a delay (Verdict.settle_as/4), and the queue's dead-letter queue moves the message on after its delivery limit.
The broker's API documents the lock's ttl in seconds, at most 12 hours,
while a receive's lockTtl is in milliseconds; the delay is sent in
whole seconds, rounded up, at least 1 and at most 43 200. That has been
read from the API's description, not tried against a broker.
A batch answered with each entry's status settles each by its own
(matched by message and lock), one the answer leaves out by the 2xx
unless the answer names a failure; the
ack and nack batches are documented to answer one status for all, which
then settles every entry alike. A 401 drops the token and calls once
more with a new one.
A message's id is its messageId, its handle %{"message_id", "lock_id"}, receive_count its deliveryCount and sent_at its
created (an HTTP date or epoch milliseconds). Its attributes are its
properties, each value as text.
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.
Summary
Functions
A message's created header as a time: an HTTP date (Sat, 1 Jan 2022 02:08:22 GMT) or epoch milliseconds; nil for anything else.
Functions
@spec sent_at(term()) :: DateTime.t() | nil
A message's created header as a time: an HTTP date (Sat, 1 Jan 2022 02:08:22 GMT) or epoch milliseconds; nil for anything else.