dart_nats 0.1.4 copy "dart_nats: ^0.1.4" to clipboard
dart_nats: ^0.1.4 copied to clipboard

outdated

A Dart client for the NATS messaging system. It's simple. Design to use with flutter easy to write no need to deal with complex asynchronous.

Dart-NATS #

A Dart client for the NATS messaging system. It's simple. Design to use with flutter easy to write no need to deal with complex asynchronous.

Dart Examples: #

Run the example/main.dart:

dart example/main.dart
import 'package:dart_nats/dart_nats.dart';

void main() async {
  var client = Client();
  client.connect('localhost');
  var sub = client.sub('subject1');
  client.pubString('subject1', 'message1');
  var msg = await sub.stream.first;

  print(msg.payloadString);
  client.unSub(sub);
  client.close();
}

Flutter Examples: #

Import and Declare object

import 'package:dart_nats/dart_nats.dart' as nats;

  nats.Client natsClient;
  nats.Subscription fooSub, barSub;

Simply connect to server and subscribe to subject

  void connect() {
    natsClient = nats.Client();
    natsClient.connect('demo.nats.io');
    fooSub = natsClient.sub('foo');
    barSub = natsClient.sub('bar');
  }

Use as Stream in StreamBuilder

          StreamBuilder(
            stream: fooSub.stream,
            builder: (context, AsyncSnapshot<nats.Message> snapshot) {
              return Text(snapshot.hasData ? '${snapshot.data.payloadString}' : '');
            },
          ),

Publish Message

      natsClient.pubString(subject, _controller.text);

Dispose

  void dispose() {
    natsClient.close();
    super.dispose();
  }

Full Flutter sample code example/flutter/main.dart

Done #

  • inbox
  • nuid
  • Connect to NATS Server
  • Basic sub and pub
  • Reconnect to single server when connection lost and resume subscription

Todo #

  • sub sync
  • sub with max message
  • Connect to cluster
  • authentication
  • TLS support
32
likes
0
pub points
83%
popularity

Publisher

unverified uploader

A Dart client for the NATS messaging system. It's simple. Design to use with flutter easy to write no need to deal with complex asynchronous.

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

More

Packages that depend on dart_nats