System Message.
This module defines a X3m.System.Message struct and the main functions
for working with it.
Fields:
service_name- the name of the service that should handle this message. Example::create_job.id- unique id of the message.correlation_id- id of the message that "started" conversation.causation_id- id of the message that "caused" this message.logger_metadata- In each new processLogger.metadatashould be set to this value.invoked_at- utc time when message was generated.dry_run- specifies dry run option. It can be eitherfalse,trueor:verbose.request- request structure converted to Ecto.Changeset (or anything else useful).raw_request- request as it is received before converting to Message (i.e.paramsfrom controller action).assigns- shared Data as a map.response- the response for invoker.events- list of generated events.aggregate_meta- metadata for aggregate.valid?- when set totrueit means that raw_request was successfully validated and structered request is set torequestfieldorigin_node- Node.self() of invokerreply_to- Pid of process that is waiting for response.halted?- when set totrueit means that response should be returned to the invoker without further processing of Message.
Summary
Functions
Adds event in message.events list. If event is nil
it behaves as noop.
Assigns a value to a key in the message. The "assigns" storage is meant to be used to store values in the message so that others in pipeline can use them when needed. The assigns storage is a map.
Returns message it received with Response.created(id) result set.
Creates new message with given service_name and provided opts
Creates new message with given service_name that is caused by other msg.
Puts value under key in message.raw_request map.
Returns sys_msg with provided response and as halted? = true.
Types
@type dry_run() :: boolean() | :verbose
@type t() :: %X3m.System.Message{ aggregate_meta: map(), assigns: assigns(), causation_id: String.t(), correlation_id: String.t(), dry_run: dry_run(), events: [map()], halted?: boolean(), id: String.t(), invoked_at: DateTime.t(), logger_metadata: Keyword.t(), origin_node: Node.t(), raw_request: map(), reply_to: pid(), request: nil | request(), response: nil | X3m.System.Response.t(), service_name: atom(), valid?: boolean() }
Functions
Adds event in message.events list. If event is nil
it behaves as noop.
After return/2 (and friends) order of msg.events will be the same as
they've been added.
Assigns a value to a key in the message. The "assigns" storage is meant to be used to store values in the message so that others in pipeline can use them when needed. The assigns storage is a map.
Examples
iex> sys_msg.assigns[:user_id]
nil
iex> sys_msg = assign(sys_msg, :user_id, 123)
iex> sys_msg.assigns[:user_id]
123
Returns message it received with Response.created(id) result set.
@spec gen_msg_id() :: String.t()
Creates new message with given service_name and provided opts:
id- id of the message. If not provided it generates random one.correlation_id- id of "conversation". If not provided it is set toid.causation_id- id of message that "caused" this message. If not provided it is set toid.reply_to- sets pid of process that expects response. If not provided it is set toself().raw_request- sets raw request as it is received (i.e.paramsfrom controller action).logger_metadata- if not providedLogger.metadatais used by default.
Creates new message with given service_name that is caused by other msg.
Puts value under key in message.raw_request map.
@spec return(t(), X3m.System.Response.t()) :: t()
Returns sys_msg with provided response and as halted? = true.