Class SerializedMessage

java.lang.Object
io.fluxcapacitor.common.api.SerializedMessage
All Implemented Interfaces:
HasMetadata, SerializedObject<byte[]>

public class SerializedMessage extends Object implements SerializedObject<byte[]>, HasMetadata
Represents a fully serialized message for transmission or storage within the Flux platform.

A SerializedMessage wraps the binary Data of a message payload, along with associated Metadata and optional routing and tracking information such as index, segment, and requestId.

This class is the wire format and persistence format for messages. It implements SerializedObject to expose type and revision metadata, and HasMetadata to allow downstream access to structured metadata.

Key Features

  • Encapsulates payload as serialized byte[] via Data
  • Immutable-style updates via @With for metadata, segment, etc.
  • Tracks message origin and target via source and target
  • Supports custom revision control via originalRevision, set before upcasting

Tracking Fields

  • segment – the segment of the message log this message belongs to (used for partitioning)
  • index – the index of this message in the log, used for ordering and deduplication
  • requestId – identifier that ties a response to its originating request

Typical Use

Serialized messages are produced by serializing a Message using a Serializer, and are then stored, indexed, transmitted, or routed based on metadata and log location.
See Also:
  • Constructor Details

    • SerializedMessage

      public SerializedMessage(Data<byte[]> data, Metadata metadata, String messageId, Long timestamp)
  • Method Details

    • getOriginalRevision

      public int getOriginalRevision()
      Returns the original revision of the payload object.

      If originalRevision was explicitly set before upcasting, it is returned. Otherwise, the revision is delegated to SerializedObject.getRevision().

      Returns:
      the original revision of the serialized payload
    • data

      public Data<byte[]> data()
      Description copied from interface: SerializedObject
      Returns the serialized payload held by this object.
      Specified by:
      data in interface SerializedObject<byte[]>
      Returns:
      the serialized payload
    • withData

      public SerializedMessage withData(@NonNull @NonNull Data<byte[]> data)
      Description copied from interface: SerializedObject
      Returns a new SerializedObject with the given data object. If the given data is the same instance as the current one, this may be returned.
      Specified by:
      withData in interface SerializedObject<byte[]>
      Parameters:
      data - the new serialized payload
      Returns:
      a new SerializedObject instance. May be this if unchanged
    • getRevision

      public int getRevision()
      Description copied from interface: SerializedObject
      Returns the revision of the serialized object.
      Specified by:
      getRevision in interface SerializedObject<byte[]>
    • getType

      public String getType()
      Description copied from interface: SerializedObject
      Returns the type identifier for the serialized payload.
      Specified by:
      getType in interface SerializedObject<byte[]>
    • getBytes

      public long getBytes()
      Returns the length of bytes in the serialized payload. If the amount cannot be determined, 0 is returned.