Microservices Layer
EARLY ALPHA, DON'T USE IT IN PRODUCTION!
A wrapper for microservices strategies, based on Pigato (ZeroMQ) with an optional network abstraction for Docker Links.
Also provides Pub/Sub functionalities .
Install
npm install --save microservices-layer
How to use
Client
Localhost
var port = 1234;var host = 'localhost'; var MsLayer = ;MicroServices = port host; MicroServices;
Between Docker Containers
Since 1.0.6 you can abstract your network between Docker containers using Docker Links. Just use the same string for your service name and your service's Docker container/link (In the service).
var port = 1234; var MsLayer = ;MicroServices = port null docker:true; MicroServices;
Client is lazy, it means that the tcp connection with zmq will be only open the first time the service is called and, as the connection is based on the service name, you don't need any additional configuration besides the Docker Links. Just request the service by its name, enywhere in your code.
Service
The service will not change its configuration, it will be the same for localhost or Docker environments. Just use the right service name.
var MsLayer = ; var serviceName = 'someservice'; // the service identifier string. DON'T use hifens or underscores in the name.var serviceConfigs = port: 1234;var { // some logic maybe... }; var service = serviceName serviceGateway serviceConfigs;
Pub/Sub
Since 0.1.2 you can use Pub/Sub directly with this module and with a very simple syntax.
Publisher
var MsLayer = ; var Publisher = 3002; // then, somewhere in your code...Publisher;
Subscriber
var MsLayer = ; Subscriber = 3002; // subscription is automatic, just set your callbackSubscriber;