#nats #client #messaging #api #async

nats-aflowt

Unofficial port of NATS rust client to pure async

5 releases

Uses new Rust 2021

0.16.105 Feb 14, 2022
0.16.104 Feb 7, 2022
0.16.103 Jan 11, 2022
0.16.102 Jan 10, 2022
0.16.101 Jan 8, 2022

#856 in Network programming

Download history 191/week @ 2022-03-11 252/week @ 2022-03-18 73/week @ 2022-03-25 99/week @ 2022-04-01 102/week @ 2022-04-08 211/week @ 2022-04-15 218/week @ 2022-04-22 266/week @ 2022-04-29 500/week @ 2022-05-06 317/week @ 2022-05-13 261/week @ 2022-05-20 542/week @ 2022-05-27 138/week @ 2022-06-03 177/week @ 2022-06-10 184/week @ 2022-06-17 86/week @ 2022-06-24

816 downloads per month
Used in 18 crates (via wasmbus-rpc)

Apache-2.0

375KB
6.5K SLoC

Experimental port of rust NATS client to rust async

Don't get blocked by asynk - stay aflowt

The nats::asynk module is an async veneer over blocking io and consumes a thread-per-connection, and, depending on how you use subscriptions, an additional thread per subscription handler. This package uses real async throughout the client. All connections and subscriptions are non-blocking and may safely share the same thread, or, optionally, a thread pool.

This package is not endorsed by the Nats team. I wrote it as an experiment after running into some limitations with ratsio, another nats async client.

📢 Warning

⚠️ This should only be used in environments where software is expected to hang, consume all CPU, destroy data, and explode at random intervals.

Status (Jan 8, 2022)

  • Feature parity with rust nats client (including jetstream, tls, etc.) as of commit d22329c (main branch, jan 7, 2022)

  • Tested on linux x86_64. All tests pass except for two: (jetstream:kv and jetstream:object_store), which are currently disabled by a feature flag.

  • apis are subject to change

Changes from nats.rs

  • can run all async tasks in a single thread (subscriptions and connections do not spawn new threads)
  • in the port to async, many apis have changed:
    • most public functions have been changed to be async
    • all functions that used to return an Iterator now return futures::Stream
    • wherever there was an explicit iter(..) method to create an iterator, it's been replaced with stream(..).
    • jetstream PagedIterator replaced with Stream
    • error callbacks must now implement a trait, instead of being a simple closure. See doc comments and examples folder for examples.
    • added Subscription.with_async_handler to take async closure
      • (Subscription.with_handler still takes sync closure)
  • jetstream kv and object_store functions are enabled in this crate in the default feature set to support testing. (In nats.rs they are behind an "unstable" feature flag and should be considered unstable here).
  • some tests have been added
  • upgraded to rust 2021 edition

This crate currently depends on the tokio runtime. I suspect if the Nats team does develop a pure async rust client, they will attempt to make it runtime agnostic.

Dependencies

~16–26MB
~583K SLoC