npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-nameko-client

v1.0.16

Published

Node.JS client for Nameko microservice framework.

Downloads

41

Readme

node-nameko-client is a library for interacting with Nameko microservices framework.

Usage

This example connects to RabbitMQ and calls send_mail method from mailer service:

var nameko = require('node-nameko-client');

nameko.connect({host: '127.0.0.1', port: 5672}).on('ready', function(rpc) {
    rpc.call('mailer', 'send_mail', ['[email protected]', 'Hello!', 'It\'s been a lo-o-o-ong time.'], {}, function(e, r) {
        if (e) {
            console.log('Oops! RPC error:', e);
        } else {
            console.error('Success: Result is', r);
        }
    });
});

// You can also use promises. Here's an example with promises & ES6 syntax:

nameko.connect({host: '127.0.0.1', port: 5672})
    .then(
        rpc => rpc.call('mailer', 'send_mail', ['[email protected]', 'Hello!', 'It\'s been a lo-o-o-ong time.']);
    )
    .then(
        result => console.log('Success: Result is', result);
    )
    .catch(
        error => console.error('Oops! RPC error:', error.stack);
    )
;

Installation

npm install node-nameko-client

Methods

.connect([config, [callback, [onError]]])

This method takes one optional argument: a config object. Allowed keys are:

  • host - RabbitMQ host (default: "127.0.0.1")
  • port - RabbitMQ port (default: 5672)
  • login - RabbitMQ username (default: "guest")
  • password - RabbitMQ password (default: "guest")
  • exchange - RabbitMQ exchange (default: "nameko-rpc")
  • timeout - Timeout for waiting for response (in ms, default: 5000)
  • debug_level - Debug level. Choices are "debug", "info", "warning" or "error" (default: "debug"). Has no effect if logger is provided (see below.)
  • logger - Custom logger to use (default: null). debug_level will have no effect if you provide it.

callback is called when the connection succeeds, onError is called when a connection error occurs.

If callback is not provided then this method returns Promise.

.call(service_name, method_name, [args, [kwargs, [callback(e, r)]]])

Performs RPC call by sending event to the appropriate RabbitMQ queue. args should be a list or undefined, kwargs should be an object or undefined.

If a callback is provided it will be called once a method is complete. Otherwise this method returns Promise.

Using with ExpressJS

They also play well together:

var nameko = require('node-nameko-client');
var express = require('express');

var app = express();
var rpc = nameko.connect({host: '127.0.0.1', port: 5672});

rpc.on('ready', function() {
    console.log('Connected to AMQP.');

    app.listen(9000, function() {
        console.log('Server started on port 9000.');
    });
});

app.get('/', function(req, res) {
    rpc.call('mailer', 'ping', ['[email protected]', 'Hello!', 'It\'s been a lo-o-o-ong time.'], {}, function(e, r) {
        if (e) {
            res.send('Oops! RPC error: ' + e);
        } else {
            res.send('Success: Result is ' + r);
        }
    });
});

What's on the roadmap?

  • [x] Promises
  • [x] Reusing reply queues for better performance
  • [ ] Fixing some unknown hard-coded values (already have information from Nameko devs regarding this, will fix soon)
  • [ ] Adding support for event broadcasting (e. g. BROADCAST & SINGLETON message types)
  • [ ] Adding tests

License

The license is MIT.

Issues

Any contribution is highly appreciated! Feel free to submit an issue here: https://github.com/and3rson/node-nameko-client/issues.