Stateful Interprocess for Node.js

I may miss the obvious trick here, but ...

Is there anyway for 2+ processes node.js for stateful messaging? As an example: process A is an HTTP server that portes incoming external HTTP requests, to fulfill these requests it needs to get information from process B or C. Currently I have an “A” that opens a TCP / IP connection for each request for 'B' or 'C' that are listening on a suitable port.

This seems completely juicy and a lot of overhead, since each request requires a lot of overhead to open the socket and close it, but without opening the socket on the request, I see no way to make sure that the response from “B” or “C” is associated with correct HTTP response.

All processes are in nodes, B + C have a long start time (30 + seconds), so their spawning at the request is not an option. All processes currently operate in the same field (dual core).
In terms of the protocol, all I use is the base net 'server, as described in nodejs docs, and throwing text through it.

Any suggestions, etc. gladly accepted

+4
source share
1 answer

You can select a unique session identifier (application server / self-generated) as part of your messages (between processes A ↔ B / C) and optionally add a session identifier counter (delimited between session identifier and counter) to track requests. The counter will increment every new request. I am sure there may be better / simpler options that you could use.

To transfer messages between processes, you can look at caches in memory (for example, redis / memcached, etc.) or use messaging servers such as ZermoMQ / RabbitMQ, etc. (you can use Redis to queue / pub-sub messaging). You can also opt out of messaging servers and just use hook.io or net / tcp in node to send messages.

Hope this helps.

+2
source

Source: https://habr.com/ru/post/1401258/


All Articles