Skip to main content

Function: declareStreams()

declareStreams(nc): Promise<DeclaredStream[]>

Defined in: packages/messaging/src/stream-setup.ts:203

Declares every stream in the permission table and each of its durable consumers, as streams.ts configures them. Run by the setup runner (bootstrap), the only principal granted stream create and update, never by the service that reads the stream.

Idempotent. A missing stream or consumer is created. One that differs from the declaration is updated back to it, so a changed bound reaches an existing stream and a consumer whose filter was widened is narrowed again. One that already agrees is not written to.

Every existing stream is settled before any missing one is created. The broker refuses two streams that capture one subject, so when a subject moves from one stream to a new one (placement.changed left PROVISIONING for PLACEMENT in slice 3), the old stream has to give the subject up first. Doing all the updates first makes that hold whatever order the table lists the streams in.

A consumer the table no longer lists is left alone. It is not deleted here: the setup principal holds no grant to list or delete consumers, and is not given one, because deleting a consumer forgets what its reader acknowledged and a principal that could do it could make any reader start over. A durable left behind by a move delivers nothing (its stream no longer captures its filter) and no principal may read it; an operator removes it once.

Parameters​

nc​

NatsConnection

A connection as the setup principal.

Returns​

Promise<DeclaredStream[]>

One entry per stream, in table order.

Throws​

The broker refused (permissions), is unreachable, or a stream or consumer could not be brought back by an update (a sealed stream, or a field JetStream does not let an existing consumer change; the message names it, and an operator has to remove it, after backing a stream up, so that the next run declares it again).