node-etcd-servicecatalog
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

About

This module is for inclusion in your NodeJS based application.

The goal is to provide a very simple ServiceCatalog implementation. It's very crude, and is only good for smaller implementations.

It's for basic microservices, one server, one service endpoint. In theory there is no reason why you couldn't use multiple service instances, as long as, you don't mind the traffic.

Issues

  1. Currently it seems overly heavy on the etcd, and that traffic should be reduced.

  2. The findEndpointForPath uses the magic word 'ui' to consider as a fallback service. That comes from the nature of the application I currently use it for.

  3. There is no mechanism to handle specialized or overlapping paths. For example if you want Service A to be mapped at /myservice/*, but Service B is to be mapped at /myservice/foobar/* it will be first-come-first served. It would be pretty simple to do a more advanced matching, but I don't need it at the moment.

How to use

Read the API docs and the code. If in doubt ask the author.

API

ServiceCatalog

ServiceCatalog (registryHost:string, registryPort:number, servicePrefix:string, serviceName:string, servicePath:string, servicePort:number, serviceUrl:string)

Constructor for the ServiceCatalog. It will publish the service provided by the application on startup.

registryHost - The IP address of the etcd instance to use

registryPort - The port of the etcd instance to use

serviceName - The service this server provides

servicePath - The path the service should map to. It will be converted to RegExp to match the begining of the URL only

servicePort - The port the provided service is available on (can be null)

serviceUrl - The url the provided service is available on (can be null)

findServiceIndex(data:ServiceEndpoint):number

@return the position of the serviceEndpoint in the catalog.

A service is considered to be the same if it's name and hostname match. To be used internally.

findEndpointForPath(path:string):ServiceEndpoint[]

@return all endpoints matching the path, or the fallback endpoints (currently services named ui, see Issues above) otherwise

findFirstEndpointForName(serviceName:string):ServiceEndpoint

@return the first endpoint providing the named service, or null if there is none

subscribe(serviceName:string, callbackOnCatalog:Function, callbackOnUncatalog:Function):void

Subscribes to the changes of the named service. NB. The currently registered services are not scanned on subscription. See issue #1

serviceName - The service to subscribe to

callbackOnCatalog - A callback function with a [ServiceEndpoint] parameter containing the newly created ServiceEndpoint

callbackOnUnatalog - A callback function with an optional [ServiceEndpoint] parameter containing the previous version of the unregistered ServiceEndpoint

ServiceEndpoint

This is a class for holding the endpoints, and also a placeholder for statistical information.

Package Sidebar

Install

npm i node-etcd-servicecatalog

Weekly Downloads

0

Version

0.0.3

License

none

Last publish

Collaborators

  • gpapp