Krishanu Dey
Krishanu Dey

Reputation: 6406

Passing messages between two processes

I'm building a system that has 2 processes.

Process 1
This process is actually a Node.js program. This process is actually a Web Server handling the incoming request.

Process 2
This process is actually a C++ program.

Both the processes are started automatically at startup with help of rc.local

Now, for Process 1 there are some specific request that should be passed to Process 2.

For example, if Process 1 receives a post request at route /enqueue with a JSON body payload, Process 1 should stringify the JSON and pass to Process 2.

When Process 2 receives the JSON, it should kill a worker thread and start a new thread with that JSON to perform the actual task. The worker thread should be killed irrespective of whether the worker thread is still processing previous JSON

If both the processes were Node.js application, I could have forked Process 2 from Process 1 and used the following code.

process.on('message',function(message){
    //implementation
}
...
process.send(data);

But my second process is a C++ app.

Any idea on how to implement it?

Note: Before flagging this question, please keep in mind I'm not looking for a full code. I just need the idea on how to do it.

Upvotes: 0

Views: 513

Answers (1)

Rob Raisch
Rob Raisch

Reputation: 17367

You cannot use the Nodejs messaging/eventing facility for this purpose as it is specific to Node.

You will need to use the communications facilities of your operating system such as Unix, TCP, UDP sockets or an eventing system that both processes can communicate with, like Redis or ZeroMQ.

Upvotes: 1

Related Questions