Skip to main content

Path

The way of one message through a RustStream service, on a stream file and on a pipe: the reader, the channel, the handler, the reply and the write.

The path of one message that is answered, on a stream file and on a pipeStream filePipeClient consumerreads the fileDriver taskstamps the generationChannel of 64FileSubscriberdrops old generationsBatchingunder batch(n)FileContext,then decodeHandler#[subscriber] fnFilePublisherenvelope if headersAppend, flushinto the filestdin threadparses the lineReader taskof the subscriptionChannel of 64StdioSubscriberone message per pollBatchingunder batch(n)DecodeHandler#[subscriber] fnStdioPublisherenvelope if neededstdout threadwrites the line
The diagram as text
  1. Stream file: Client consumer reads the file; Driver task stamps the generation; Channel of 64; FileSubscriber drops old generations; Batching under batch(n); FileContext, then decode; Handler #[subscriber] fn; FilePublisher envelope if headers; Append, flush into the file
  2. Pipe: stdin thread parses the line; Reader task of the subscription; Channel of 64; StdioSubscriber one message per poll; Batching under batch(n); Decode; Handler #[subscriber] fn; StdioPublisher envelope if needed; stdout thread writes the line
  3. Client consumer reads the file → Driver task stamps the generation
  4. Driver task stamps the generation → Channel of 64
  5. Channel of 64 → FileSubscriber drops old generations
  6. FileSubscriber drops old generations → Batching under batch(n)
  7. Batching under batch(n) → FileContext, then decode
  8. FileContext, then decode → Handler #[subscriber] fn
  9. Handler #[subscriber] fn → FilePublisher envelope if headers
  10. FilePublisher envelope if headers → Append, flush into the file
  11. stdin thread parses the line → Reader task of the subscription
  12. Reader task of the subscription → Channel of 64
  13. Channel of 64 → StdioSubscriber one message per poll
  14. StdioSubscriber one message per poll → Batching under batch(n)
  15. Batching under batch(n) → Decode
  16. Decode → Handler #[subscriber] fn
  17. Handler #[subscriber] fn → StdioPublisher envelope if needed
  18. StdioPublisher envelope if needed → stdout thread writes the line

The subscription's task reads ahead of the handler. It takes each message off the client, opens the envelope and copies the payload into a buffer of its own. It adds the message's number in the stream-sequence header, then queues the delivery on a channel of up to 64. The handler reads from that channel, so the next message is out of the file while the current one is handled.

On a file, every delivery carries the generation the reader was in when it read it. A seek opens a new generation, and the subscription drops what was queued under the old one. A delivery also holds a shared reference to the subscription's seeker, so building its context per message only counts references.

The handler's reply is encoded into a buffer the dispatch loop reuses. The publisher copies those bytes into the message it hands the client, and wraps them in the envelope only when the message has headers, or on a pipe when a line would change the payload. A file publish returns once the append is flushed to the file. A reply written to the file the subscription reads is passed over by its reader, because it sits under another stream key.

The delivery settles after the reply. On both transports an ack and a nack report that they are unsupported, as Settlement draws.