简体   繁体   中英

Communication between Node.js microservices

I'm creating an application with Node.js using microservices architecture. I'm trying to find the best way of communication between nodes. I have a Java background so the best option I can imagine is something like SOAP, where you create a proxy object and by calling it's method a request to a remote node would be made via http.

Currently I only see an option of direct calls like

http.get("remote-node/api/method1", function(res) {
}).on('error', function(e) {
  console.log("Got error: " + e.message);
});

However I don't think it's convenient. Are there better approaches?

Thanks.

The most common and simple approach is to communicate your microservices using a REST-ish approach, you will have to manually the communication and the discovery of services, which can become messy as the system grows. You can also search for some packages on npm for service discovery and remote procedure call.

I strongly suggest the usage of Studio which is a micro services framework. It also have a plugin to do automatic clusterization (service discovery + rpc) with really minimal configuration, this plugin also uses websocket for communication which is more light weight then rest-ish approach

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM