Skip to main content
Deno 2 is finally here 🎉️
Learn more
Go to Latest
interface Msg
import { type Msg } from "https://deno.land/x/natsws@v1.28.0/src/nats-base-client.ts";

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

Properties

subject: string

The subject the message was sent to

sid: number

The subscription ID where the message was dispatched.

optional
reply: string

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

data: Uint8Array

The message's data (or payload)

optional
headers: MsgHdrs

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

Methods

respond(payload?: Payload, opts?: PublishOptions): boolean

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

json<T>(reviver?: ReviverFn): T

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

string(): string

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