Options
All
  • Public
  • Public/Protected
  • All
Menu

NATS server Client object.

Hierarchy

  • EventEmitter
    • Client

Index

Properties

createInbox

createInbox: createInbox = createInbox

Returns an unique and properly formatted inbox subject that can be used for replies

Static defaultMaxListeners

defaultMaxListeners: number

Methods

addListener

  • addListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

close

  • close(): void
  • Closes the connection to the NATS server. A closed client cannot be reconnected.

    Returns void

drain

  • drain(): Promise<any>
  • Drains all subscriptions. Returns a Promise that when resolved, indicates that all subscriptions have finished, and the client closed. Note that after calling drain, it is impossible to create new subscriptions or make any requests. As soon as all messages for the draining subscriptions are processed, it is also impossible to publish new messages. A drained connection is closed when the Promise resolves.

    see

    Subscription.drain

    Returns Promise<any>

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

eventNames

  • eventNames(): Array<string | symbol>
  • Returns Array<string | symbol>

flush

  • Flush outbound queue to server and call optional callback when server has processed all data.

    Parameters

    • Optional cb: FlushCallback

      is optional, if not provided a Promise is returned. Flush is completed when promise resolves.

    Returns Promise<void> | void

    Promise or void if a callback was provided.

getMaxListeners

  • getMaxListeners(): number
  • Returns number

isClosed

  • isClosed(): boolean
  • Returns boolean

    true if the NATS client is closed.

listenerCount

  • listenerCount(type: string | symbol): number
  • Parameters

    • type: string | symbol

    Returns number

listeners

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

numSubscriptions

  • numSubscriptions(): number
  • Report number of subscriptions on this connection.

    Returns number

off

  • off(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

on

  • on(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

once

  • once(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependListener

  • prependListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

publish

  • publish(subject: string, data?: any, reply?: string): void
  • Publish a message to the given subject, with optional payload and reply subject.

    Parameters

    • subject: string
    • Default value data: any = undefined

      optional (can be a string, JSON object, or Buffer. Must match [[NatsConnectionOptions.payload].)

    • Default value reply: string = ""

      optional

    Returns void

rawListeners

  • rawListeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

removeAllListeners

  • removeAllListeners(event?: string | symbol): this
  • Parameters

    • Optional event: string | symbol

    Returns this

removeListener

  • removeListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

request

  • request(subject: string, timeout?: number, data?: any): Promise<Msg>
  • Publish a request message with an implicit inbox listener as the reply. Message is optional. This should be treated as a subscription. The subscription is auto-cancelled after the first reply is received or the timeout in millisecond is reached.

    If a timeout is reached, the promise is rejected. Returns the received message if resolved.

    Parameters

    • subject: string
    • Default value timeout: number = 1000
    • Default value data: any = undefined

      optional (can be a string, JSON object, or Buffer. Must match specified Payload option)

    Returns Promise<Msg>

    Promise

setMaxListeners

  • setMaxListeners(n: number): this
  • Parameters

    • n: number

    Returns this

subscribe

  • Subscribe to a given subject. Messages are passed to the provided callback.

    Parameters

    Returns Promise<Subscription>

    Promise

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • deprecated

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number

Legend

  • Property
  • Method
  • Property
  • Inherited method

Generated using TypeDoc