This API documentation is for Ballerina 1.2.0. View API documentation for the latest release.

Clients - nats : StreamingProducer

The streaming producer provides the capability to publish messages to the NATS streaming server. The nats:StreamingProducer needs the nats:Connection to be initialized.



(Connection connection, string? clientId, string clusterId, StreamingConfig? streamingConfig)

  • connection Connection
  • An established NATS connection

  • clientId string? ()
  • A unique identifier of the client

  • clusterId string test-cluster
  • The unique identifier of the cluster configured in the NATS server

  • streamingConfig StreamingConfig? ()
  • The configuration related to the NATS streaming connectivity

Remote Methods


Publishes data to a given subject.


Close the producer.


(string subject, Content data)

returns string | Error

Publishes data to a given subject. ballerina string|error result = producer->publish(subject, <@untainted>message);


  • subject string
  • The subject to send the message

  • Return Type

    (string | Error)
  • The string value representing the NUID (NATS Unique Identifier) of the published message if the message gets successfully published and acknowledged by the NATS server, a nats:Error with NUID and message fields in case an error occurs in publishing, the timeout elapses while waiting for the acknowledgement, or else a nats:Error only with the message field in case an error occurs even before publishing is completed



returns error?

Close the producer.

  • Return Type

  • () or else a nats:Error if unable to complete the close operation.