Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

dart-nats

a dart client for the nats messaging system. design to use with dart and flutter.

flutter web support by websocket

client.connect(uri.parse('ws://localhost:80'));

flutter other platform support by tcp socket and websocket

client.tcpconnect('localhost');
client.connect(uri.parse('ws://localhost:80'));

api change

to support flutter web. we change transport from socket to websocket and also change api call

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(uri.parse('ws://localhost:80'));
  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(uri.parse('wss://demo.nats.io:443');
    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
  • [x] – 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
  • [x] – events/status
  • [ ] – disconnect handler, reconnect handler
  • [x] – buffering message during reconnect atempts
  • [ ] – all authentication models, including nats 2.0 jwt and seed keys
  • [ ] – nats 2.2

Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Top