Skip to content

Msg

@wuespace/telestion / nats / Msg

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

Properties

data

data: Uint8Array

The message’s data (or payload)


headers?

headers?: MsgHdrs

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


reply?

reply?: string

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


sid

sid: number

The subscription ID where the message was dispatched.


subject

subject: string

The subject the message was sent to

Methods

json()

json<T>(reviver?): T

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

reviver?: ReviverFn

a reviver function

Returns

T


respond()

respond(payload?, opts?): boolean

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

Parameters

payload?: Payload

opts?: PublishOptions

Returns

boolean


string()

string(): string

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

Returns

string