Sending Messages

    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:

    Java

    1. nc.publish("updates", "All is Well".getBytes(StandardCharsets.UTF_8));
    2. // Make sure the message goes through before we close
    3. nc.close();

    Python

    1. nc = NATS()
    2. await nc.connect(servers=["nats://demo.nats.io:4222"])

    TypeScript

    1. let nc = await connect({
    2. url: "nats://demo.nats.io:4222",
    3. payload: Payload.STRING
    4. nc.publish('updates', 'All is Well');