Payload and Messages
In Evento Framework, Messages and Payloads are the workhorses of communication within your event-driven architecture. They work together to ensure data flows effectively between components:
Messages:
Imagine envelopes carrying instructions and relevant data. Messages in Evento act similarly. They encapsulate the following:
Payload: The core data carrier, holding information specific to the message type (Event, Command, View, or Query).
Message Type: An indicator specifying the type of message (e.g., "OrderCreatedEvent", "UpdateCustomerCommand").
(Optional) Routing Details: Additional information used for routing the message to the appropriate handler within the receiving component.
Here's an analogy:
Think of a restaurant order. The order itself (Message) specifies what's being requested (message type). The specific dishes (payload) detail the order contents. Routing details might include table number or a specific chef for a specialized dish.
Payloads:
These are the data carriers residing within messages. They represent the specific information associated with the message type:
Event Payloads: Carry data about events that have occurred within the system (e.g., "OrderCreatedEvent" payload might include details like order ID, items ordered, etc.).
Command Payloads: Encapsulate data required to perform actions (e.g., "UpdateCustomerCommand" payload might include new customer information).
View Payloads: Hold data requested by views to construct a specific representation (e.g., "CustomerDetailsView" payload might include customer name, address, etc.).
Query Payloads: Carry data retrieved in response to queries (e.g., "GetOrderByIdQuery" payload might include order details based on the provided ID).
Key Points:
Flexibility: Payloads can have different structures depending on the message type. They can range from simple data types to complex objects representing domain concepts.
Data-Centric: Payloads primarily focus on data representation. They don't contain any logic or functionality themselves. The receiving component interprets the data within the payload to perform the desired action or fulfill the request.
Serialization: Evento Framework might utilize serialization mechanisms (like converting payloads to a byte stream) for efficient storage or transmission within messages.
Understanding Messages and Payloads is Crucial:
By grasping how Messages and Payloads work together, you can effectively design and implement communication channels within your event-driven applications built with Evento Framework. Messages ensure structured communication, while Payloads carry the essential data that drives actions and information retrieval.
Message in Evento Framework
Methods:
Constructor:
public Message(T payload)
: This constructor takes a payload object (T
extendingPayload
) as an argument. It likely initializes theserializedPayload
object with the provided payload and sets the timestamp usingInstant.now().toEpochMilli()
.
Getters and Setters:
public T getPayload()
: Retrieves the actual payload object (T
) from theserializedPayload
object. This likely involves deserialization if the payload was stored in a serialized format.public void setPayload(T payload)
: Sets the payload of the message by updating theserializedPayload
object with the provided payload (T
). This might involve serialization for storage or transmission.public SerializedPayload<T> getSerializedPayload()
: Returns the internalSerializedPayload
object holding the serialized representation of the payload.public void setSerializedPayload(SerializedPayload<T> serializedPayload)
: Sets the internalSerializedPayload
object with the provided serialized payload information.
Type and Payload Name Retrieval:
public String getType()
: Utilizes theserializedPayload
object to determine the class name of the payload object (T
). This provides a string representation of the message type.public String getPayloadName()
: Extracts the name of the payload class from the full type string retrieved bygetType()
. This isolates the actual payload class name (useful for identifying the specific payload structure).
Timestamp:
public long getTimestamp()
: Returns the timestamp of the message, likely set during initialization usingInstant.now().toEpochMilli()
.public void setTimestamp(long timestamp)
: Allows setting a custom timestamp for the message, potentially for testing or specific use cases.
Metadata (Optional):
The provided code snippet doesn't explicitly show methods for accessing or manipulating metadata. However, the
Message
class might have getter and setter methods for aMetadata
object (not provided) to attach and retrieve additional information associated with the message.
Force Telemetry (Optional):
Purpose: By setting
forceTelemetry
totrue
, you explicitly instruct the Evento framework to collect and store telemetry data for this particular message, regardless of the system's default telemetry settings. This can be useful for troubleshooting critical events or monitoring performance of specific message types.Default Behavior: When
forceTelemetry
isfalse
(the default setting), telemetry collection adheres to the overall system configuration for the message type.
Key Points:
These methods provide access to the core elements of a message: payload, type information, timestamp, and potentially metadata.
Getters and setters allow for retrieving and modifying the message structure as needed.
Methods like
getType
andgetPayloadName
offer convenient ways to identify the type of message and the specific payload class it carries.
Understanding these methods is essential for effectively working with messages in Evento Framework. They allow you to construct messages with the appropriate payload, access the carried data, and potentially manage additional information through metadata.
Last updated