# `Alternera.Plugins.AnypointMq.Broker`
[🔗](https://github.com/10e-ab/alternera-anypoint-mq/blob/v0.9.0/lib/alternera/plugins/anypoint_mq/broker.ex#L1)

The calls an Anypoint MQ step makes to the broker's REST API, for
`Alternera.Plugins.AnypointMq`. Every path is under
`<broker_url>/organizations/<org>/environments/<env>/destinations/<destination>`:

  * publish: `PUT …/messages/<message id>`, a JSON body of `headers`
    (`messageId`, `messageGroupId`, `deliveryDelay`), `properties` and
    `body`, answered `201`;
  * consume: `GET …/messages?pollingTime=…&batchSize=…&lockTtl=…`,
    answered `200` with a JSON array of messages or `204` with none; with
    immediate acks, `DELETE …/messages` with `[{messageId, lockId}]`;
  * ack: `DELETE …/messages/<message id>` with `{"lockId": …}`;
  * nack: `DELETE …/messages/<message id>/locks/<lock id>`.

An ack's or nack's answer carries `status`, `"successful"` or
`"failure"`.

Each call goes out through `Plugin.Provisional.Outbound` as the step's
proxy user, with the `Authorization` the tenant's auth profile for its
URL gives (`Plugin.Provisional.Credentials.for_call/3`), its recording
redacted; a `401` drops that token and calls once more with a new one.
The calls end `call_reserve_ms/1` before the step's own time, so a slow
broker fails the step `timeout` with its call recorded rather than the
runner stopping it.

# `call_reserve_ms`

```elixir
@spec call_reserve_ms(non_neg_integer()) :: non_neg_integer()
```

How long before the step's time is up its calls must be done.

# `check_url`

```elixir
@spec check_url(String.t()) :: {:ok, String.t()} | {:error, String.t()}
```

`url` as a broker URL (`Wire.check_url/1`).

# `fingerprint`

```elixir
@spec fingerprint(map(), map()) :: String.t()
```

The fingerprint of a resolved call: the operation, method, URL (a
publish's generated id and a consume's polling time, which change from
run to run, left out), body and proxy user, so a dry run and the real
run of the same call agree.

# `run`

```elixir
@spec run(Alternera.Plugin.Inputs.t(), map(), map()) :: tuple()
```

Runs the step's operation: `call/3`'s result.

# `would_call`

```elixir
@spec would_call(Alternera.Plugin.Inputs.t(), map(), map()) :: map()
```

What a preview says the step would do: the call, as whom and its
fingerprint, with nothing sent. A setting that does not resolve is named
in place of the call.

---

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