Documentation
¶
Index ¶
- type BatchHandlerFunc
- type BatchTxHandlerFunc
- type Client
- func (c *Client) HandleFetches(ctx context.Context) error
- func (c *Client) Ping(ctx context.Context) error
- func (c *Client) Produce(ctx context.Context, record *kgo.Record, promise PromiseFunc)
- func (c *Client) ProduceSync(ctx context.Context, records ...*kgo.Record) error
- func (c *Client) RunInTx(ctx context.Context, fn TxFunc) (err error)
- func (c *Client) Shutdown(ctx context.Context) error
- func (c *Client) TryProduce(ctx context.Context, record *kgo.Record, promise PromiseFunc)
- type Config
- type ConsumerOpt
- func WithConsumeResetOffset(offset kgo.Offset) ConsumerOpt
- func WithConsumerBatchHandler(handler BatchHandlerFunc) ConsumerOpt
- func WithFetchIsolationLevel(level kgo.IsolationLevel) ConsumerOpt
- func WithGroupTransactSessionBatchHandler(handler BatchTxHandlerFunc) ConsumerOpt
- func WithShareGroupBatchHandler(handler BatchHandlerFunc) ConsumerOpt
- type GroupOpt
- type GroupTransactSession
- func (g *GroupTransactSession) HandleFetches(ctx context.Context) error
- func (g *GroupTransactSession) Ping(ctx context.Context) error
- func (g *GroupTransactSession) Produce(ctx context.Context, record *kgo.Record, promise PromiseFunc)
- func (g *GroupTransactSession) ProduceSync(ctx context.Context, records ...*kgo.Record) error
- func (g *GroupTransactSession) Shutdown(_ context.Context) error
- func (g *GroupTransactSession) TryProduce(ctx context.Context, record *kgo.Record, promise PromiseFunc)
- type Opt
- func WithClientID(s string) Opt
- func WithConfig(config *Config) Opt
- func WithLogger(logger kgo.Logger) Opt
- func WithMeterProvider(provider metric.MeterProvider) Opt
- func WithMetricLabel(key, value string) Opt
- func WithMetricsNamespace(namespace string) Opt
- func WithTLS(tlsConfig *tls.Config) Opt
- func WithTracerPropagator(propagator propagation.TextMapPropagator) Opt
- func WithTracerProvider(provider trace.TracerProvider) Opt
- type ProducerOpt
- func WithAllowIdempotentProduceCancellation() ProducerOpt
- func WithProducePromise(promiseFunc PromiseFunc) ProducerOpt
- func WithProducerBatchCompression(preference ...kgo.CompressionCodec) ProducerOpt
- func WithProducerBatchMaxBytesFn(fn func(topic string) int32) ProducerOpt
- func WithRecordPartitioner(partitioner kgo.Partitioner) ProducerOpt
- func WithRequiredAcks(acks kgo.Acks) ProducerOpt
- type PromiseFunc
- type Tx
- type TxFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BatchHandlerFunc ¶
BatchHandlerFunc handles a batch of consumed Kafka records.
type BatchTxHandlerFunc ¶ added in v0.3.1
BatchTxHandlerFunc handles a batch of consumed Kafka records inside a group transaction.
type Client ¶ added in v0.3.1
type Client struct {
// contains filtered or unexported fields
}
Client provides Kafka produce and consume operations.
func (*Client) HandleFetches ¶ added in v0.3.1
func (*Client) ProduceSync ¶ added in v0.3.1
func (*Client) RunInTx ¶ added in v0.3.1
RunInTx executes fn inside a Kafka transaction.
The transaction is committed when fn returns nil. It is aborted when fn returns an error. Panics are recovered only long enough to abort the transaction, then re-thrown.
func (*Client) Shutdown ¶ added in v0.3.1
Shutdown stops polling, flushes pending records and acks, and closes the underlying client.
func (*Client) TryProduce ¶ added in v0.3.1
type Config ¶ added in v0.3.1
type Config struct {
// Brokers sets the seed brokers for the client to use.
//
// Any seed without a port uses the default Kafka port 9092.
Brokers string
// SASLMechanism is the SASL mechanism used for authentication.
// Supported values: PLAIN, SCRAM-SHA-256, SCRAM-SHA-512.
SASLMechanism string
// User is the SASL username.
User string
// Password is the SASL password.
Password string
// RequestTimeoutOverhead adds extra time while setting request deadlines.
RequestTimeoutOverhead time.Duration
// ConnIdleTimeout controls how long idle broker connections are kept open.
ConnIdleTimeout time.Duration
// DialTimeout sets the timeout for opening broker connections.
DialTimeout time.Duration
// RequestRetries sets how many times retryable requests may be retried.
RequestRetries *int
// RetryTimeout limits the total time allowed for retrying a request.
RetryTimeout time.Duration
// BrokerMaxWriteBytes limits how many bytes may be written to a broker in one write.
BrokerMaxWriteBytes *int32
// BrokerMaxReadBytes limits the maximum response size read from a broker.
BrokerMaxReadBytes *int32
// MetadataMaxAge sets the maximum age of cached Kafka metadata.
MetadataMaxAge time.Duration
// MetadataMinAge sets the minimum time between metadata refreshes.
MetadataMinAge time.Duration
// AlwaysRetryEOF retries EOF errors instead of treating them as terminal connection failures.
AlwaysRetryEOF bool
// DefaultProduceTopic sets the default topic for records without an explicit topic.
DefaultProduceTopic string
// ProducerBatchMaxBytes limits the maximum size of a produced record batch.
ProducerBatchMaxBytes int32
// MaxBufferedRecords limits how many records the producer may buffer.
MaxBufferedRecords int
// MaxBufferedBytes limits how many bytes the producer may buffer.
MaxBufferedBytes int
// ProduceRequestTimeout limits how long brokers may take to respond to produce requests.
ProduceRequestTimeout time.Duration
// RecordRetries sets how many times producing records may be retried.
RecordRetries int
// ProducerLinger sets how long records may wait for batching before a produce request is built.
ProducerLinger *time.Duration
// RecordDeliveryTimeout limits how long a record may remain buffered before timing out.
RecordDeliveryTimeout time.Duration
// TransactionalID identifies the transactional producer.
//
// It is used by producer transactions and group transact sessions.
TransactionalID string
// TransactionTimeout limits how long a Kafka transaction may remain open.
TransactionTimeout time.Duration
// ConsumeRegex treats configured topics as regular expressions.
ConsumeRegex bool
// Topics contains Kafka topics consumed by the consumer or group transact session.
Topics string
// MaxPollRecords limits how many records are handled in one poll iteration.
MaxPollRecords int
// FetchMaxWait limits how long a broker may wait before returning a fetch response.
FetchMaxWait time.Duration
// FetchMaxBytes limits the maximum bytes returned in one fetch response.
FetchMaxBytes int32
// FetchMinBytes sets the minimum bytes a broker tries to return in one fetch response.
FetchMinBytes int32
// FetchMaxPartitionBytes limits how many bytes may be fetched from one partition.
FetchMaxPartitionBytes int32
// DisableFetchSessions disables Kafka fetch sessions.
DisableFetchSessions bool
// Rack identifies the client rack for rack-aware fetching and consumer assignment.
Rack string
// MaxConcurrentFetches limits how many fetch requests may be in flight or buffered at once.
//
// It can be used together with FetchMaxBytes to bound consumer memory usage.
MaxConcurrentFetches *int
// Group identifies the Kafka consumer group.
Group string
// InstanceID sets a static consumer group member ID.
InstanceID string
// SessionTimeout controls how long a group member may go without heartbeating.
SessionTimeout time.Duration
// RebalanceTimeout controls how long group members may take during a rebalance.
RebalanceTimeout time.Duration
// HeartbeatInterval controls how often a group member sends heartbeats.
HeartbeatInterval time.Duration
//
// If set, share group consuming is used instead of a regular consumer group.
ShareGroup string
//
// If zero, the franz-go default is used.
ShareMaxRecords int32
ShareMaxRecordsStrict bool
//
// If zero, failed records are released for redelivery.
ShareRejectAfterDeliveries int32
//
// If zero, failed records are released immediately.
ShareReleaseTimeout time.Duration
// Enabled enables this Kafka component.
Enabled bool
// SkipFatalErrors allows the consumer to continue after non-retriable fetch errors.
SkipFatalErrors bool
// PollInterval sets the interval between consumer poll iterations.
PollInterval time.Duration
// SuspendProcessingTimeout sets the wait time after handler errors.
SuspendProcessingTimeout time.Duration
// SuspendCommittingTimeout sets the wait time after offset commit or ack errors.
SuspendCommittingTimeout time.Duration
}
type ConsumerOpt ¶ added in v0.3.1
type ConsumerOpt interface {
Opt
// contains filtered or unexported methods
}
ConsumerOpt is a consumer-specific option to configure a client.
This is simply a namespaced Opt.
func WithConsumeResetOffset ¶
func WithConsumeResetOffset(offset kgo.Offset) ConsumerOpt
func WithConsumerBatchHandler ¶
func WithConsumerBatchHandler(handler BatchHandlerFunc) ConsumerOpt
func WithFetchIsolationLevel ¶
func WithFetchIsolationLevel(level kgo.IsolationLevel) ConsumerOpt
func WithGroupTransactSessionBatchHandler ¶ added in v0.3.1
func WithGroupTransactSessionBatchHandler(handler BatchTxHandlerFunc) ConsumerOpt
func WithShareGroupBatchHandler ¶ added in v0.4.2
func WithShareGroupBatchHandler(handler BatchHandlerFunc) ConsumerOpt
type GroupOpt ¶ added in v0.3.1
type GroupOpt interface {
Opt
// contains filtered or unexported methods
}
GroupOpt is a consumer group-specific option to configure a client.
This is simply a namespaced Opt.
func WithBalancers ¶ added in v0.3.1
func WithBalancers(balancers ...kgo.GroupBalancer) GroupOpt
func WithShareAckCallback ¶ added in v0.3.1
func WithShareAckCallback(fn func(*kgo.Client, kgo.ShareAckResults)) GroupOpt
type GroupTransactSession ¶ added in v0.3.1
type GroupTransactSession struct {
// contains filtered or unexported fields
}
GroupTransactSession consumes records and produces records in the same Kafka transaction.
It is intended for Kafka-to-Kafka consume-process-produce flows where consumed offsets and produced records must be committed atomically.
func NewGroupTransactSession ¶ added in v0.3.1
func NewGroupTransactSession(opts ...Opt) (*GroupTransactSession, error)
NewGroupTransactSession creates a Kafka group transaction session.
func (*GroupTransactSession) HandleFetches ¶ added in v0.3.1
func (g *GroupTransactSession) HandleFetches(ctx context.Context) error
func (*GroupTransactSession) Ping ¶ added in v0.4.4
func (g *GroupTransactSession) Ping(ctx context.Context) error
func (*GroupTransactSession) Produce ¶ added in v0.3.1
func (g *GroupTransactSession) Produce(ctx context.Context, record *kgo.Record, promise PromiseFunc)
func (*GroupTransactSession) ProduceSync ¶ added in v0.3.1
func (*GroupTransactSession) Shutdown ¶ added in v0.3.1
func (g *GroupTransactSession) Shutdown(_ context.Context) error
Shutdown stops polling and closes the group transaction session.
func (*GroupTransactSession) TryProduce ¶ added in v0.3.1
func (g *GroupTransactSession) TryProduce(ctx context.Context, record *kgo.Record, promise PromiseFunc)
type Opt ¶ added in v0.3.1
type Opt interface {
// contains filtered or unexported methods
}
func WithClientID ¶ added in v0.3.1
func WithConfig ¶ added in v0.3.1
func WithLogger ¶ added in v0.3.1
func WithMeterProvider ¶ added in v0.3.1
func WithMeterProvider(provider metric.MeterProvider) Opt
func WithMetricLabel ¶ added in v0.3.1
func WithMetricsNamespace ¶ added in v0.3.1
func WithTracerPropagator ¶ added in v0.3.1
func WithTracerPropagator(propagator propagation.TextMapPropagator) Opt
func WithTracerProvider ¶ added in v0.3.1
func WithTracerProvider(provider trace.TracerProvider) Opt
type ProducerOpt ¶ added in v0.3.1
type ProducerOpt interface {
Opt
// contains filtered or unexported methods
}
ProducerOpt is a producer-specific option to configure a client.
This is simply a namespaced Opt.
func WithAllowIdempotentProduceCancellation ¶ added in v0.3.1
func WithAllowIdempotentProduceCancellation() ProducerOpt
func WithProducePromise ¶ added in v0.3.1
func WithProducePromise(promiseFunc PromiseFunc) ProducerOpt
func WithProducerBatchCompression ¶
func WithProducerBatchCompression(preference ...kgo.CompressionCodec) ProducerOpt
func WithProducerBatchMaxBytesFn ¶ added in v0.3.1
func WithProducerBatchMaxBytesFn(fn func(topic string) int32) ProducerOpt
func WithRecordPartitioner ¶ added in v0.3.1
func WithRecordPartitioner(partitioner kgo.Partitioner) ProducerOpt
func WithRequiredAcks ¶ added in v0.3.1
func WithRequiredAcks(acks kgo.Acks) ProducerOpt
type PromiseFunc ¶ added in v0.4.2
PromiseFunc is called when an asynchronous produce request completes.
type Tx ¶ added in v0.4.0
type Tx struct {
// contains filtered or unexported fields
}
Tx exposes producing operations inside a Kafka transaction.
func (*Tx) Produce ¶ added in v0.4.0
Produce asynchronously produces a record inside the current Kafka transaction.
func (*Tx) ProduceSync ¶ added in v0.4.0
ProduceSync synchronously produces records inside the current Kafka transaction.
func (*Tx) TryProduce ¶ added in v0.4.0
TryProduce attempts to enqueue a record inside the current Kafka transaction without blocking on producer backpressure.