Documentation ¶
Overview ¶
Package kafkacgo provides a simple high-level API for producing and consuming Apache Kafka messages. It abstracts away the complexities of the Kafka protocol and provides a simplified interface for working with Kafka topics.
IMPORTANT: This package depends on a C implementation, CGO must be enabled to use this package. For a non-CGO implementation see the "kafka" package.
Index ¶
- func DefaultMessageDecodeFunc(_ context.Context, msg []byte, data any) error
- func DefaultMessageEncodeFunc(_ context.Context, _ string, data any) ([]byte, error)
- type Consumer
- type Offset
- type Option
- func WithAutoOffsetResetPolicy(p Offset) Option
- func WithConfigParameter(key string, val kafka.ConfigValue) Option
- func WithMessageDecodeFunc(f TDecodeFunc) Option
- func WithMessageEncodeFunc(f TEncodeFunc) Option
- func WithProduceChannelSize(size int) Option
- func WithSessionTimeout(t time.Duration) Option
- type Producer
- type TDecodeFunc
- type TEncodeFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultMessageDecodeFunc ¶ added in v1.85.0
DefaultMessageDecodeFunc is the default function to decode a message for ReceiveData(). The value underlying data must be a pointer to the correct type for the next data item received.
Types ¶
type Consumer ¶
type Consumer struct {
// contains filtered or unexported fields
}
Consumer represents a wrapper around kafka.Consumer.
func NewConsumer ¶
NewConsumer creates a new instance of Consumer.
type Offset ¶
type Offset string
Offset points to where Kafka should start to read messages from.
const ( // OffsetLatest automatically reset the offset to the latest offset. OffsetLatest Offset = "latest" // OffsetEarliest automatically reset the offset to the earliest offset. OffsetEarliest Offset = "earliest" // OffsetNone throw an error to the consumerClient if no previous offset is found for the consumerClient's group. OffsetNone Offset = "none" )
type Option ¶
type Option func(*config)
Option is a type alias for a function that configures Kafka client.
func WithAutoOffsetResetPolicy ¶
WithAutoOffsetResetPolicy sets what to do when there is no initial offset in Kafka or if the current offset does not exist any more on the server (e.g. because that data has been deleted).
func WithConfigParameter ¶
func WithConfigParameter(key string, val kafka.ConfigValue) Option
WithConfigParameter extends kafka.ConfigMap with additional parameters. Parameters are listed at: * consumer: https://docs.confluent.io/platform/current/installation/configuration/consumer-configs.html * producer: https://docs.confluent.io/platform/current/installation/configuration/producer-configs.html
func WithMessageDecodeFunc ¶ added in v1.85.0
func WithMessageDecodeFunc(f TDecodeFunc) Option
WithMessageDecodeFunc allow to replace DefaultMessageDecodeFunc(). This function used by ReceiveData() to decode a message encoded with messageEncodeFunc to the provided data object. The value underlying data must be a pointer to the correct type for the next data item received.
func WithMessageEncodeFunc ¶ added in v1.85.0
func WithMessageEncodeFunc(f TEncodeFunc) Option
WithMessageEncodeFunc allow to replace DefaultMessageEncodeFunc. This function used by SendData() to encode the input data.
func WithProduceChannelSize ¶
WithProduceChannelSize sets the buffer size (in number of messages).
func WithSessionTimeout ¶
WithSessionTimeout sets the timeout used to detect client failures when using Kafka's group management facility. The client sends periodic heartbeats to indicate its liveness to the broker. If no heartbeats are received by the broker before the expiration of this session timeout, then the broker will remove this client from the group and initiate a rebalance. Note that the value must be in the allowable range as configured in the broker configuration by group.min.session.timeout.ms and group.max.session.timeout.ms.
type Producer ¶
type Producer struct {
// contains filtered or unexported fields
}
Producer represents a wrapper around kafka.Producer.
func NewProducer ¶
NewProducer creates a new instance of Producer.
type TDecodeFunc ¶ added in v1.85.0
TDecodeFunc is the type of function used to replace the default message decoding function used by ReceiveData().