stan_dart 0.0.2 stan_dart: ^0.0.2 copied to clipboard
Dart client for NATS-Streaming, an extremely performant, lightweight reliable streaming platform built on NATS.
stan.dart #
A Dart client for NATS-Streaming, an extremely performant, lightweight reliable streaming platform built on NATS.
Note: this package is still in pre-release and not all features/functionalities are yet implemented. #
Usage #
// create a connection
var client = await Client.connectSingle(natsHost, 'myApp', username: natsUsername, password: natsPassword);
// subscribe to a topic
client.subscribe('myTopic', handler: (DataMessage message, {NatsError error}) {
log.general.info('ooh, looky! A message for meeeeeee! ::: ${message.decodedPayload}');
});
// publish a message
await client.publish('myTopic', payload: 'this is an event on topic: myTopic')); // -- let the client encode it for us (with the default encoder (ascii))
// publish a message with a custom encoding
await client.publish('myTopic', payload: 'this is another event on topic: myTopic'), encoding: utf8); // -- specify our own encoding
// publish a message of raw bytes
var alreadyEncodedMessageBytes = ascii.encode('this is a pre-encoded event on topic: myTopic');
await client.publish('myTopic', payload: alreadyEncodedMessageBytes, encoding: null); // -- passing a null-encoding tells the client encoding has already been done
See example files for more awesomeness.