defmodule Runbox.Message do
@moduledoc group: :messages
@moduledoc """
Altworx message runtime representation.
"""
alias __MODULE__, as: Message
@derive Jason.Encoder
defstruct [:from, :type, :timestamp, :body, :origin]
@type from :: atom | String.t()
@type type :: atom | String.t()
@type timestamp :: integer
@type body :: term
@type origin :: %{offset: non_neg_integer, topic: String.t(), partition: non_neg_integer} | nil
@type t :: %Message{
from: from,
type: type,
timestamp: timestamp,
body: body,
origin: origin
}
@spec new(from, type, timestamp, body) :: t
def new(from, type, timestamp, body) do
%Message{from: from, type: type, timestamp: timestamp, body: body}
end
@spec from(t) :: from
def from(%Message{from: from}), do: from
@spec type(t) :: type
def type(%Message{type: type}), do: type
@spec timestamp(t) :: timestamp
def timestamp(%Message{timestamp: ts}) when is_integer(ts), do: ts
@spec body(t) :: body
def body(%Message{body: body}), do: body
end