# `EctoPGMQ.Message`
[🔗](https://github.com/gdwoolbert3/ecto_pgmq/blob/main/lib/ecto_pgmq/message.ex#L1)

Schema for PGMQ messages.

# `group`

```elixir
@type group() :: String.t()
```

A PGMQ message group.

For more information about FIFO message groups, see
[FIFO Message Groups](`m:EctoPGMQ#fifo-message-groups`).

# `headers`

```elixir
@type headers() :: %{optional(String.Chars.t()) =&gt; term()}
```

PGMQ message headers.

# `id`

```elixir
@type id() :: pos_integer()
```

A PGMQ message ID.

# `payload`

```elixir
@type payload() :: %{optional(String.Chars.t()) =&gt; term()}
```

A PGMQ message payload.

# `specification`

```elixir
@type specification() ::
  payload()
  | {payload(), group() | nil}
  | {payload(), group() | nil, headers() | nil}
```

A PGMQ message specification.

> #### Warning {: .warning}
>
> If the group is not `nil`, it will override any group that may already be
> specified in the headers.

# `t`

```elixir
@type t() :: %EctoPGMQ.Message{
  archived_at: DateTime.t() | nil,
  enqueued_at: DateTime.t(),
  group: group() | nil,
  headers: headers() | nil,
  id: id(),
  last_read_at: DateTime.t() | nil,
  payload: payload(),
  reads: non_neg_integer(),
  visible_at: DateTime.t()
}
```

A PGMQ message.

# `archive_query`

```elixir
@spec archive_query(EctoPGMQ.Queue.name()) :: Ecto.Query.t()
```

Returns a query for the messages in the archive for the given queue.

## Examples

    iex> message_ids = EctoPGMQ.send_messages(Repo, "my_queue", [%{"foo" => 1}, %{"bar" => 2}])
    iex> EctoPGMQ.archive_messages(Repo, "my_queue", message_ids)
    iex> messages = Repo.all(archive_query("my_queue"))
    iex> Enum.all?(messages, &is_struct(&1, EctoPGMQ.Message))
    true

# `queue_query`

```elixir
@spec queue_query(
  EctoPGMQ.Queue.name(),
  keyword()
) :: Ecto.Query.t()
```

Returns a query for the messages in the given queue.

## Options

  * `:archived_at?` - An optional `t:boolean/0` denoting whether or not to
    select a `NULL` `:archived_at` column. This can be used to make the query
    structure match that of `archive_query/1`. Defaults to `false`.

## Examples

    iex> EctoPGMQ.send_messages(Repo, "my_queue", [%{"foo" => 1}, %{"bar" => 2}])
    iex> messages = Repo.all(queue_query("my_queue"))
    iex> Enum.all?(messages, &is_struct(&1, EctoPGMQ.Message))
    true

---

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