tree: d327343eebbe1e12f9c18ad7d4560e002a285396 [search]
  1. scripts/
  2. src/
  3. commitlint.config.js
  4. cucumber.json
  5. docker-compose.yml
  6. eslint.config.mjs
  7. LICENSE
  8. NOTICE
  9. package-lock.json
  10. package.json
  11. README.md
  12. tsconfig.json
foreign/node/README.md

Apache Iggy Node.js Client

Apache Iggy Node.js client written in typescript, it currently only supports tcp & tls transports.

Disclaimer: although all iggy commands & basic client/stream are implemented this is still a WIP, provided as is, and has still a long way to go to be considered “battle tested”.

note: This lib started as iggy-bin ( github / npm) before migrating under iggy-rs org. package iggy-bin@v1.3.4 is equivalent to @iggy.rs/sdk@v1.0.3 and migrating again under apache iggy monorepo ( github and is now published on npmjs as apache-iggy

note: previous works on node.js http client has been moved to iggy-node-http-client (moved on 04 July 2024)

install

npm i --save apache-iggy@edge

This SDK uses binary client protocol 0.12.3. Server 0.10.1-edge.2 accepts that protocol and requires fresh storage with marker IGGY-TIERED-SEGMENT-CHAIN-2. For a local server with the example credentials, follow the example setup.

basic usage

Response frame limit

Compatibility note: response frames larger than maxResponseFrameSize (default 64 MiB) are rejected and close the connection. Raise the limit in the client configuration when polling very large batches.

VSR framing

The SDK speaks the VSR wire protocol exclusively and requires an Iggy VSR server:

import { SimpleClient, getRawClient } from "apache-iggy";

const config = {
  transport: "TCP" as const,
  options: { host: "127.0.0.1", port: 8090 },
  credentials: { username: "iggy", password: "iggy" },
};
const client = new SimpleClient(getRawClient(config));
const stats = await client.system.getStats();

Codes absent from the SDK command table use Operation::NonReplicated and carry the command code in the request header's reserved field. The server remains authoritative for classifying or rejecting extension commands.

Sends always carry an explicit partition id. The client resolves Partitioning.Balanced round-robin and Partitioning.MessageKey as XXH32 (seed 0) of the key modulo the topic's partition count, as the Rust SDK does. The count is cached per topic. The client reads it again after a refused send, and after the client deletes a stream or a topic or creates or deletes partitions. A raw SendMessages command without an explicit partition id fails with error code 5 before the client sends it.

sendBinaryRequestToReplica(code, payload, replica) sends a raw command to one node of a cluster, named by the replica id that cluster metadata returns, and sendCommand takes the same id as the replica option.

Each node answers non-replicated commands such as GetStats from its own state, so this reads the state of that node. Replicated commands, polls, fetches, consumer-offset reads and session-control codes fail with error code 3 before anything is sent. An id that cluster metadata does not name fails with error code 6. An unreachable node is retried until the request deadline, and a NotPrimary (89) reply is returned rather than sent to another node.

Partition commands carry a context containing the partition incarnation, owner generation and metadata operation. Pass the context of an earlier poll reply to keep an offset write or continuation tied to that history. Otherwise the client captures the route context. A poll, offset write or offset read with a context that is all zero also captures the route context. If its context names incarnation 0, the client fills in the incarnation of the route once. It keeps the owner generation and metadata operation of that context. A route of incarnation 0 is not ready. The client looks up such a route again until the request deadline. Then the call fails with error code 58. A fetch keeps a zero context in its header. Each fetch target follows the same rules for its own partition, but a target carries no metadata operation. Non-admission retries and uncertain-operation replay preserve the first captured context, request identity and payload. Route refreshes change the destination. Lifecycle error 88 retries with a fresh ID and the same context. A send without caller-supplied context, or with one that is all zero, captures the route context and can refresh history once after error 87. Other explicit contexts return that error. A new call can capture newer metadata progress.

Route discovery uses command 105. Sends, polls and offset reads/writes use the partition primary. Other commands use the metadata primary. One logical client owns a shared session, a monotonic request counter and one multiplexed link per replica. Healthy links survive primary changes. Each link dials the address that its node advertises in the cluster roster. With a one-node roster, the link dials the configured endpoint instead. A single node behind a port mapping or a port-forward thus stays reachable. The legacy poolSize option accepts only one logical client. It does not limit replica links or concurrency. The public Client._pool property has been removed. Applications should use the client methods directly. The client owns its replica connections.

A backup replica can miss a stream, topic or partition that the metadata primary already created. When such a replica replies “not found” (error 1009, 1010, 2010, 2011 or 3007) to a route lookup or a partition command, the call looks up the route again and retries. If the deadline ends the call first, it fails with error 58. Only a “not found” reply from the metadata primary is final. A leader change can make the client's view of the metadata primary out of date. If the client believes that the replica that replied is the metadata primary, it reads the cluster roster from that replica. If the client has no link to the metadata primary, it also reads that roster. If that roster names this replica as the metadata primary, the reply is final.

VSR authentication translates password and personal-access-token login into the Register handshake. Replacement links bind the existing session. Confirmed session expiry requires a new Register. An uncertain mutation is never replayed under that new session. An eviction that ends the session does not prove the outcome of a mutation that the client already wrote. That call ends with OperationUncertainError. A stale client eviction drops only its link, because the server keeps the session. The client binds the same session on a new link, as after any lost link, so retained operations and group membership stay. Explicit relogin logs out the previous session first.

The client signs in by itself as the last sign-in of the caller, or with the configured credentials while the caller never signed in. After a logout, or after the server refuses those credentials, it does not sign in by itself, and a call fails with status 40 until the caller signs in again. A sign-in or logout of the caller ends each earlier call that has to wait for a new session: with status 40 if it sent nothing, or with OperationUncertainError if its outcome is unknown. A Next poll that commits nothing, which has no operation ID, ends with status 57 instead, and an auto-commit poll ends with FetchProgressUncertainError (see below). A typed send, a group poll and a whole-list read can send more than one command. If the caller signs in or logs out before the next command of such a call, the call fails with status 40. Only a call that waits for the client's own sign-in goes on under the new session. If the server refuses that sign-in, the call fails with status 40, and its cause holds the refusal. A call whose deadline ends while it waits for a session fails with status 58. So does a call that replicas refuse with 89 until its deadline.

A reply with status 30 (StaleClient) says that the server no longer attaches the link to the session. This happens, for example, after the user was deleted or deactivated. A 30 refusal before commit fails a first attempt with that error. After an earlier written attempt, it does not prove the outcome, so that call ends with OperationUncertainError. The client closes that link and binds the session on a new link, as after any lost link. A replica that replaced its client table refuses a live session the same way, so the bind decides. A live session stays, with its retained operations and group membership. An ended session refuses the bind, and the client signs in again.

A committed 30 comes from the replicated session table, so that session ended. It is a proved outcome, like any other committed rejection, and the client drops the session at once and signs in again.

Deferred polls

message.poll takes deferred options. With them, the client sends command 106, and the server waits for messages before it replies. Options that you do not give take the values of DEFAULT_DEFERRED_POLL_OPTIONS, which are the defaults of the Rust SDK. Durations are in milliseconds.

optiondefaultlimits
maxWait1000up to 600 s. When minCount messages are there, or when maxWait ends, the server replies
minCount1from 1 to the count of the poll
maxBytes1048576at least 344 bytes, the size of a reply with one message header
requestTimeout11000from 1 ms to 630 s. If maxWait is above 0, at least maxWait plus 1 s

An option outside its limits fails before anything is sent: minCount with error 4009, maxWait and requestTimeout with error 3, and maxBytes with error 80. The call gives up at requestTimeout, not at the 30 s operation budget. A link fails on a reply larger than maxResponseFrameSize, so the client lowers maxBytes to that size minus the 256-byte header.

A client parks at most 64 deferred polls and fetches at once. Another one waits for a free slot within its own deadline. If the server refuses one with 90, because the session parks too many requests, the client pauses and sends it again within the deadline.

The signal option takes an AbortSignal that cancels the call. If the request already waits on the server, the client sends command 108 on the same link. The server then drops the request without a reply. The client ignores a reply that comes later. A raw 106 gets the same routing, limits and cancellation as the typed calls. A raw 108 fails with error 3 before anything is sent.

A consumer-group poll with deferred options needs a partition. Without one, it fails with error 3 before anything is sent. A member reads all its partitions with message.reader.

An auto-commit or Next deferred poll holds the progress lane of its partition while it waits on the server, up to maxWait. Offset reads, stores and deletes of the same client on that partition wait behind it. Sends do not take the progress lane, so a parked poll does not delay them.

Polling one partition

message.poll with a strategy reads one batch of one partition with PollOptions. It waits on the server until minCount messages are ready, the reply reaches maxBytes, or maxWait ends, and returns what is ready, which can be nothing.

import { CommitPolicy, Consumer, PollingStrategy } from "apache-iggy";

const consumer = Consumer.Single;
const options = { count: 100, maxWait: 5_000 };
const polled = await client.message.poll({
  streamId, topicId, partitionId: 1, consumer, strategy: PollingStrategy.Next, options
});
for (const message of polled.messages) console.log(message.payload.toString());

const checkpoint = polled.checkpoint();
if (checkpoint) await client.offset.storePosition({ streamId, topicId, consumer, checkpoint });

const next = await client.message.poll({
  streamId, topicId, partitionId: 1, consumer, strategy: polled.continuation(), options
});
optiondefaultlimits
count1000the most messages of one batch
maxWait0up to 600 s. Zero replies at once. The call gives up 10 s after maxWait
minCount1from 1 to count, else error 4009
maxBytes1048576at least 344 bytes, else error 80
commitCommitPolicy.Manualwho stores the offset, see below
  • CommitPolicy.Manual stores nothing. Store checkpoint(), or checkpointAt(index) for a part of the batch, with offset.storePosition, and remove it with offset.deletePosition. A checkpoint keeps the partition history that delivered it, so a store after the partition was deleted and created again fails with error 87.
  • CommitPolicy.OnRead makes the server store the offset of the last message of each read as part of the read, in one round trip. While the primary stays up a message is delivered at most once. A failover before the store replicates can deliver the last batch again. A one-shot poll refuses CommitPolicy.Auto() with error 2 (InvalidConfiguration), since it has nothing to count.
  • continuation() continues the partition after the batch, under its context. An empty batch keeps the start of its read, so Next stays Next. A poll of another partition refuses the continuation with error 3.
  • A first message larger than maxBytes comes alone in its read.
  • If you abort a waiting poll, the client cancels it on the server. A poll that stores nothing rejects with the abort reason. A poll that commits keeps its reply: the server answers it once, refused when the cancel won and nothing was stored, so the call rejects with the abort reason, or with the messages that it stored before the cancel came, which the call returns.

Partition reader

message.reader opens a PartitionReader, which reads many partitions in batches and keeps the position of each. It reads the partitions of one primary in one request, finds a moved primary by itself and gives each partition its turn. A partition whose last read ended before the end of the partition is read in a fetch of its own while the read ahead has room for another full read, so a backlog of many partitions is read as fast as one poll of each partition would read it. At most 32 reads of one reader run at once, fetches and polls alike. The fetches of each primary go first, and the polls of single partitions leave a request for each primary. Under CommitPolicy.OnRead the reader starts those fetches only while next() waits, and each partition is in one committing read at a time.

import { Consumer, ReadError } from "apache-iggy";

const reader = await client.message.reader({
  streamId, topicId, consumer: Consumer.Single, partitions: [1, 2, 3], options: { maxWait: 5_000 }
});
try {
  while (true) {
    try {
      const batch = await reader.next();
      process(batch);
      await reader.commit(batch.checkpoint()!);
    } catch (error) {
      // A message that does not decode. The reader reads it again until a seek passes it.
      if (error instanceof ReadError && error.skip) await reader.seek(error.partitionId!, error.skip);
      else if (!(error instanceof ReadError)) throw error;
    }
  }
} finally {
  await reader.close();
}
  • A consumer group reads the assignment of its member: { consumer: Consumer.Group('g') } without partitions joins the group, follows rebalances and leaves the group in close(). The reader releases a join with an unknown outcome in the client at once and joins again after the retry interval. close() releases a leave with an unknown outcome the same way. So neither blocks a later metadata write of the client. When the join of open() has an unknown outcome, open() releases it in the client and fails with it, so a later open() can join. A join that landed anyway keeps its member in the group until the session ends.
  • next() returns one batch of one partition, never empty. A ReadError names the partition of an error, or none for an error of the whole reader, and the reader retries by itself. Error 87 stops a partition until seek when its position is tied to the history of an earlier read, and so do error 80, error 96 (the object store refuses a read of tiered data for good, so the reader never sends it again) and a refusal other than 5009 that six retries did not change. A context that is all zero ties a position to no history. The error of each stop sets stopsPartition, and that of an 87 or a refusal stop also sets resumable: a seek to Next reads the partition again after its stored offset. When close() starts, a next() that waits fails at once because the reader is closed.
  • For a message that does not decode, ReadError carries skip, offset and record, the record as the reply carried it: its 48-byte frame header, payload and user headers, so the message can be kept or inspected. When the framing of the reply is malformed, offset is undefined and record holds the remaining reply bytes from where decoding stopped.
  • With CommitPolicy.Manual, commit stores a checkpoint. When its store has an unknown outcome, commit fails. The reader releases that request in the client, so a retry of commit can store. With CommitPolicy.OnRead the server stores the offset of each read, the reader reads only while next() waits, and close() moves the offset back to the last batch that the application took. When the application took none, close() moves the offset before the first batch that the reader held. At offset 0, if the server holds an offset, close() deletes it. When a store or delete of close() has an unknown outcome, close() fails. It first releases that request in the client, so the request does not block a later reader. A read whose reply was lost is repaired: the next read finds what it stored, and the reader reads those messages again by offset without a commit. If the partition no longer holds a part of that range, for example after retention, next() fails once with error 14010. Its ReadError names that part, also as lost, the first and last offset, and the reader reads on after it. Only a lost read makes the reader read skipped offsets again: when the stored offset moved ahead because the application or another session stored it, the reader delivers from there. A batch that the server stored is handed over even when its partition left the assignment of the member. If a lost read of that partition stored a range that the reader did not read again, next() first fails with error 14010. Its ReadError names that range, also as lost. close() does not move the offset of a partition that left, so the group loses its batches that next() did not return. A seek first waits for each committing read of its partition in flight, also one from before a new assignment. A seek to an offset above 0 then stores the offset before it, so a restart resumes at the sought offset. If the server holds an offset, a seek to offset 0 or First deletes it instead, because the commit of a read never moves an offset back. A seek to a timestamp first reads the first message at that time without a commit. Then it seeks to the offset of that message. No read of the partition starts until the seek ends. A second seek of the partition and close() wait for it. A refused read, store, lookup or delete fails the seek and moves nothing: the partition keeps its queued batches and reads on from where it was. A store or delete whose outcome is unknown fails the seek too. The reader then handles it as a lost read: it reads skipped messages again, and close() moves the offset back. Before its write, a seek from a position without an offset looks up the stored offset. A Next start before the first read, a timestamp and Last are such positions. So is a start that applies because the server held no offset. A seek of a partition that delivered no message looks it up too. After a write with an unknown outcome, a Next position reads on from that offset. Until a later read returns messages, close() restores that offset, or deletes the stored offset when the server held none. If an earlier read stored messages that nobody took, close() moves the offset back before that read instead. Every other seek stores and deletes nothing. A seek after close() fails.
  • start sets where a partition without a position starts, Next by default. With CommitPolicy.OnRead it applies only to a partition without a stored offset. A partition with one resumes after it, also after a new assignment. A Last start reads the last count messages. With CommitPolicy.OnRead, a read that stores nothing first finds the offset of a timestamp or Last position. Then close() can move the offset back before it.
  • A refusal 5009 is not a leave. After a 5009 on a read of a group partition, the partition keeps its position, its queued batches and what close() needs to move its offset back. It reads again without an owner, and the reader asks for a refresh of the assignment. Only a leave that a refresh shows drops that state. So a 5009 never stops the partition. When the server serves the partition again, a catch-up after a lost read goes on. The wait before the next read starts at the retry interval and doubles after each 5009 in a row. Each sixth 5009 in a row gives one ReadError, and then the count and the wait start again. A read that succeeds, a seek or a session change also starts them again.
  • If an offset store or delete of a partition that is still assigned gets 5009, a read without a commit finds the installed owner. Then the write goes once more under that owner. A transient refusal of that read repeats it after the retry interval. If that read stops, the write fails with its refusal. The read for a write of close({ signal }) stops 10 s after the close starts. If signal of the first call aborts earlier, the read stops at that abort. Each later write of the close then goes once without that read, and the close still leaves the group. During an outage close() can take about one 30 s operation budget of the client for each partition with a pending store. A second close() call waits for the first one, and its signal does not stop the close. The read for commit(checkpoint, { signal }) stops after signal aborts or close() starts. The read for a seek or an automatic store stops after close() starts. After such a stop, a reply to that read does not send the write again. The reader logs a failed automatic store with the iggy:client debug logger.
  • With CommitPolicy.Auto({ interval, every, after }) the reader counts each batch when next() returns it (CommitAfter.Delivery), at the next next() or close() (CommitAfter.Processing), or on mark (CommitAfter.Marked), and stores the latest counted position at the interval, on the event (CommitEvery.Message, CommitEvery.Messages(n) or CommitEvery.Batch), and in close(). DEFAULT_AUTO_COMMIT stores every 10,000 messages or 5 s after processing. When a store has an unknown outcome, the reader releases it in the client. Then it does not block the next store of the partition. The reader stores again at the next interval, event or close().
  • Requested read-ahead budgets default to 16 MiB and 16,000 messages (prefetchBytes, prefetchMessages). Each effective budget holds at least 32 full batches, and larger configured budgets still apply. A budget that is NaN, infinite or negative is refused with error 3 before anything is sent. The byte budget counts message frame headers, payloads and encoded user headers. It is not a limit on retained memory: payload views keep whole reply buffers alive, including the uncounted 256-byte batch header per record. With one small message per record, retained buffers can occupy several times the byte budget. Decoded objects and in-flight reads also use memory outside this count. Without options a read waits up to 5 s. After a refused read, a lost read or a failed refresh it waits retryInterval, 1 s by default. While a refresh of the group assignment fails or gets no answer, the reader reads on under its last assignment. After a new session or a lost membership, it starts no read until a refresh confirmed the assignment. A retryInterval that is not a finite number above 0 is refused with error 3 too.
  • With CommitPolicy.OnRead the server stores the offset of each read before the application takes its batch. A crash, or a reader that stops without close(), loses the batches that the reader held: up to the effective budget, which holds at least 32 batches. CommitPolicy.Auto or CommitPolicy.Manual stores offsets after delivery instead.

Consumers

client.consumer and client.consumerGroup hand over one message at a time on a partition reader, as an async iterable, with a handler loop, or as a Readable.

import { CommitAfter, CommitPolicy } from "apache-iggy";

const consumer = await client.consumerGroup({
  name: 'orders', streamId, topicId,
  options: { commit: CommitPolicy.Auto({ after: CommitAfter.Processing }) },
  onError: (error) => console.warn(error)
});
await consumer.consume(async ({ message }) => handle(message));
await consumer.shutdown();
  • client.consumerGroup creates the group when it is missing and joins it. When that create has an unknown outcome, the call releases it in the client and fails with it. client.consumer reads the given partitions under the consumer name.
  • Under CommitAfter.Processing a message counts once the iterator is read again or its handler returns. A handler that throws ends consume with its error and leaves its message uncounted, and so does a shutdown while the handler runs. shutdown() counts the last message of the iterator, stores or moves back the offsets and leaves the group. A later shutdown() waits for the first and ends as it does. seek drops the rest of the batch of its partition.
  • commit(checkpoint, { signal }) and shutdown({ signal }) give signal to commit() and close() of the reader. If a store gets 5009, the read for the owner stops as for the reader: 10 s after the shutdown starts, or at an earlier abort of signal. Only the signal of the first shutdown() call can stop the shutdown.
  • A read error that the reader retries by itself goes to onError and the consumer goes on. A stop of a partition (stopsPartition) ends the iteration with its ReadError, and so does a message that does not decode, whose skip passes it with seek. A resumable stop reads again after a seek to Next. A stop while a committing read that lost its reply is still pending reports that read as 14010 instead, since a seek to Next would skip what it stored. A lost range (lost, error 14010) ends the iteration with its ReadError too. The reader reads on after that range, so a new iteration hands over the messages after it.
  • toReadable() takes the next message only when its own reader asks for it, and destroying it shuts the consumer down.

Mutation recovery and limits

Receipt access follows the server's session and revocation policy. An unresolved operation cannot recover its receipt after its original session ends, even after a new login or account reactivation. A fresh send can duplicate that operation.

Each node counts the messages in its stream, topic and system stats. After a successful send, a node that is not the partition primary shows the new count only after the next prepare or commit broadcast. When no other write follows, this delay is at most cluster.commit_busy_heartbeat_interval (500 ms by default). See metadata freshness and counters.

Mutations share one FIFO lane per partition history, with a separate metadata lane. Progress polls (Next or auto-commit), offset reads, stores and deletes share a separate progress lane per partition. Sends use only the mutation lane, so a parked poll does not delay a producer that shares the client. Offset stores and deletes hold both lanes. They take the progress lane first, so a send can pass a store that waits behind a parked poll.

An uncertain mutation remains retained and blocks later mutations in its lane. An uncertain offset store or delete also blocks the progress lane until it is resolved or abandoned. OperationUncertainError.operationId and LaneBlockedError.operationId are exact bigint values. Use resolveOperation(operationId, { deadline }) to replay the retained frame, where deadline is an absolute Date.now() timestamp in milliseconds. The default operation budget is 30 seconds, including admission, routing, link waits and retries.

For a blocked fetch target, LaneBlockedError.partitionId identifies the partition whose retained operation needs repair. A block from an uncertain committing fetch also sets requiresExplicitRecovery, including on stores and deletes, and has errorCode 14009 (PARTITION_LANE_BLOCKED). Other blocks have errorCode 14007 (LANE_BLOCKED). Other single-lane errors leave partitionId undefined.

Resolution requires correlated committed-result proof. A proved business rejection returns the original error and releases the lane. An unproved denial keeps an uncertain operation retained. The client keeps the proved outcomes of its last maxPendingOperations replays, also across a session reset. If a resolver already proved the outcome, a later resolveOperation of the same ID returns it without a request. A resolveOperation call that waits for another replay of the same ID and reaches its deadline fails with OperationUncertainError.

abandonOperation(operationId) releases the client lane without proving that the mutation failed. A replay that is already running keeps the lane until it ends, and the client keeps the outcome that it proves. Logout, session reset and destruction discard retained operations with their outcomes still unknown. OperationNotRetainedError does not establish the outcome: a reset or an abandon came before a proved outcome, or the proved outcome aged out.

Breaking change: Client.destroy() aborts in-flight calls immediately and discards retained operations. It does not wait for outstanding calls to finish. Await those calls before destroying the client when their results are needed.

Next polls that commit nothing (100/106), and non-committing fetches, hold their progress lane only during the active call. Error 57, a lost reply or another unknown outcome ends the call immediately with status 57 and no retained operation ID. These polls never replay after uncertainty. Known non-admission errors 58/89 remain retryable. Pure reads may retry lost replies. Before uncertainty, lifecycle error 88 retries with a fresh ID within the same deadline. After uncertainty, only committed-result proof can release the lane.

An auto-commit poll (100/106) or a committing fetch (109) with an unknown outcome throws FetchProgressUncertainError (local code 14010) and retains progress blocks for every affected partition history. Its operationId is a client-lifetime recovery key, not a server replay receipt. A lost reply, a transport failure after the send, a disconnect or a logout while the call waits leave the outcome unknown.

So does every refusal except those that prove the server stored nothing: 5, 6, 58, 80, 87, 89, 90, 1009, 1010, 2010, 2011, 3007, 3024, 4100 and 5009 for a whole reply, and 58, 80, 87, 89, 3007, 3024 and 5009 for a fetch section.

Later progress polls, fetches, stores and deletes fail with LaneBlockedError carrying that ID, the blocked partition and errorCode 14009. Stateless reads, GetOffset inspection and sends remain available. Reconnect, sign-in and late replies do not clear these blocks.

resolveOperation returns the same uncertainty without I/O. abandonOperation explicitly releases the blocks while accepting that the old server request may still finish. An inspected offset is not a completion barrier.

Valid partial replies preserve healthy sections. An uncertain section carries status: 14010 and progressError. Record decode failures keep their existing rewind behavior. Raw replies keep their wire bytes, so raw callers inspect section statuses and obtain the recovery ID from a later blocked-target call. A partition reader delivers healthy sections and abandons the lost reads of its own committing fetches, so the next read finds what they stored and its streams and consumers go on. Creating a new independent client does not inherit that client's blocks.

Committing fetches reserve a separate bounded recovery pool using maxPendingOperations and maxPendingOperationBytes before sending. The byte charge is the request size, but retained state holds only target identities and the local ID. Capacity refusal occurs before send. A proved result or explicit abandonment releases the reservation. Session reset does not release retained fetch blocks.

Configure maxPendingOperations (default 256) and maxPendingOperationBytes (default 64 MiB) on the client. Admission waits before allocating an ID or freezing a mutation frame. Both limits must be positive. The byte budget includes the 256-byte header and body. Smaller positive budgets reject mutations that cannot fit while reads and login remain available. Oversized frames fail locally. Completion, abandonment and reset release the operation slot. Writer aliases keep bytes charged until they release the frame. These limits cover admitted active/retained frames, not caller buffers, queued API input snapshots, or read/control bodies. sendBinaryRequest preserves its immediate payload snapshot before awaiting a custom provider.

An explicit sign-in uses its caller's credentials and supersedes automatic or queued sign-ins. A failed explicit attempt, including invalid input, timeout or cancellation, withdraws credentials from automatic sign-in until another explicit sign-in succeeds. This also discards a session whose Register succeeded when a later step of the explicit sign-in fails. Earlier calls keep their original lineage. Only SDK recovery continues them under a replacement session.

With server 0.10.1-edge.2, a password change keeps the binary session that submitted it and ends the account's other sessions. Deleting or expiring a personal access token ends access for the sessions opened with it. A valid personal access token can open a new session after a password change. Logout, lease expiry and account deactivation also end session access.

The client pings every heartbeatInterval milliseconds, 5000 by default, which keeps an idle session alive when the server's [heartbeat] eviction is enabled. heartbeatInterval also accepts a duration expression such as "10s" or "1h 30m", like the Rust SDK. With the default heartbeat settings, a client that sends nothing for 36 s (1.2 x the 30 s interval) stops renewing its session, and the server ends the session about 36 s later. The verifier checks once per interval and also evicts the connection of a consumer-group member that is silent past 36 s. If the client interval exceeds 36 s, the verifier evicts an idle group member. If it exceeds about 72 s, or is 0 to disable client heartbeats, any idle session expires. Any other unusable value is rejected instead of silently disabling the heartbeat.

A replica link redials on its own after it drops, with jittered exponential backoff. reconnect.maxRetries limits one burst of redials, not the life of the client. While the client stays signed in, each heartbeat restarts a link that used its budget, with a fresh budget. A request does not redial a link. It retries within its deadline until the link returns. If the deadline ends before the request was sent and no replica refused it, it fails with status 58. destroy() and logout stop the restarts.

When every link used its budget, a request fails with NotConnectedError and does not wait for its deadline. When no endpoint accepts a dial before its retry budget or its deadline ends, a sign-in also fails with NotConnectedError, and its cause holds the last dial error. In both cases a later call can succeed, because the heartbeat restarts the links and each sign-in dials again. If reconnection or heartbeats are disabled, nothing restarts a link that used its budget, so the request fails with a plain Error instead.

Breaking change: singleConsumerStream and groupConsumerStream are adapters over a partition reader, each on a client of its own, and hand over batches with messages only, never an empty one. pollOptions sets maxWait, minCount and maxBytes of each read, and a read waits up to 5 s by default. requestTimeout is not used: a read gives up 10 s after its maxWait. With autocommit, which is the default, the reader commits on read, and the stream reads only when its consumer asks for another batch, so the server never stores a batch that waits in the stream buffer. Without autocommit the stream reads ahead. endOnLastOffset ends the stream once the last read of every partition found no message.

When a read fails with status 30, 40, 57, 58, 89 or 90, after a deadline, after unknown progress, after NotConnectedError and after ConnectionClosedError, the stream reads again after pollingRetryInterval, 1000 ms by default, the same as polling_retry_interval of the Rust consumer. A lost reply of a read that commits is repaired by the reader. The client binds the session again, signs in again, reconnects or routes again after these errors on its own. Any other error ends the stream, and so does a message that does not decode. The server can also refuse a sign-in with status 40, for example for an inactive user. So after a 40 the stream signs in again, and a refused sign-in ends the stream.

singleConsumerStream and groupConsumerStream sign in before they return the stream, and groupConsumerStream also creates and joins its group. If the sign-in or the join fails, the call destroys its client and rejects with that error. If no endpoint accepts a dial before the retry budget or the 30 second sign-in deadline ends, the error is NotConnectedError. When a stream closes, it closes its reader, which waits for a read that commits, moves the offsets of the batches that nobody read back and leaves the group, then destroys its client. A batch still in the stream buffer counts as unread. If the client of a destroyed stream has no session, the stream destroys the client at once, and it never keeps the client longer than 5 seconds for the close.

sendBinaryRequest(code, payload) sends an arbitrary command code. Known replicated commands use their registered operation, while unknown codes reach the server as non-replicated requests and are rejected by servers that do not register them.

import { ResponseError } from "apache-iggy";

try {
  await client.sendBinaryRequest(60_000, Buffer.from("opaque request"));
} catch (error) {
  if (error instanceof ResponseError) {
    console.error(error.commandCode, error.errorCode);
  }
}

The client includes its npm package version and the binary wire protocol version in VSR registration. An incompatible server rejects registration with a protocol-version error instead of accepting a mismatched wire contract.

import { Client } from "apache-iggy";

const credentials = { username: "iggy", password: "iggy" };

const client = new Client({
  transport: "TCP",
  options: { port: 8090, host: "127.0.0.1" },
  credentials,
});

const stats = await client.system.getStats();

Connection strings

Every client constructor (except SimpleClient see note) also accepts a connection string instead of a config object:

import { Client } from "apache-iggy";

const client = new Client("iggy://iggy:iggy@127.0.0.1:8090");
const stats = await client.system.getStats();

Supported schemes are iggy:// (TCP, default) and iggy+tcp://. Credentials are username:password or a single personal access token. Options mirror the other SDKs: tls, tls_domain, tls_ca_file, reconnection_retries, reconnection_interval, heartbeat_interval, nodelay, max_pending_operations and max_pending_operation_bytes. reestablish_after is accepted for format compatibility but has no Node equivalent.

note: SimpleClient does not accept a connection string: it wraps an existing RawClient instance rather than building one from configuration. Pass the connection string to Client, SingleClient or getRawClient and hand the resulting raw client to SimpleClient if needed.

option limits

optionlimit
reconnection_retriesinteger up to 4294967295 (u32 max). Larger values are rejected like Rust's u32 overflow, and unlimited maps to this ceiling. Defaults to unlimited
heartbeat_intervalduration up to 2147483647ms (Node's largest timer delay). 0 disables heartbeats
reconnection_intervalpositive duration (ms, s, m, h) up to 2147483647ms (Node's largest timer delay). Zero spellings are rejected. Defaults to 1s
port in the authoritydecimal up to 65535

Durations accept the same expressions as the Rust SDK, for example 500ms, 10s, 1h 30m, 5d, 2w, 1y. Matching is case-insensitive and 0, unlimited, disabled and none map to zero. Unit-less numbers such as 5 are rejected.

resource options

A stream can carry its own data encryption key. Build it with StreamEncryptionKey.from from exactly 32 random bytes, or from their canonical padded base64, and pass it to stream.create as encryptionKey. Never derive the key from a password, because its fingerprint is readable by anyone who can read the stream. A key that is not 32 bytes or canonical base64 is refused with error 70 before anything is sent.

A StreamEncryptionKey keeps its own copy of the bytes and prints only its fingerprint through util.inspect, JSON.stringify and string conversion, so create arguments carrying it can be logged. Entries passed through options print as given, so an encryption_key entry there is refused with error 70 before anything is sent.

The key travels inside the create request over whatever transport the client uses, so connect over TLS when the key must stay confidential. The server stores the key wrapped and never returns it: reads report only encryptionKeySource, encryptionKeyFingerprint and encryptionKekFingerprints. Without a key, a server with encryption enabled generates one for the stream and reports the source server.

import { randomBytes } from "node:crypto";
import { Client, StreamEncryptionKey } from "apache-iggy";

const client = new Client({
  transport: "TLS",
  options: { host: "localhost", port: 8090 },
  credentials: { username: "iggy", password: "iggy" },
});

const key = StreamEncryptionKey.from(randomBytes(32));
const stream = await client.stream.create({ name: "orders", encryptionKey: key });
console.log(stream.encryptionKeySource); // "stream"
console.log(stream.encryptionKeyFingerprint === key.fingerprint()); // true

stream.update, topic.update and user.update change only the keys they name and leave every other setting as it is, so an update without name keeps the name. reset returns a key to the server default. Use the StreamOptionKey, TopicOptionKey and UserOptionKey constants to name keys.

Only the topic keys message_expiry, max_topic_size, local_retention_age and local_retention_size can be reset. The topic key tiered_storage is enable-only: an update can set it to true, and setting it to false or resetting it is refused with 4103. Settings fixed at create, such as the topic compression algorithm, the partition resize policy or the stream key, have no update field.

A geo topic takes six durations of its own, in microseconds: freshUploadInterval, consumerOffsetUploadInterval, positionsPublishInterval, tombstoneGrace, positionsResumeTimeout and longTermRewriteMaxInterval (GeoTopicDurations). Each overrides the server setting of the same name, and one left out leaves that setting. 0n is a value and is sent. topic.update can set them, and they are the only keys it may change on a geo topic, but a reset of one is refused with 4104. A normal topic refuses them with 4042. Reads report them as bigint, null when unset.

The SDK checks the typed fields and reset before sending, in the server's order and with its error codes (4041 for an unknown key, 4105 for a read-only key, 4103 for a create-only key, 4104 for a key without a default, then the name, username or status error). For a key this build has no field or constant for, pass options entries and rawReset names. The SDK sends those as they are and the server decides, so a refusal comes back from the server.

The server returns 4108 when a non-root caller tries to rename root or change root's status, or when root tries to deactivate itself.

await client.topic.update({
  streamId: "orders",
  topicId: "events",
  messageExpiry: 7_200_000_000n,
  reset: ["max_topic_size"],
});

Reads return every setting in options (keys the client set) and derivedOptions (keys the server filled). u64 values stay bigint, so values above 2^53 keep their precision. system.describeOptions({ scope: OptionsScope.Stream }) lists the keys a server accepts per scope, with updatable, resettable, secret, readOnly and critical.

list pages

stream.list, topic.list, group.list and user.list return a whole list. Each of them reads the list in pages of at most 1,000 items, so the result is not one consistent read. An entity that someone creates or deletes during the walk can appear or not appear. The walk keeps the sign-in and the deadline that it started with. If the server answers a page request with the cursor that the request sent, the walk fails with a DeserializeError.

stream.listPage, topic.listPage, partition.listPage, group.listPage and user.listPage return one page. To read the next page, send the same query with the next of the page as its cursor. A page can be empty and still have a next.

import { Client, type NamedPageQuery } from "apache-iggy";

const printStreams = async (client: Client) => {
  let query: NamedPageQuery = {};
  for (;;) {
    const page = await client.stream.listPage(query);
    for (const stream of page.items)
      console.log(stream.id, stream.name);
    if (!page.next) return;
    query = { ...query, cursor: page.next };
  }
};

A PageQuery holds order, descending, limit and cursor. order selects PageOrder.Id or PageOrder.Created, and descending reverses it. A NamedPageQuery is a PageQuery with an optional name, which keeps the entries whose name holds the text, case-sensitive. stream.listPage, topic.listPage, group.listPage and user.listPage take a NamedPageQuery. partition.listPage takes a PageQuery, which has no name.

The client refuses a query that breaks the page rules with error 3 (invalid command), before it sends anything. Examples are a limit outside 1 to 1000, a name that is empty or longer than 255 bytes, and a partition.listPage query with a name. A PageCursor prints and parses as the pg1_ text form that the HTTP API and the CLI use, and JSON.stringify writes it as that text. The client does not read the bytes of a cursor. The server refuses a cursor that it cannot use, also with error 3.

metadata changes

system.getMetadataChanges reads the node‘s change log: one record per public result of a committed metadata operation, such as a stream created, a topic renamed, a user’s permissions changed or a session closed. A mirror keeps a cursor, asks for the records after it, and stores the returned next cursor. The call needs root or the global manage_servers permission.

import { setTimeout as sleep } from "node:timers/promises";
import {
  Client, MetadataChangeStart, MetadataChangeStatus,
  type MetadataChangeGroup, type MetadataCurrentPageToken,
} from "apache-iggy";

const follow = async (client: Client, groups: MetadataChangeGroup[]) => {
  let start: MetadataChangeStart = MetadataChangeStart.Earliest;
  for (;;) {
    const page = await client.system.getMetadataChanges({ start, groups });
    switch (page.status) {
      case MetadataChangeStatus.Ok:
        for (const record of page.records)
          console.log(record.op, record.kind, record.actorUserId, record.body);
        if (page.next) start = MetadataChangeStart.After(page.next);
        if (!page.hasMore) await sleep(1000);
        break;
      case MetadataChangeStatus.Behind:
        await sleep(100);
        break;
      default:
        start = await rebuild(client, groups);
    }
  }
};

/** Pages the current state, then returns the position to follow from. */
const rebuild = async (client: Client, groups: MetadataChangeGroup[]) => {
  let pageToken: MetadataCurrentPageToken | undefined;
  for (;;) {
    const page = await client.system.getMetadataChanges({
      start: MetadataChangeStart.Current(pageToken), groups,
    });
    if (page.status === MetadataChangeStatus.Behind) {
      await sleep(100);
      continue;
    }
    if (page.status !== MetadataChangeStatus.Ok) {
      pageToken = undefined;
      continue;
    }
    for (const item of page.items)
      console.log(item.group, item.body);
    if (page.currentPageToken) pageToken = page.currentPageToken;
    else if (page.next) return MetadataChangeStart.After(page.next);
    else pageToken = undefined;
  }
};

expired means the log no longer holds the history after the cursor, and reset means the cursor belongs to another history, for example after the data directory was rebuilt. Either way the mirror rebuilds from current state pages and then follows the changes after the anchor they return.

Current pages need the parent groups of every selected group, for example topics with streams. Keep a rebuilt state private until a change page answers ok with hasMore false and a headOp at or above the last current page's.

Records narrow by kind and items by group, so record.kind === "stream_created" types record.body as a stream. A group or kind newer than this build arrives as "unknown" with the raw body and the wire codes in groupCode and kindCode, while a record of a newer kind keeps its known group, so a mirror that cannot apply it can stop without advancing its cursor. Ops, timestamps and 128-bit ids are bigint.

A query that breaks the request rules, such as a limit outside 1 to 1000 or a time bound with a latest or current start, is refused with error 3 before anything is sent. MetadataChangeCursor and MetadataCurrentPageToken print and parse as the mc1_ and cs1_ text forms the HTTP API and the CLI use, and JSON.stringify writes them as that text.

use sources

Cluster polling uses command 15 (BindSession), route discovery 105 and poll 100. Deferred polls use 106, fetches 109 and their cancellation 108. Commands 14, 103, 104 and 123 are retired. Pause consumers for the coordinated server/SDK upgrade and restart them to rejoin their groups. There is no fallback to retired polling commands.

Stream, topic and user updates use the generic update command 16. The former update commands 35, 204 and 304 are retired.

Install

npm ci

build

npm run build

test

note: use env var IGGY_TCP_ADDRESS="host:port" to set the server address for e2e tests. bdd tests need more variables, see below.

unit tests

npm run test:unit

e2e tests

e2e test expect an iggy-server at tcp://127.0.0.1:8090

The resource options tests also expect the server to run with encryption enabled and a config key (IGGY_ENCRYPTION_ENABLED=true and IGGY_ENCRYPTION_KEY set to the base64 of 32 bytes), so a stream created without a key reports a server-generated one. The keyed metadata changes case registered from the same file needs the config key too.

npm run test:e2e

bdd tests

the bdd suite has no defaults and fails when IGGY_TCP_ADDRESS, IGGY_ROOT_USERNAME or IGGY_ROOT_PASSWORD is missing. from the repository root run

./scripts/run-bdd-tests.sh node

the script starts the server and sets every variable, so none of them have to be exported by hand. to iterate against a server you started yourself, see src/bdd/README.md.

run all test

npm run test runs unit, bdd and e2e tests suite against an iggy-server at tcp://127.0.0.1:8090, started with the same root credentials

IGGY_TCP_ADDRESS=127.0.0.1:8090 IGGY_ROOT_USERNAME=iggy IGGY_ROOT_PASSWORD=iggy \
  npm run test

lint

npm run lint