MessageStore.Message (message_store v3.1.0) View Source
A module for build, copy and folow message data.
Link to this section Summary
Functions
Create event data struct from message map.
The copy function constructs a message from another message's data.
Constructing a message from a preceding message.
Link to this section Types
Specs
event_message() :: EventStore.EventData.t()
Specs
key() :: Map.key()
Specs
Specs
Specs
path() :: [key(), ...]
Specs
recorded_message() :: EventStore.RecordedEvent.t()
Specs
stream_name() :: String.t()
Specs
uuid() :: String.t()
Specs
version() :: EventStore.expected_version()
Link to this section Functions
Specs
build(message()) :: event_message()
Create event data struct from message map.
Examples
iex> message = %{type: "Foo", data: %{foo: 1}, metadata: %{bar: 2}}
iex> Message.build(message)
%EventStore.EventData{
event_id: nil,
event_type: "Foo",
data: %{foo: 1},
metadata: %{bar: 2},
causation_id: nil,
correlation_id: nil
}
Specs
copy(message_type(), recorded_message(), [path() | key()]) :: event_message()
The copy function constructs a message from another message's data.
Examples
iex> recorded_message = %EventStore.RecordedEvent{
...> causation_id: nil,
...> correlation_id: "abcd1234",
...> created_at: ~U[2021-07-15 12:15:07.379908Z],
...> data: %{foo: "bazinga"},
...> event_id: "b9fcdccd-a495-4df3-889a-4b38f35a2618",
...> event_number: 935,
...> event_type: "Test",
...> metadata: %{bar: "baz", moo: 1},
...> stream_uuid: "test-123",
...> stream_version: 935
...> }
iex> Message.copy("Foo", recorded_message, [:data, [:metadata, :bar]])
%EventStore.EventData{
event_id: nil,
event_type: "Foo",
data: %{foo: "bazinga"},
metadata: %{bar: "baz"},
causation_id: nil,
correlation_id: nil
}
Warning
Copying the metadata should be used with extreme caution, and has no practical use in everyday applicative logic. Except for certain testing and infrastructural scenarios, copying the identifying metadata from one message to another can result in significant malfunctions if the copied message is then written to a stream and processed.
Specs
follow(message_type(), recorded_message(), [path() | key()]) :: event_message()
Constructing a message from a preceding message.
Following a message has almost identical behavior to a message copy/3
method.
The follow message leverages the implementation of copy/3
to fulfill its purpose.
Message Workflows
Messages frequently represent subsequent steps or stages in a process. Subsequent messages follow after preceding messages. Selected data or metadata from the preceding message is copied to the subsequent messages.
Examples
iex> recorded_message = %EventStore.RecordedEvent{
...> causation_id: nil,
...> correlation_id: "abcd1234",
...> created_at: ~U[2021-07-15 12:15:07.379908Z],
...> data: %{foo: "bazinga"},
...> event_id: "b9fcdccd-a495-4df3-889a-4b38f35a2618",
...> event_number: 935,
...> event_type: "Test",
...> metadata: %{bar: "baz", moo: 1},
...> stream_uuid: "test-123",
...> stream_version: 935
...> }
iex> Message.follow("Foo", recorded_message, [:data, [:metadata, :bar]])
%EventStore.EventData{
event_id: nil,
event_type: "Foo",
data: %{foo: "bazinga"},
metadata: %{bar: "baz"},
causation_id: "b9fcdccd-a495-4df3-889a-4b38f35a2618",
correlation_id: "abcd1234"
}
Specs
write(message_store, stream_name, message_or_messages, version \\ :any_version)
View SourceSpecs
write(module(), stream_name(), event_message() | [event_message()], version()) :: Result.t(any(), any())