Documentation
¶
Index ¶
- type CheckpointInfo
- type OperatorInfo
- type PipelineInfo
- type Stream
- func (s *Stream) Filter(fn func(types.Record) bool, label ...string) *Stream
- func (s *Stream) FlatMap(fn func(types.Record) []types.Record, label ...string) *Stream
- func (s *Stream) KeyBy(fn func(types.Record) []byte, label ...string) *Stream
- func (s *Stream) Map(fn func(types.Record) types.Record, label ...string) *Stream
- func (s *Stream) Reduce(fn operator.ReduceFn, label ...string) *Stream
- func (st *Stream) ToSink(sk sink.Sink) *StreamExecutionEnv
- func (s *Stream) Window(assigner window.WindowAssigner, label ...string) *Stream
- func (s *Stream) WindowWithIdleTimeout(assigner window.WindowAssigner, idleTimeout time.Duration, label ...string) *Stream
- type StreamExecutionEnv
- func (env *StreamExecutionEnv) Describe() PipelineInfo
- func (env *StreamExecutionEnv) DescribeJSON() string
- func (env *StreamExecutionEnv) Execute(ctx context.Context) error
- func (env *StreamExecutionEnv) FromSource(src source.Source) *Stream
- func (env *StreamExecutionEnv) WithCheckpointing(interval time.Duration, storage checkpoint.Storage) *StreamExecutionEnv
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CheckpointInfo ¶
CheckpointInfo describes the checkpointing configuration.
type OperatorInfo ¶
type OperatorInfo struct {
Type string `json:"type"`
Label string `json:"label,omitempty"`
Config map[string]string `json:"config,omitempty"`
}
OperatorInfo describes a single operator in the pipeline chain.
type PipelineInfo ¶
type PipelineInfo struct {
Source source.SourceInfo `json:"source"`
Operators []OperatorInfo `json:"operators"`
Sink sink.SinkInfo `json:"sink"`
Checkpoint *CheckpointInfo `json:"checkpoint,omitempty"`
}
PipelineInfo is the JSON-serializable description of a pipeline. It is returned by Describe() and consumed by the dashboard.
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
Stream represents a pipeline stage. Method calls on Stream append operators to the chain and return the updated Stream.
Streams are built using a fluent API:
env.FromSource(src).Map(fn).Filter(fn).ToSink(s)
The pipeline is lazy — nothing runs until env.Execute() is called.
func (*Stream) Filter ¶
Filter keeps only records where fn returns true. The optional label is shown in the dashboard.
func (*Stream) FlatMap ¶
FlatMap applies a 1:many transformation to each record. The function returns a slice; if empty, the record is dropped. The optional label is shown in the dashboard.
func (*Stream) KeyBy ¶
KeyBy partitions the stream by the given key selector function. All records with the same key are routed together. Required before stateful operations like Reduce. The optional label is shown in the dashboard.
func (*Stream) Map ¶
Map applies a 1:1 transformation to each record in the stream. If the function returns the zero value of Record, the record is dropped. The optional label is shown in the dashboard.
func (*Stream) Reduce ¶
Reduce applies a stateful aggregation per key. Must be used after KeyBy. The reduce function is called with the current accumulator (nil on first call) and the incoming record, and returns the new accumulator. The updated accumulator is emitted downstream after every record.
Example (count per key):
stream.KeyBy(func(r types.Record) []byte { return r.Key }).
Reduce(func(accum []byte, curr types.Record) []byte {
count := 0
if accum != nil {
count = int(binary.BigEndian.Uint64(accum))
}
count++
buf := make([]byte, 8)
binary.BigEndian.PutUint64(buf, uint64(count))
return buf
})
func (*Stream) ToSink ¶
func (st *Stream) ToSink(sk sink.Sink) *StreamExecutionEnv
ToSink connects the stream to a sink and returns the execution environment. The pipeline is still lazy — call env.Execute() to start processing.
func (*Stream) Window ¶
func (s *Stream) Window(assigner window.WindowAssigner, label ...string) *Stream
Window groups records into time-based windows. Must be used after KeyBy. Records are buffered into windows, and when a watermark passes a window's end time, the window fires — all its records are emitted as a single result.
Supported window types:
- window.Tumbling(size): fixed-size, non-overlapping (e.g. 5-minute buckets)
- window.Sliding(size, slide): overlapping windows (e.g. 5-min every 1-min)
- window.Session(gap): variable-size, closes after inactivity gap
Example (5-minute tumbling window):
stream.KeyBy(func(r types.Record) []byte { return r.Key }).
Window(window.Tumbling(5 * time.Minute)).
Reduce(aggregateFn)
func (*Stream) WindowWithIdleTimeout ¶
func (s *Stream) WindowWithIdleTimeout(assigner window.WindowAssigner, idleTimeout time.Duration, label ...string) *Stream
WindowWithIdleTimeout creates a window with an idle timeout. If no records arrive within the timeout duration, all remaining windows are fired and the pipeline stage completes. Useful for infinite streams that don't receive shutdown signals.
type StreamExecutionEnv ¶
type StreamExecutionEnv struct {
// contains filtered or unexported fields
}
StreamExecutionEnv is the entry point for building and running stream pipelines. Create one with NewEnv(), define your pipeline using FromSource/ToSink, then call Execute() to run it.
env := mailer.NewEnv() env.FromSource(src).Map(fn).Filter(fn).ToSink(stdout) env.Execute(ctx)
func (*StreamExecutionEnv) Describe ¶
func (env *StreamExecutionEnv) Describe() PipelineInfo
Describe returns a serializable description of the pipeline: source, operator chain, sink, and checkpoint config. Call this before Execute() to get the pipeline graph for the dashboard.
func (*StreamExecutionEnv) DescribeJSON ¶
func (env *StreamExecutionEnv) DescribeJSON() string
DescribeJSON returns the pipeline description as indented JSON.
func (*StreamExecutionEnv) Execute ¶
func (env *StreamExecutionEnv) Execute(ctx context.Context) error
Execute runs the pipeline. It starts the source, wires up all operators as goroutines connected by channels, and connects the final output to the sink. Blocks until the source is exhausted or the context is cancelled.
If checkpointing is enabled, the pipeline will attempt to restore from the latest checkpoint before starting. A goroutine injects checkpoint barriers at the configured interval. When a barrier completes the full pipeline round-trip, operator state is saved to the checkpoint storage.
func (*StreamExecutionEnv) FromSource ¶
func (env *StreamExecutionEnv) FromSource(src source.Source) *Stream
FromSource sets the data source for the pipeline and returns a Stream that you can chain operators on.
func (*StreamExecutionEnv) WithCheckpointing ¶
func (env *StreamExecutionEnv) WithCheckpointing(interval time.Duration, storage checkpoint.Storage) *StreamExecutionEnv
WithCheckpointing enables periodic checkpointing with the given interval and storage backend. Barriers are injected into the stream at the specified interval; when a barrier passes through all operators and reaches the sink, the checkpoint is complete.
On recovery, Execute() will load the latest checkpoint, restore all stateful operators, and resume from the saved source offset.
Example:
env := mailer.NewEnv()
env.WithCheckpointing(30*time.Second, checkpoint.NewFileStorage("/tmp/checkpoints"))
Directories
¶
| Path | Synopsis |
|---|---|
|
control
module
|
|
|
examples
|
|
|
dashboard-demo
command
|
|
|
kafka-dashboard
command
|
|
|
kafka-orders
command
|
|
|
pg-orders
command
|
|
|
windowing
command
|
|
|
wordcount
command
|
|
|
Package state provides keyed state storage for stateful stream processing.
|
Package state provides keyed state storage for stateful stream processing. |
|
Package watermark provides watermark generation for event-time processing.
|
Package watermark provides watermark generation for event-time processing. |
|
Package window provides window assigners for grouping unbounded streams into finite chunks based on time.
|
Package window provides window assigners for grouping unbounded streams into finite chunks based on time. |