antenna

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2023 License: MIT Imports: 7 Imported by: 0

README

Antenna

Antenna is the implementation of the Inbox Pattern for handling messages from Kafka

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Antenna

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

Antenna is a helper for consuming Kafka messages

func NewAntenna

func NewAntenna(
	topic string,
	brokers []string,
	groupID string,
	opts ...Option,
) *Antenna

NewAntenna creates a new Antenna instance

func (*Antenna) Run

func (a *Antenna) Run() error

Run starts the antenna

func (*Antenna) Stop

func (a *Antenna) Stop()

Stop stops the antenna

type Handler

type Handler interface {
	Process(ctx context.Context, msg kafka.Message) error
}

A Handler responds to a Kafka message

type HandlerFunc

type HandlerFunc func(ctx context.Context, msg kafka.Message) error

The HandlerFunc type is an adapter to allow the use of ordinary functions as a Kafka handler. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler that calls f.

func (HandlerFunc) Process

func (f HandlerFunc) Process(ctx context.Context, msg kafka.Message) error

Process calls f(ctx, msg).

type Logger

type Logger interface {
	Printf(string, ...interface{})
}

Logger interface API for log.Logger.

type LoggerFunc

type LoggerFunc func(msg string, args ...any)

LoggerFunc is a bridge between Logger and any third party logger Usage:

l := NewLogger() // some logger
a := antenna.NewAntenna(...)
a.SetLogger(LoggerFunc(l.Infof))
a.SetErrorLogger(LoggerFunc(l.Errorf))

func (LoggerFunc) Printf

func (f LoggerFunc) Printf(msg string, args ...any)

Printf implements Logger interface.

type OffsetProvider

type OffsetProvider interface {
	GetOffset(ctx context.Context, topic string, partition int) (int64, error)
}

OffsetProvider provides offset for a topic partition

type Option

type Option func(*Antenna)

Option is a function that configures an Antenna.

func WithErrorLogger

func WithErrorLogger(logger Logger) Option

WithErrorLogger sets the error logger for the antenna.

func WithLogger

func WithLogger(logger Logger) Option

WithLogger sets the logger for the antenna.

func WithMessageHandler

func WithMessageHandler(handler Handler) Option

WithMessageHandler sets the message handler for the antenna.

func WithOffsetProvider

func WithOffsetProvider(offsetProvider OffsetProvider) Option

WithOffsetProvider sets the offset provider for the antenna.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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