Setting up a client and firing up a connection
var client = NatsClient('ws://demo.host:port/path');
await client.connect();
...
await client.close();
Publishing a message can be done with or without a reply-to
topic
// No reply-to topic set
client.publish("sub-id", "foo");
// If server replies to this request, send it to `bar`
client.publish("sub-id", "foo", replyTo: "bar");
To subscribe to a topic, specify the topic and optionally, a queue group
var subStream = client.subscribe("sub-id", "foo");
// If more than one subscriber uses the same queue group,
// only one will receive the message
var subStream = client.subscribe("sub-id", "foo", queueGroup: "group-1");
subStream.listen((message) {
// Do something awesome
});