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
nc.publish("updates", "All is Well".getBytes(StandardCharsets.UTF_8));
// Make sure the message goes through before we close
nc.close();
Python
nc = NATS()
await nc.connect(servers=["nats://demo.nats.io:4222"])
TypeScript
let nc = await connect({
url: "nats://demo.nats.io:4222",
payload: Payload.STRING
nc.publish('updates', 'All is Well');