This page has moved to

Click here if you are not redirected.

Sending Messages

NATS sends and receives messages using a protocol that includes a target subject, an optional reply subject and an array of bytes. Some libraries may provide helpers to convert other data formats to and from bytes, but the NATS server will treat all messages as opaque byte arrays.

All of the NATS clients are designed to make sending a message simple. For example, to send the string “All is Well” to the “updates” subject as a UTF-8 string of bytes you would do:

nc, err := nats.Connect("", nats.Name("API PublishBytes Example"))
if err != nil {
defer nc.Close()

if err := nc.Publish("updates", []byte("All is Well")); err != nil {
Connection nc = Nats.connect("nats://");

nc.publish("updates", "All is Well".getBytes(StandardCharsets.UTF_8));

// Make sure the message goes through before we close
let nc = NATS.connect({url: "nats://"});
nc.publish('updates', "All is Well");
nc = NATS()

await nc.connect(servers=["nats://"])

await nc.publish("updates", b'All is Well')

require 'nats/client'

NATS.start(servers:["nats://"]) do |nc|
  nc.publish("updates", "All is Well")
let nc = await connect({
    url: "nats://",
    payload: Payload.STRING
nc.publish('updates', 'All is Well');

results matching ""

    No results matching ""