#stateful #sdk #apache #flink #function #effect #html

yanked statefun-sdk

A Rust SDK for the Apache Flink Stateful Functions (StateFun) project. See: https://flink.apache.org/stateful-functions.html

0.1.0 Jul 5, 2020

#19 in #flink

MIT license

36KB
601 lines

Statefun Rust SDK

An SDK for writing stateful functions in Rust. See the Apache Flink Stateful Functions website for more information about the project.

At the moment this project is very bare-bones. I'm just getting started and there's no tests yet and probably some bugs.


lib.rs:

An SDK for writing "stateful functions" in Rust. For use with Apache Flink Stateful Functions (Statefun).

Examples

The following shows how to write a simple stateful function and serve it for use in a Statefun deployment.

use protobuf::well_known_types::StringValue;

use statefun_sdk::io::kafka;
use statefun_sdk::transport::hyper::HyperHttpTransport;
use statefun_sdk::transport::Transport;
use statefun_sdk::{Address, Context, Effects, EgressIdentifier, FunctionRegistry, FunctionType};

let mut function_registry = FunctionRegistry::new();

function_registry.register_fn(
    FunctionType::new("example", "function1"),
    |context, message: StringValue| {
        let mut effects = Effects::new();

        effects.send(
            Address::new(FunctionType::new("example", "function2"), "doctor"),
            message,
        );

        effects
    },
);

let hyper_transport = HyperHttpTransport::new("0.0.0.0:5000".parse()?);
hyper_transport.run(function_registry)?;

The program creates a FunctionRegistry, which can be used to register one or more functions. Then we register a closure as a stateful function. Finally, we need to create a Transport, in this case the HyperHttpTransport to serve our stateful function.

Not that you can also use a function instead of a closure when registering functions.

Refer to the Stateful Functions documentation to learn how to use this in a deployment. Especially the modules documentation is pertinent.

Dependencies

~14MB
~229K SLoC