State Example
This tutorial is for using states. We will use states in this example to write a simple dataflow that counts the number of entries sent to a topic. The following page contains an indepth explanation about states.
Prerequisites
This guide uses local
Fluvio cluster. If you need to install it, please follow the instructions at here.
Dataflow
Overview
We will define a service that contains a state which counts how much entries have entered the source.

Service With State
In this section we will show how to write a dataflow with a primitive state. The service needs to include a state
and a partition
. Inside the state, we will define a key-value pair. For our case, we are only using a primitive key-value pair(String -> u32
). Inside the partition
, we will define an assign-key
and update-state
. The function in assign-key
will take the input from the source and map it to a key. The function in update-state
will define the logic how the state is updated.
count-service:
sources:
- type: topic
id: sentences
states:
(...)
partition:
assign-key:
(...)
update-state:
(...)
1. State definition
For our example, we defined a simple key-value pair.
states:
counter:
type: keyed-state
properties:
key:
type: string
value:
type: u32