npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

apache-flink-statefun

v3.3.0

Published

JavaScript SDK for Apache Flink Stateful functions

Downloads

346

Readme

Apache Flink Stateful Functions

Stateful Functions is an API that simplifies the building of distributed stateful applications with a runtime built for serverless architectures. It brings together the benefits of stateful stream processing - the processing of large datasets with low latency and bounded resource constraints - along with a runtime for modeling stateful entities that supports location transparency, concurrency, scaling, and resiliency.

It is designed to work with modern architectures, like cloud-native deployments and popular event-driven FaaS platforms like AWS Lambda and KNative, and to provide out-of-the-box consistent state and messaging while preserving the serverless experience and elasticity of these platforms.

Stateful Functions is developed under the umbrella of Apache Flink.

This README is meant as a brief walkthrough on the StateFun JavaScript SDK for NodeJS and how to set things up to get yourself started with Stateful Functions in JavaScript.

For a fully detailed documentation, please visit the official docs.

For code examples, please take a look at the examples.

Table of Contents

JavaScript SDK for NodeJS Overview

Background

The JVM-based Stateful Functions implementation has a RequestReply extension (a protocol and an implementation) that allows calling into any HTTP endpoint that implements that protocol. Although it is possible to implement this protocol independently, this is a minimal library for the JavaScript programing language that:

  • Allows users to define and declare their functions in a convenient way.

  • Dispatches an invocation request sent from the JVM to the appropriate function previously declared.

A Mini-Tutorial

Define and Declare a Function

const {Context, Message, StateFun} = require("apache-flink-statefun");

let statefun = new StateFun();
statefun.bind({
	typename: "example/greeter",
	fn(context, message) {
    console.log("Hey %s!", message.asString())
  }
});

This code declares a function with of type example/greeter and binds it to the instance.

Registering and accessing persisted state

You can register persistent state that will be managed by the Stateful Functions workers for state consistency and fault-tolerance. Values can be generally obtained via the context parameter:

const {Context, Message, StateFun} = require("apache-flink-statefun");

let statefun = new StateFun();
statefun.bind({
    typename: "example/greeter",
    fn(context, message) {
        const name = message.asString();
        let seen = context.storage.seen || 0;
        seen = seen + 1;
        context.storage.seen = seen;

        console.log("Hello %s for the %dth time!", name, seen);
    },
    specs: [{
        name: "seen",
        type: StateFun.intType(),
    }]
});

Exposing the Request Reply Handler

const http = require("http");
const {Context, Message, StateFun} = require("apache-flink-statefun");

let statefun = new StateFun();
//...

http.createServer(statefun.handler()).listen(8000);

This creates an HTTP server that accepts requests from the Stateful Functions cluster and dispatches it to the handler.

Composing the Module YAML File

The remaining step would be to declare this function type in a module.yaml

functions:
  - function:
    meta:
      kind: http
      type: demo/greeter
    spec:
      endpoint: http://<end point url>/statefun

Contributing

There are multiple ways to enhance the Stateful Functions API for different types of applications; the runtime and operations will also evolve with the developments in Apache Flink.

You can learn more about how to contribute in the Apache Flink website. For code contributions, please read carefully the Contributing Code section and check the Stateful Functions component in Jira for an overview of ongoing community work.

License

The code in this repository is licensed under the Apache Software License 2.