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

vizz.microservice-client

v1.6.2

Published

Library for interact in the microservice with the api-gateway (register, unregister, do request to other microservices, etc)

Downloads

21

Readme

register-microservice-client

Library to register/unregister microservice in the api-gateway. This library implement the /info endpoint that the api-gateway uses to obtain info of the registered microservices. IMPORTANT Now only support koajs 1.x framework. Soon, we support expressjs, etc.

Install

npm install --save vizz.microservice-client

Use in microservice

In listen callback of koajs app add the next code:

    var promise = require('register-microservice-client').register({
        id: config.get('service.id'),
        name: config.get('service.name'),
        dirConfig: path.join(__dirname, '../microservice'),
        dirPackage: path.join(__dirname, '../../'),
        logger: logger,
        app: app //koa app object,
        callbackUpdate: <function> // this callback is called when the api-gateway call to info endpoint. Is called with the new token and api-gateway url (same object that getInfo() returns)
    });
    p.then(function() {}, function(err) {
        logger.error(err);
        process.exit(1);
    });

This code, call to register library with the config of the microservice. All config is required. Is necesary defined 1 environment variables when you are developing in develop environment. This variables are:

  • API_GATEWAY_URL = Url of the api-gateway. For example: http://192.168.99.100:8000

API Reference

register([opts]) => Return Promise Object

Register /info endpoint and in local environment, it make a request to /refresh endpoint in api-gateway to the api-gateway refresh his configuration.

// Config the microservice client to listen /info endpoint in this microservice.
    var p = require('vizz.microservice-client').register({
        id: config.get('service.id'),
        name: config.get('service.name'),
        dirConfig: path.join(__dirname, '../microservice'),
        dirPackage: path.join(__dirname, '../../'),
        logger: logger,
        app: app
    });
    p.then(function() {}, function(err) {
        logger.error(err);
        process.exit(1);
    });

| Param | Type | Description | | --- | --- | --- | | [opts] | Object | | | [opts.id] | String (required) | Id of the service. Is used to replace in register.json | | [opts.name] | String (required) | Name of the service. Is used to replace in register.json | | [opts.dirConfig] | String (required) | Folder dir where it is the config of the microservice (public-swagger.yml, swagger.yml and register.json) | | [opts.dirPackage] | String (required) | Folder dir where it is the package.json file | | [opts.logger] | Object | Object to show logs. If you don't give, library use console.log | | [opts.app] | Object (required) | Koa app object. Is used to register /info endpoint |

requestToMicroservice([opts]) => Return result of request.

Method to call to other microservices registered in the same api-gateway. Is a generator function. Add to opts, the token of authentication with the api-gateway. Use co-request library. Example:

let result = yield require('vizz.microservice-client').requestToMicroservice({
            uri: '/geostore/' + hashGeoStore,
            method: 'GET',
            json: true
        });

| Param | Type | Description | | --- | --- | --- | | [opts] | Request config Object | |

setDataConnection([opts])

Method to manually config the authentication token and api-gateway url. Example:

let result = yield require('vizz.microservice-client').setDataConnection({
            apiGatewayUrl:'http://192.168.1.10:5000',
            authenticationToken: 'a245614bca9...'
        });

| Param | Type | Description | | --- | --- | --- | | [opts] | Object | | | [opts.apiGatewayUrl] | String | Url of api-gateway | | [opts.authenticationToken] | String | Authentication token |

getInfo() => Return result of request.

Return api-gateway url and token obtained when api-gateway call to /info endpoint. Example:

let result = yield require('vizz.microservice-client').getInfo();

| Result | Type | Description | | --- | --- | --- | | [result] | Object | | | [result.apiGatewayUrl] | String | Url of api-gateway | | [result.authenticationToken] | String | Authentication token |

TODO:

  • [ ] Add support to express framework