herald v0.1.0-beta.3 Herald.Message
Defines a Message.
Message is a struct 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
Any received Message 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. Should be equals the payload defined bypayload/3
;valid?
- Indicates if message is valid, eg, with all fields have correct type, and if required fields are present.
For understand how Herald defines which Message
uses to represents a received message,
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