Skip to content
/ tasu Public
forked from yentsun/tasu

A NATS-based message transport for Node.js services. Taşuu (ташуу) is 'transport' in Kyrgyz.

License

Notifications You must be signed in to change notification settings

trueshura/tasu

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tasu

A wrapper over node-nats, designed to easily integrate with your code. Taşuu (ташуу) is 'transport' in Kyrgyz.

Installation

npm i tasu

Usage

Create an instance of the wrapper:

const Tasuu = require('tasu');


const tasu = new Tasuu({group: 'some-service'});
 tasu.on('connect', () => {
     // wrapper is ready at this point
 });
 tasu.on('error', (error) => {
     throw error;
 });

Publish a request and get a response via async/await:

async () => {
    const {bar} = await tasu.request('foo', {arg: 1});
    ...
};

Note: this method uses requestOne inside, no need to worry about max
responses

Subscribe and respond to a request:

tasu.listen('foo', ({arg}, respond) => {
    ...
    respond(error, {bar: 2});
});

Note: a listener is automatically added to queue group some.request.listeners

Publish an event:

tasu.publish('some.package.sent', {...});

Subscribe and process as worker queue:

 tasu.process('*.package.sent', (pack, subject) => {
    console.log(subject, pack);
});

listen, subscribe and process methods return an integer subscription ID (SID) which can be used to unsubscribe from a subject:

const sid = tasu.process('*.package.sent', (pack, subject) => {
    console.log(subject, pack);
});

// ...

tasu.unsubscribe(sid);

Close NATS connection (if needed):

tasu.close();

Environment variables

  • NATS_LOG_LEVEL - set wrapper's log level. Default is debug

About

A NATS-based message transport for Node.js services. Taşuu (ташуу) is 'transport' in Kyrgyz.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%