0.3.4 • Published 5 years ago

miko-tvc v0.3.4

Weekly downloads
5
License
MIT
Repository
github
Last release
5 years ago

Miko (巫女)

JavaScript client to make RPC calls to Nameko services.

Inspired by node-nameko-client by @and3rson 🙏

Installation

npm install miko

Usage

Make sure you have a Nameko service up and running.

You can use the test service:

cd nameko-test-service
docker-compose up --build

Example usage:

const { connect } = require('./src/miko');

// First, connect to the queue
// connect returns a promise which will be resolved when everything goes ok
//
//
//  Default options:
//
// host: '127.0.0.1',
// port: 5672,
// login: 'guest',
// password: 'guest',
// exchange: 'nameko-rpc',
// timeout: 5000,
//

connect()
  .then((rpc) => {
    // Use rpc to make calls to nameko services

    rpc
      .fetch('demo_svc', 'noargs')
      // .fetch('demo_svc', 'get_data')
      // .fetch('demo_svc', 'get_data', [2])
      // .fetch('demo_svc', 'get_data', [], { copies: 10})
      // .fetch('demo_svc', 'required_and_optional', ['test'])
      // .fetch('demo_svc', 'variable', ['test', 'another'], { o: 1 })
      // .fetch('demo_svc', 'return_none')
      // .fetch('demo_svc', 'return_auth_token')
      // .fetch('demo_svc', 'raise_value_error')
      // .fetch('demo_svc', 'raise_exception')
      // .fetch('demo_svc', 'raise_index_error')
        .then((response) => {
          console.log('Response', response);
          rpc.close();
        })
        .catch((err) => {
          console.log('Response error', err);
          rpc.close();
        });
  })
  .catch((err) => {
    console.log('Connection error', err);
  });

Custom loggers

By default, Miko logs what is going on with the connection to Nameko to the console. If you need to use a custom logger (for example, to log events to file or to an external server), you can add your own loggers to Miko.

connect(options, loggers).then(...)

Loggers is an array of Winston loggers.

You can find an example of file logger in test/endpoint.test.js.

Testing

Make sure you have the Nameko test service up and running:

cd nameko-test-service
docker-compose up --build

Then, after the docker containers are set up and running, you can run Miko tests:

npm test

The command above runs all tests. You can also run only unit tests (which don't require Nameko service up and running):

npm run test:unit

License

MIT