iceoryx-nodejs-extended

0.0.4 • Public • Published

iceoryx-nodejs

this is bindning of iceoryx library for nodejs

Usage

There must be iceoryx installed in your system follow instructions

# Those variables are used to build addon, will find later way how to ged rid of this
export ICEORYX_NODEJS_LIB=/usr/local/lib
export ICEORYX_NODEJS_INCLUDE=/usr/local/include/iceoryx/<VERSION>
npm install iceoryx-nodejs

Environment

  • There is only linux environment tested right now

Example request/response

Client

const iceoryx = require('iceoryx-nodejs-extended')

iceoryx.setIoxProcessName("client_test");

const client = new iceoryx.IceoryxClient();

let resp = client.sendMessage("{koko : 10}");
console.log("got some resp:" + resp)

Server

const iceoryx = require('iceoryx-nodejs-extended')

iceoryx.setIoxProcessName("server_test");

const server = new iceoryx.IceoryxServer();
server.listen();

Example subsriber/publisher

const iceoryx = require('iceoryx-nodejs-extended')

// There must be name of iox process
// Second param - if "publisher" then application will push some JSON
const appArgs = process.argv.slice(2);

// Unique name of iox process
iceoryx.setIoxProcessName(appArgs[0]);

// Callback for subscriber
const canTopicCallback = (data, data2) => {
    console.log(data.data.toString());
}

if(appArgs[1] === "subscriber") {
    const service = new iceoryx.IceoryxSubscriber(["Test-app", "Test-group", "topic"], canTopicCallback);
    // Little hack by holding reference like that if not Garbage collector will destroy object
    process.on("exit", () => {
        console.log(service);
    })
} else {
    const publisher = new iceoryx.IceoryxPublisher(["Test-app", "Test-group", "topic"], canTopicCallback);
    let iteration = 0;
    setInterval(() => {
        // Sample JSON data
        const obj = {
            message: "Hello from the nodejs thru iceoryx",
            iteration
        }
        const str = JSON.stringify(obj);
        publisher.loan(str.length)
            .then((data) => {
                // We must fill data into received buffer
                data.fill(str);
                iteration++;
                // This can't be called without data received by function getLoanBuffer
                // There is buffer which has memory address from iox shared memory
                // Multiple call of loan without pusblish will lead to not getting buffer
                publisher.publish(data);
            })
            .catch(err => console.log(err))
    }, 100);
}

const BlockThread = async () => {
    while(1) {
        await new Promise(resolve => setTimeout(resolve, 5000));
    }   
}

BlockThread();

Running example

# first console (of course iox-roudi must running)
node iceoryx.js process_sub subscriber

# second console
node iceoryx.js process_pub publisher

Readme

Keywords

Package Sidebar

Install

npm i iceoryx-nodejs-extended

Weekly Downloads

3

Version

0.0.4

License

ISC

Unpacked Size

25.3 kB

Total Files

18

Last publish

Collaborators

  • ashwalh