Interface JetStreamClient

Interface for interacting with JetStream data

interface JetStreamClient {
    apiPrefix: string;
    consumers: Consumers;
    streams: Streams;
    fetch(stream: string, durable: string, opts?: Partial<PullOptions>): QueuedIterator<JsMsg>;
    getOptions(): JetStreamOptions;
    jetstreamManager(checkAPI?: boolean): Promise<JetStreamManager>;
    publish(subj: string, payload?: Payload, options?: Partial<JetStreamPublishOptions>): Promise<PubAck>;
    pull(stream: string, consumer: string, expires?: number): Promise<JsMsg>;
    pullSubscribe(subject: string, opts: ConsumerOptsBuilder | Partial<ConsumerOpts>): Promise<JetStreamPullSubscription>;
    subscribe(subject: string, opts: ConsumerOptsBuilder | Partial<ConsumerOpts>): Promise<JetStreamSubscription>;
}

Properties

apiPrefix: string

Returns the JS API prefix as processed from the JetStream Options

consumers: Consumers

Returns the interface for accessing Consumers. Consumers allow you to process messages stored in a stream. To create a consumer use JetStreamManager.

streams: Streams

Returns the interface for accessing Streams.

Methods

  • Similar to pull, but able to configure the number of messages, etc. via PullOptions.

    Parameters

    • stream: string

      the name of the stream

    • durable: string

      the consumer's durable name (if durable) or name if ephemeral

    • Optionalopts: Partial<PullOptions>

    Returns QueuedIterator<JsMsg>

  • Returns a JetStreamManager that uses the same JetStreamOptions as the current JetStream context

    Parameters

    • OptionalcheckAPI: boolean

    Returns Promise<JetStreamManager>

  • Publishes a message to a stream. If not stream is configured to store the message, the request will fail with ErrorCode.NoResponders error.

    Parameters

    • subj: string

      the subject for the message

    • Optionalpayload: Payload

      the message's data

    • Optionaloptions: Partial<JetStreamPublishOptions>

      the optional message

    Returns Promise<PubAck>

  • Retrieves a single message from JetStream

    Parameters

    • stream: string

      the name of the stream

    • consumer: string

      the consumer's durable name (if durable) or name if ephemeral

    • Optionalexpires: number

      the number of milliseconds to wait for a message

    Returns Promise<JsMsg>

  • Creates a pull subscription. A pull subscription relies on the client to request more messages from the server. If the consumer doesn't exist, it will be created matching the consumer options provided.

    It is recommended that a consumer be created first using JetStreamManager APIs and then use the bind option to simply attach to the created consumer.

    If the filter subject is not specified in the options, the filter will be set to match the specified subject.

    It is more efficient than fetch or pull because a single subscription is used between invocations.

    Parameters

    Returns Promise<JetStreamPullSubscription>

  • Creates a push subscription. The JetStream server feeds messages to this subscription without the client having to request them. The rate at which messages are provided can be tuned by the consumer by specifying ConsumerConfig.rate_limit_bps and/or maxAckPending.

    It is recommended that a consumer be created first using JetStreamManager APIs and then use the bind option to simply attach to the created consumer.

    If the filter subject is not specified in the options, the filter will be set to match the specified subject.

    Parameters

    Returns Promise<JetStreamSubscription>