statefun-0.1.0 has been yanked.
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::io::kafka;
use statefun::transport::hyper::HyperHttpTransport;
use statefun::transport::Transport;
use statefun::{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)?;
# Ok::<(), failure::Error>(())
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.