Class DocumentMessageReader

java.lang.Object
io.fluxzero.sdk.persisting.search.DocumentMessageReader

public final class DocumentMessageReader extends Object
Retains the exact stored document source through serialization and handler interceptors.
  • Constructor Details

    • DocumentMessageReader

      public DocumentMessageReader()
  • Method Details

    • read

      public Stream<DeserializingMessage> read(List<io.fluxzero.common.api.SerializedMessage> messages, String topic, Serializer serializer)
      Reads one complete serializer batch, preserving per-document source metadata through upcasting.
    • retainSource

      public static DeserializingMessage retainSource(DeserializingMessage message, io.fluxzero.common.api.SerializedMessage source)
      Retains the original stored document bytes for metadata preservation after custom deserialization. Use this when a custom Serializer.deserializeMessages(Stream, MessageType, String) implementation constructs entirely new envelopes or DeserializingMessage instances. Normal input-envelope withData, withMetadata and withSegment transformations already retain the source when invoked through this reader.

      Keep the original input before any transformation and attach it to each corresponding decoded output:

      DocumentMessageReader.retainSource(decodedOutput, originalInput);
      
      Keep this association explicitly when buffering, reordering or splitting a batch; message IDs alone are insufficient because multiple versions can share an ID. This method does not require changing the batch boundary. Later DeserializingMessage.withPayload(Object) replacements retain the attached context.

      The source must contain the exact stored version's original Data.DOCUMENT_FORMAT data. Tracking envelope metadata and the upcast/replacement payload are not substitutes for those bytes. Metadata is read lazily only when needed; there is no storage fetch or lookup of a newer version. Arbitrary custom formats are not decoded by this helper.

      This attaches metadata provenance only: it does not copy the source message's ID, timestamps, revision or transport metadata into the output. A custom serializer remains responsible for preserving those ordinary message-envelope contracts.

      Parameters:
      message - the corresponding custom-decoded output
      source - the unchanged original input document envelope
      Returns:
      the supplied output with its source attached to the handling context
      See Also:
    • sourceMetadata

      public static io.fluxzero.common.api.Metadata sourceMetadata(DeserializingMessage message)
      Returns metadata embedded in the handled document version, excluding the tracking envelope's time fields. Decoding is deferred until a replacement is actually needed. Non-document inputs have no stored metadata.