I have three (nodejs) processes P1, P2, P3.
Function A of P1 completes its execution it sends some data to P2.
P2 performs its activities and its output should be sent to P3.
P3 works on the input sends some acknowledgement data to Function B of P1.
All three are different node js applications and runs on different servers (in the same LAN). The question is what should be the communication mechanism between these processes.
Three options appears to be viable:
1) REST API (Express)
Let all the processes be Express REST APIs and using the http
node js package call the required functions
2) Pub/Sub
When P1 completes the work, it post the output as a message to a topic and P2 becomes a subscriber and onMessage
P2 process executes.
3) TCP/IP
A simple TCP/IP server-client architecture where P1 becomes the server client and P2 as server. Whenever P1 completes the work send the output through sockets.
All three options are for used for many to one or many to many communication so I guess there could be a lot of unnecessary overhead as my requirement has only one to one communication between the processes.
Is there any other method that i can use or one of these best suits is the dilemma.
Please suggest.
Thanks.
To address these issues, Node. JS uses a single thread with an event-loop. In this way, Node can handle 1000s of concurrent connections without any of the traditional detriments associated with threads. There is essentially no memory overhead per-connection, and there is no context switching.
Other reasons why we cannot use node modules at the client side is that the node uses the CommonJS module system while the browser uses standard ES Modules which has different syntax.
Cross-platform development js allows you to build cross-platform desktop apps on platforms like NW. js or Electron. This allows you to reuse some of the codes from the web app to the desktop version for Windows, macOS, and Linux.
You can work with mqtt protocol. This is a very light weight and fast protocol. In this protocol you will get a publisher, a subscriber and a broker. Publisher will send data to subscriber under a topic via mqtt broker. It is almost same as Pub/Sub.
MQTT Architecture
MQTT
Note : Function A of P1 will publish data and P2 will subscribe. After P2 completes its activities it will publish data to P3 and P3 will be in subscribing mode. After that P3 will publish acknowledgement and Function B of P1 will subscribe the topic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With