Producer
Reference for the Producer namespace in @streamsy/core. A producer position makes an append safe to retry.
import { Producer } from "@streamsy/core";A producer position names a writer and counts the appends that it has sent. When you send a position with an append, the server accepts that position once and answers Duplicate to any repeat, so a retry cannot write the items twice. For the retry flow, see Producer retries.
Producer.Position
type Position = {
readonly producerId: string;
readonly producerEpoch: number;
readonly producerSeq: number;
};
| Field | Meaning |
|---|---|
producerId | The name of the writer. The stream keeps the producer state for each producerId separately |
producerEpoch | The generation of the writer, which you choose. An append with an epoch lower than the last one for this producerId fails with StaleEpoch |
producerSeq | The number of the append in its epoch. Each new epoch starts at 0, and each append adds 1. A skipped number fails with ProducerGap |
The producer option of append takes this type. ProducerOptions is the same type under another name.
Producer.next
declare function next(position: Producer.Position): Producer.Position;
next returns a copy of position with producerSeq increased by one. It does not change producerId or producerEpoch.
Call next only after the append returns Appended or Duplicate. If you advance the position and the server never stored the earlier append, the next append fails with ProducerGap.
A writer that restarts must send the same items with the same position. If the writer cannot rebuild the items after a restart, store the items with their position before you append them. After the restart, send both again. A Duplicate result then tells you that the first append was written.
import { Producer } from "@streamsy/core";
const first: Producer.Position = { producerId: "importer", producerEpoch: 0, producerSeq: 0 };
const second = Producer.next(first);second is { producerId: "importer", producerEpoch: 0, producerSeq: 1 }.