dart_nats 0.1.6+1

  • Readme
  • Changelog
  • Example
  • Installing
  • new73

Dart-NATS #

A Dart client for the NATS messaging system.

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.string);
  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.string}' : '');
            },
          ),

Publish Message

      natsClient.pubString('subject','message string');

Dispose

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

Full Flutter sample code example/flutter/main.dart

Features #

The following is a list of features currently supported and planned by this client:

  • [x] - Publish
  • [x] - Subscribe, unsubscribe
  • [x] - NUID, Inbox
  • [x] - Reconnect to single server when connection lost and resume subscription
  • [x] - Unsubscribe after N message
  • [x] - Request, Respond
  • [x] - Queue subscribe
  • [ ] - caches, flush, drain
  • [ ] - Request timeout
  • [ ] - structured data
  • [ ] - Connection option (cluster, timeout,ping interval, max ping, echo,... )
  • [ ] - Random automatic reconnection, disable reconnect, number of attempts, pausing
  • [ ] - Connect to cluster,randomize, Automatic reconnect upon connection failure base server info
  • [ ] - Events/status disconnect handler, reconnect handler
  • [ ] - Buffering message during reconnect atempts
  • [ ] - All authentication models, including NATS 2.0 JWT and seed keys
  • [ ] - TLS support

0.1.6+1 #

  • Improve receive buffer handling

0.1.6 #

  • async connect
  • fix defect message delay when sub receive continuous message

0.1.5+1 #

  • fix defect

0.1.5 #

  • request/respond function
  • change some wording from payload to data

0.1.4+1 #

  • add inbox to generate unique inbox subject
  • add nuid to generate unique id

0.1.3+4 #

  • refactor code
  • add commend

0.1.3+1 #

  • add string api client.pubString and message.string
  • fix defect: pub sub non ascii
  • fix defect: message include \r or \n
  • revamp message decoding

0.1.2 #

  • change api from string to byte array

0.1.1 #

  • publish can be buffered.

0.1.0+4 #

  • Update sample code

0.1.0+3 #

  • Update sample code

0.1.0+2 #

  • Update readme

0.1.0+1 #

  • Add readme

0.0.2+1 #

  • Add change log

0.0.2 #

  • Refactor code

0.0.1 #

  • Initial experimental version

example/main.dart

import 'package:dart_nats/dart_nats.dart';

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

  print(data.string);
  client.unSub(sub);
  client.close();
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  dart_nats: ^0.1.6+1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:dart_nats/dart_nats.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
47
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
73
Learn more about scoring.

We analyzed this package on Jan 19, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
Dev dependencies
pedantic ^1.9.0
test ^1.9.4