kafka

package module
v0.0.0-...-085cedf Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

README

Sarama kafka worker library

Usage

Please checkout example code

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSkipMarkOffset = errors.New("skip mark offset")
)

Functions

This section is empty.

Types

type Handler

type Handler func(context.Context, *sarama.ConsumerMessage) error

Handler handles kafka message.

To stop consuming, return error except ErrSkipMarkOffset. Return ErrSkipMarkOffset to skip mark commit offset.

type Option

type Option func(*options)

func WithCleanupCallback

func WithCleanupCallback(onCleanup func(sarama.ConsumerGroupSession) error) Option

func WithSetupCallback

func WithSetupCallback(onSetup func(sarama.ConsumerGroupSession) error) Option

type Worker

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

func NewKafkaWorker

func NewKafkaWorker(cg sarama.ConsumerGroup, opts ...Option) *Worker

func (*Worker) GracefulStop

func (w *Worker) GracefulStop()

func (*Worker) RegisterHandler

func (w *Worker) RegisterHandler(topic string, handler Handler)

func (*Worker) Start

func (w *Worker) Start() error

func (*Worker) StartContext

func (w *Worker) StartContext(ctx context.Context) error

func (*Worker) Use

func (w *Worker) Use(middlewares ...func(Handler) Handler)

type WorkerIface

type WorkerIface interface {
	Use(middlewares ...func(Handler) Handler)
	RegisterHandler(topic string, handler Handler)
	Start() error
	StartContext(ctx context.Context) error
	GracefulStop()
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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