chainlink-microservices v0.2.1
ChainLink - Microservices
Simplified nodejs microservices architecture. Create a registry service (Chain) and register services (Links) to build a collection of dynamic, disributed services.
Simple Flow
1) Register links with chain 2) Clients query chain for list of available links 3) Clients query links directly
+--------------+--------------+---------------------+
| | | |
| | | |
+----+-----+ +----+-----+ +----+-----+ |
| | | | | | |
| Link | | Link | | Link | |
| | | | | | |
+----+-----+ +--+-------+ +------+---+ |
^ ^ ^ |
| | | |
| | | ^
| | | +---------+-------+
| | | | |
| | | | |
| | | | |
| | | | Chain |
| | | | |
| | | | |
| | | +---------+-------+
| | | ^
+--+------------+ +-----------+---+ |
| | | | |
| | | | |
| Client 1 | | Client 2 +---------------+
| | | | |
| | | | |
+-------+-------+ +---------------+ |
| |
| |
+----------------------------------------------+Overview - Chain
Create Chain
Use chainlink.createChain() to create the chain.
let chain = chainlink.createChain(/* options */);Start Chain
Use chain.start() to start the chain. This method will initiate an http server and expose three routes POST /register, POST /unregister, GET /links.
chain.start()Stop Chain
Use chain.stop() to stop the chain. This will stop the http server and unregister all links.
chain.stop()Overview - Link
Create Link
To create a link use the constructor and pass in a port.
let link = chainlink.createLink(3000);Register Link
Use link.register to register the link and pass in details of the chain you want to register with.
link.register({
port: /* port of running chain */
hostname: /* hostname of running */
path: /* registration path */
});Add Routes
Use link.addRoute(route, action) to add a route to the link. When a request is made to the route, the action will be performed.
link.addRoute('/home', (req, res) => {
res.writeHead(200, {
'Content-Type': 'text/plain'
});
res.write('Hello, World!');
res.end()
});Stop Link
Use link.stop() to stop the running link and unregister it from the chain.
link.stop();