Represents a message delivered by NATS. This interface is used by Subscribers.

interface Msg {
    data: Uint8Array;
    headers?: MsgHdrs;
    reply?: string;
    sid: number;
    subject: string;
    json<T>(reviver?: ReviverFn): T;
    respond(payload?: Payload, opts?: PublishOptions): boolean;
    string(): string;
}

Properties

data: Uint8Array

The message's data (or payload)

headers?: MsgHdrs

Possible headers that may have been set by the server or the publisher.

reply?: string

A possible subject where the recipient may publish a reply (in the cases where the message represents a request).

sid: number

The subscription ID where the message was dispatched.

subject: string

The subject the message was sent to

Methods

  • Convenience method to parse the message payload as JSON. This method will throw an exception if there's a parsing error;

    Type Parameters

    • T

    Parameters

    • Optionalreviver: ReviverFn

      a reviver function

    Returns T

  • Convenience to publish a response to the reply subject in the message - this is the same as doing nc.publish(msg.reply, ...).

    Parameters

    Returns boolean

  • Convenience method to parse the message payload as string. This method may throw an exception if there's a conversion error

    Returns string