herald v0.1.0 Herald.Message
Defines the behaviour to Message Schemas.
Message Schemas are the structs which represents data exchanged using a Broker queue.
Any message which you expect receive or send
in your application must be represented by a module,
and this module must use/2
Herald.Message
and defines a payload/1
for the represented
message, as bellow:
defmodule MyApp.UserRegistered do
use Herald.Message
payload do
field :age, :integer
field :name, :string, required: true
end
end
Each message received in the broker is converted in a struct with the following fields:
id
- A unique UUID for message. Can be used to filter duplicated messages;queue
- The queue where this message is received of will be sent;payload
- Content of message, represented by a map of atom keys, and defined bypayload/3
call in module definition;valid?
- Indicates if message is valid, eg, with all fields have correct type, and if required fields are present.
The definition of which Message Schema will be
used to represents a message received from broker
must be created in Router. More details,
see Herald.Router
.
Link to this section Summary
Link to this section Functions
Defines a field of payload.
Fields receives a name
, type
, and
can have aditional options.
Options
required
- Aboolean
indicating if field is required to be present or not.
Defines the valid payload for a
message, i.e. wrap all field/3
calls