MessageData Writer

The message data writer is the more primitive writer of the two levels of writer, with the messaging writer being the upper level.

Using the message data writer is uncommon for typical applications. It can be useful when eliminating the message-to-message-data transformation when utmost performance optimization is required, and it can be useful as well in certain testing scenarios.

The message data writer writes message data to the message store. In the most common scenario, the message data are converted from rich message objects.

Example

message_data = MessageStore::MessageData::Write.new

message_data.data = {
  some_attribute: 'some value'
  some_other_attribute: 'some other value'
}

stream_name = "account-123"

MessageStore::Write.(message_data, stream_name)

MessageData Writer Facts

  • The message data writer can write one message or a batch of messages
  • A write is always made to a single stream
  • A writer can protect writes against concurrency using its expected_version argument
  • Actuating a writer can be done either from its class interface or its instance interface

MessageStore::Postgres::Write Class

The Write class is a concrete class from the MessageStore::Postgres library and namespace.

The MessageStore::Postgres::Write class provides:

  • Actuator methods for both the class and instance interface that write message data to the specified stream

Writing a MessageData

call(message_data, stream_name, expected_version: nil)

Returns

Position of the message_data written.

Alias

write

Parameters

NameDescriptionType
messageThe message to be writtenMessaging::Message or Array
stream_nameThe stream name to write the message toString
expected_versionExpected version of the stream at the time of the writeInteger

The writer is a callable object. It's actuated using the .() convention.

write.(some_message, some_stream)

Conversely, the writer can be actuated by directly invoking the call method. It can also be actuated via the write alias, although this option is rarely exercised in practice.

Note: Streams only come into existence when messages are written to them. There's no need to create a stream before using it. A stream is created implicitly by an event having been written to it.

Log Tags

The following tags are applied to log messages recorded by a message data writer:

TagDescription
writeApplied to all log messages recorded by a message data writer
message_storeApplied to all log messages recorded inside the MessageStore namespace

The following tags may be applied to log messages recorded by a message data writer:

TagDescription
message_dataApplied to log messages that record the writing of a MessageData instance
dataApplied to log messages that record the data content of a MessageData instance

See the logging user guide for more on log tags.


Related