X3m System v0.4.7 X3m.System.Message View Source

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 process Logger.metadata should be set to this value.
  • invoked_at - utc time when message was generated.
  • dry_run - specifies dry run option. It can be either false, true or :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. params from 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 to true it means that raw_request was successfully validated and structered request is set to request field
  • reply_to - Pid of process that is waiting for response.
  • halted? - when set to true it means that response should be returned to the invoker without further processing of Message.

Link to this section 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

Puts value under key in message.raw_request map.

Returns sys_msg with provided response and as halted? = true.

Link to this section Types

Link to this type

dry_run()

View Source
dry_run() :: boolean() | :verbose
Link to this type

errors()

View Source
errors() :: [{atom(), error()}]
Link to this type

t()

View Source
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(),
  raw_request: map(),
  reply_to: pid(),
  request: nil | request(),
  response: nil | X3m.System.Response.t(),
  service_name: atom(),
  valid?: boolean()
}

Link to this section Functions

Link to this function

add_event(message, event)

View Source
add_event(message :: t(), event :: nil | any()) :: t()

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.

Link to this function

gen_msg_id()

View Source
gen_msg_id() :: String.t()
Link to this function

new(service_name, opts \\ [])

View Source

Creates new message with given service_name and provided opts:

  • id - id of the message. If not provided it tries to find request_id in Logger.metadata. If that one is also missing it generates random one.
  • correlation_id - id of "conversation". If not provided it is set to id.
  • causation_id - id of message that "caused" this message. If not provided it is set to id.
  • reply_to - sets pid of process that expects response. If not provided it is set to self().
  • raw_request - sets raw request as it is received (i.e. params from controller action).
  • logger_metadata - if not provided Logger.metadata is used by default.
Link to this function

prepare_aggregate_id(message, id_field, opts \\ [])

View Source
Link to this function

put_in_raw_request(message, key, value)

View Source

Puts value under key in message.raw_request map.

Link to this function

put_request(request, message)

View Source

Returns sys_msg with provided response and as halted? = true.

Link to this function

to_service(sys_msg, service_name)

View Source
to_service(t(), atom()) :: t()