NatsX
Reactive Nats client and RxJS wrapper for ts-nats
$ npm i --save natsx
Usage
The main purpose of the library is to manage nats subscription behavior with RxJS operators like take
and timeout
.
You can pass a nats client or use connect() method of NatsX to initalize the wrapper
;; ;;client.from'greeting'.subscribe
To unsubscribe from nats subscription, you must unsubscribe from the observable with operators or manually.
// that will get 3 greeting messages then unsubscribe from nats subscriptionclient.from'greeting' .pipe take3 .subscribe
To achieve the same ability for nats requests, we are not using the ts-nats request method directly. You must manage your subscription same way of from
method of NatsX
// that will wait a response for 2 seconds then throw timeout error and unsubscribe from reply subject.client.request'greeter', 'me' .pipe timeout2000 .subscribe
Also, you can use other methods like publish
, close
, drain
and listen the connection status with status$
, and other nats events with error$
, subscriptions$
, serverChanged$
, yield$
Contributing
You are welcome to contribute to this project, just open a PR.
License
- NatsX is MIT licensed.