Client: Client

Isolated

The client provides the capability to publish messages to the NATS server.

Constructor

Initializes the NATS client.

1nats:Client natsClient = check new(nats:DEFAULT_URL);
init (string | string[ ] url, *ConnectionConfiguration config)
  • url string | string[ ]
  • The NATS broker URL. For a clustered use case, provide the URLs as a string array

Remote Methods

publishMessage

Publishes data to a given subject.

requestMessage

Publishes data to a given subject and waits for a response.

Methods

close

Closes the NATS client connection.

publishMessage

function publishMessage(AnydataMessage message) returns Error?
Isolated Function
Remote Function

Publishes data to a given subject.

1check natsClient->publishMessage(message);

Parameters

Return Type

(Error?)

() or else a nats:Error if an error occurred

requestMessage

function requestMessage(AnydataMessage message, decimal? duration, typedesc<AnydataMessage> T) returns T | Error
Isolated Function
Remote Function

Publishes data to a given subject and waits for a response.

1check natsClient->requestMessage(message, 5);

Parameters

  • duration decimal? (default ())
  • The time (in seconds) to wait for the response

  • T typedesc<AnydataMessage> (default <>)
  • Type of AnydataMessage to be returned

Return Type

(T | Error)

The response or else a nats:Error if an error occurred

close

function close() returns Error?
Isolated Function

Closes the NATS client connection.

1check natsClient.close();

Return Type

(Error?)

() or else a nats:Error if an error is occurred