Détail du package

ipc-network

ulwanski33GPL-3.01.0.5

Inter-process communication network, allows multiple node process to exchange messages using unix-socket.

ipc, rpc, jobs, sock

readme

ipc-network

Inter-process communication network, allows multiple node process to exchange messages using fast datagram unix-socket. Also support RPC request (command is send to another process, and response is returned as a Promise, resolved when response arrives).

Installation

npm i ipc-network --save

Examples

Start listening for messages

import {IpcNetwork, Message} from "ipc-network";

const ipc = new IpcNetwork('process-A');

ipc.on('error', (error: Error) => {
    console.log(error.message);
});

ipc.on('message', (data: Message) => {
    console.log(`New message from ${data.from}: ${data.message.toString()}`);
});

ipc.startListening();

Sending messages

import {IpcNetwork} from "ipc-network";

const ipc = new IpcNetwork('process-A');

ipc.on('error', (error: Error) => {
    console.log(error.message);
});

ipc.send('example content', 'process-B');

Sending RPC (requesting job)

import {IpcNetwork} from "ipc-network";

const ipc = new IpcNetwork('process-A');

ipc.on('error', (error: Error) => {
    console.log(error.message);
});

ipc.sendRpc('example-job', 'process-B', 500).then((result: Buffer) => {
    console.log(`Received job data: ${result.toString()}`);
}).catch((error: Error) => {
    console.log(error.message);
});

Receiving job

import {IpcNetwork} from "ipc-network";

const ipc = new IpcNetwork('process-B', (jobName: string, from: string) => {
    console.log(`Received new job "${jobName}" from: ${from}`);

    return Buffer.from('example jpb results!');
});

ipc.on('error', (error: Error) => {
    console.log(error.message);
});

ipc.startListening();

Additional information

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

GPL-3.0

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

Unreleased

[1.0.5] - 2019-03-22

  • Added unique id buffer, for rpc jobs

[1.0.4] - 2019-03-20

  • Removed tslib dependency from package.json
  • Added RPC examples in readme

[1.0.3] - 2019-03-20

Changed

  • Fixed example code in readme

[1.0.2] - 2019-03-20

Changed

  • Improvements in TypeScript configuration

[1.0.1] - 2019-03-20

Changed

  • Rearranged directory structure
  • Added TypeScript declaration re-export

[1.0.0] - 2019-03-19

Added

  • Init commit