Clients - nats : Producer

NATS Producer would act as a basic client allowing to publish messages to the NATS server. Producer needs the NATS Connection to be initialized.

Constructor

__init

(Connection connection)

  • connection Connection
  • An already-established connection.

Remote Methods

publish

Produces a message to a NATS basic server for the given subject.

request

Produces a message and would wait for a response.

Methods

publish

(string subject, Content data, string | service | () replyTo)

returns Error?

Produces a message to a NATS basic server for the given subject.

Parameters

  • subject string
  • The subject to send the message to.

  • replyTo string | service | () (default ())
  • The subject or the callback service the receiver should send the response to.

  • Return Type

    (Error?)
  • A specific error if there is a problem when publishing the message. Returns () otherwise.

request

(string subject, Content data, int duration)

returns Message | Error

Produces a message and would wait for a response.

Parameters

  • subject string
  • Would represent the topic/queue name.

  • data Content
  • The message body to publish.

  • duration int (default ())
  • The time to wait for a response measured in milliseconds.

  • Return Type

    (Message | Error)
  • The response message or an error.

close

()

returns Error?

Close a given connection.

  • Return Type

    (Error?)
  • Retruns () or the error if unable to complete the close operation.