1. Process Data Streams
  2. Generic Runtime(Alpha)

Develop&Deploy NodeJs Function

The following example shows how to create a NodeJs kind generic runtime function on Streamnative Cloud using different tools.

Below is an example of the NodeJs function, you can find more examples in here:

async function process(message, context) {
    const logger = context.getLogger();
    for (let word of message.split(" ")) {
        await context.incrementCounter(word, 1)
        let count = await context.getCounter(word)
        logger.info(`got word: ${word} for ${count['value']} times`)
    }
    await context.publish("persistent://public/default/test-node-package-serde-extra", message.concat("!!!"))
    return message.concat("!");
}

Upload your function file to Pulsar

Please refer to: Upload Function Package

Create a NodeJs kind generic runtime Pulsar function

pulsarctl functions create \
--tenant public \
--namespace default \
--name function1 \
--inputs persistent://public/default/test-nodejs-input \
--output persistent://public/default/test-nodejs-output \
--classname exclamation \
--py function://public/default/[email protected]
--custom-runtime-options '{"genericKind": "nodejs"}'

You should see something like this:

Created function1 successfully

For details about Pulsar function configurations, see Pulsar function configurations.

What’s next?

Previous
Overview