@nats-io/nats-core
    Preparing search index...

    Interface Msg

    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;
        respondRequest(
            payload?: Payload,
            opts?: Partial<Omit<RequestOptions, "noMux" | "reply">>,
        ): Promise<Msg>;
        string(): string;
    }
    Index
    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

    • 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 to publish a request to the reply subject in the message, resolving with the first response to it. Rejects if the message has no reply subject.

      The reply subject (typically the requester's inbox) must be handled by a subscriber that expects a request there, and responds to it. A requester using a plain request() won't: its reply is the response, and nothing answers the follow up, so this times out or rejects with no responders.

      This is useful when implementing custom protocols over NATS, where the response shares an inbox where the client can send additional message(s).

      Parameters

      • Optionalpayload: Payload
      • Optionalopts: Partial<Omit<RequestOptions, "noMux" | "reply">>

        timeout defaults to 2000 millis

      Returns Promise<Msg>

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

      Returns string