Stateful Interprocess communication for Node.js
I may be missing an obvious trick here but...
Is there anyway for 2+ node.js processes to exchange messages in a stateful fashion? As an example: process A is an HTTP server that fields incoming external http requests, to fulfil these requests it needs to get information from either process B or C. Currently I have 'A' opening a TCP/IP connection for each request to 'B' or 'C' which are listening on a suitable port.
This seems completely sucky and alot of overhead as each request requires lots of overhead to open a socket and close it, yet without opening a socket per request I cannot see a way to make sure that a response from the either 'B' or 'C' are bound to the correct HTTP response.
All processes are in Nodejs, B + C have a long startup time (30+ seconds) so spawning them per request isn't an option. All processes are currently running on the same box (dual core).
In terms of protocol all I'm using is basic 'net' server as described in the nodejs docs and throwing text across it.
Any suggestions etc gladly accepted
You could choose to pass a unique session ID (app server/self generated) as part of your messages (between processes A B/C) & perhaps append a counter to the session ID (with a delimiter between the session ID and the counter) to keep track of requests. The counter would increment on each new request. I am sure there may be better/simpler options that you could avail.
Hope it helps.