source

package
v0.0.0-...-2c2f5ba Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package source defines the Source interface and implementations for reading records into the StreamForge processing pipeline.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultGenerator

func DefaultGenerator(seq int64) *record.Record

DefaultGenerator produces simple records with sequential keys and values.

Types

type ChannelSource

type ChannelSource struct {
	// contains filtered or unexported fields
}

ChannelSource reads records from an in-memory channel. Useful for testing.

func NewChannelSource

func NewChannelSource(ch chan *record.Record) *ChannelSource

NewChannelSource creates a source that reads from the given channel.

func (*ChannelSource) Close

func (c *ChannelSource) Close() error

Close marks the source as closed.

func (*ChannelSource) Commit

func (c *ChannelSource) Commit(_ context.Context) error

Commit is a no-op for channel sources.

func (*ChannelSource) Open

func (c *ChannelSource) Open(_ context.Context) error

Open is a no-op for channel sources.

func (*ChannelSource) Read

func (c *ChannelSource) Read(ctx context.Context) (*record.Record, error)

Read blocks until a record is available or the context is cancelled.

type GeneratorFunc

type GeneratorFunc func(seq int64) *record.Record

GeneratorFunc produces a record given a sequence number.

type GeneratorOption

type GeneratorOption func(*GeneratorSource)

GeneratorOption configures the generator source.

func WithMaxCount

func WithMaxCount(n int64) GeneratorOption

WithMaxCount sets the maximum number of records to generate. A value <= 0 means unlimited.

func WithRate

func WithRate(d time.Duration) GeneratorOption

WithRate sets the time between generated records.

type GeneratorSource

type GeneratorSource struct {
	// contains filtered or unexported fields
}

GeneratorSource produces records using a generator function at a configurable rate. Useful for benchmarks and testing.

func NewGeneratorSource

func NewGeneratorSource(fn GeneratorFunc, opts ...GeneratorOption) *GeneratorSource

NewGeneratorSource creates a source that generates records using the given function.

func (*GeneratorSource) Close

func (g *GeneratorSource) Close() error

Close is a no-op for generator sources.

func (*GeneratorSource) Commit

func (g *GeneratorSource) Commit(_ context.Context) error

Commit is a no-op for generator sources.

func (*GeneratorSource) Open

func (g *GeneratorSource) Open(_ context.Context) error

Open is a no-op for generator sources.

func (*GeneratorSource) Read

func (g *GeneratorSource) Read(ctx context.Context) (*record.Record, error)

Read generates and returns the next record.

type KafkaSource

type KafkaSource struct {
	// contains filtered or unexported fields
}

KafkaSource reads records from a Kafka topic using segmentio/kafka-go.

func NewKafkaSource

func NewKafkaSource(cfg KafkaSourceConfig) *KafkaSource

NewKafkaSource creates a new Kafka consumer source.

func (*KafkaSource) Close

func (k *KafkaSource) Close() error

Close shuts down the Kafka reader.

func (*KafkaSource) Commit

func (k *KafkaSource) Commit(ctx context.Context) error

Commit commits the current offset to Kafka.

func (*KafkaSource) Open

func (k *KafkaSource) Open(_ context.Context) error

Open creates the Kafka reader.

func (*KafkaSource) Read

func (k *KafkaSource) Read(ctx context.Context) (*record.Record, error)

Read fetches the next message from Kafka and converts it to a Record.

type KafkaSourceConfig

type KafkaSourceConfig struct {
	Brokers  []string
	Topic    string
	GroupID  string
	MaxWait  time.Duration
	MinBytes int
	MaxBytes int
}

KafkaSourceConfig holds configuration for a Kafka source.

type Source

type Source interface {
	// Open initializes the source and prepares it for reading.
	Open(ctx context.Context) error
	// Read returns the next record from the source. It blocks until a record
	// is available, the context is cancelled, or an error occurs.
	Read(ctx context.Context) (*record.Record, error)
	// Commit acknowledges that all records returned so far have been processed.
	Commit(ctx context.Context) error
	// Close releases resources held by the source.
	Close() error
}

Source is the interface for reading records into a topology.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL