Skip to main content
This section introduces how to develop and pacakge NodeJs Pulsar functions to use on StreamNative cloud. The NodeJs runtime is still in private preview stage, If you want to try it out or have any questions, please submit a ticket to the support team.

Develop

The StreamNative cloud will find the process method from the NodeJs function file, below is an example:
It can also handle Avro and Json schema record, for Avro scheme input and output:
For Json input and output:
To get more examples, please refer to examples

Feature Matrix

The NodeJs runtime doesn’t support full features comparing to Java runtime, and it’s still in developing, below is the matrix:

Input Arguments

Output Arguments

Context

Other

Package

You can either provide a single .js file or package your function into a .zip file when creating NodeJs functions. A zip file should contain:
  1. the pacakge.json file
  2. other source code file
Like:
Below is an example of the package.json:
The “main” file is required for such package.json:
The StreamNative Cloud will install dependencies specified in the package.json and handle your function.

Deploy

After creating a cluster, set up your environment and develop&package your function, you can use the snctl, pulsarctl, pulsar-admin command, the REST API, or terraform to deploy a Pulsar function to your cluster. You can create a NodeJs Pulsar function by using a local .js or .zip file or an uploaded Pulsar functions package(recommend).

(Optional) Upload your function file to Pulsar

It’s recommended to upload your function file to Pulsar before you create a function. Since you can add a version suffix to the package.
Upload packages
You should see the following output:

Create

Only Pulsar 4.0.x clusters running version 4.0.10.6 or later, or Pulsar 4.2.x clusters running version 4.2.1.4 or later, support the --sn-service-account flag.You can use --as-service-account instead of --sn-service-account if you are using other versions of Pulsar clusters.
Since Pulsar doesn’t support NodeJs runtime, we need to use --py to specify the function file and specify the --custom-runtime-options '{"genericKind": "nodejs"}' to make it work.
You should see something like this:
For details about Pulsar function configurations, see Pulsar function configurations.

What’s next?