Bitbucket Pipelines branch Codecov Dart Version License

nats.dart

A Dart client for NATS, a lightweight, high-performance cloud native messaging system


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, 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', data: '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', data: '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', data: alreadyEncodedMessageBytes, encoding: null); // -- passing a null-encoding tells the client encoding has already been done

See example files for more awesomeness.


Note: this package is still in pre-release and not all features/functionalities are yet implemented.

Contributors and PRs welcome!

Libraries

nats_dart
watchdog