Documentation
¶
Overview ¶
Package kafka defines driver-independent Kafka contracts and failure handling.
Index ¶
- Variables
- func AuthenticationContext(ctx context.Context, timeout time.Duration) (context.Context, context.CancelFunc)
- func PublishValue(ctx context.Context, p Producer, serializer encodingx.Serializer, ...) error
- func ValidateOAuth(t OAuthToken) error
- type AckHandler
- type AcknowledgedMessage
- type Admin
- type Consumer
- type CredentialProvider
- type Credentials
- type Delivery
- type GroupInfo
- type GroupMember
- type Handler
- type Inspector
- type ManualConsumer
- type Message
- type OAuthToken
- type Offset
- type PartitionInfo
- type Producer
- type TokenProvider
- type Topic
- type TopicDescription
- type TopicInfo
Constants ¶
This section is empty.
Variables ¶
var ErrUnacknowledged = errors.New("kafka: handler returned without acknowledgment")
Functions ¶
func AuthenticationContext ¶
func AuthenticationContext(ctx context.Context, timeout time.Duration) (context.Context, context.CancelFunc)
AuthenticationContext gives credential providers a finite deadline without retaining a request context in a client.
func PublishValue ¶
func PublishValue(ctx context.Context, p Producer, serializer encodingx.Serializer, metadata Message, value any) error
PublishValue serializes a typed payload while retaining topic/key/headers metadata. Nil serializer uses bounded JSON.
func ValidateOAuth ¶
func ValidateOAuth(t OAuthToken) error
ValidateOAuth rejects absent or already expired tokens before sending them to a broker.
Types ¶
type AckHandler ¶
type AckHandler func(context.Context, AcknowledgedMessage) error
AckHandler handles a message requiring explicit acknowledgment intent.
type AcknowledgedMessage ¶
AcknowledgedMessage requires Ack before the handler returns successfully. Ack requests the post-handler offset commit; it is not a broker commit receipt.
type Admin ¶
type Admin interface {
CreateTopic(context.Context, Topic) error
DeleteTopic(context.Context, string) error
ListTopics(context.Context) ([]TopicInfo, error)
Close() error
}
Admin owns a Kafka administration client.
type CredentialProvider ¶
type CredentialProvider func(context.Context) (Credentials, error)
type Credentials ¶
type Credentials struct{ Username, Password string }
Credentials are fetched at authentication time. Providers must honor cancellation and avoid returning secrets in errors.
type GroupInfo ¶
type GroupInfo struct {
Name, State, ProtocolType string
Members []GroupMember
}
GroupInfo describes consumer group state and membership.
type GroupMember ¶
type GroupMember struct{ ID, ClientID, Host string }
GroupMember identifies a current consumer group member.
type Handler ¶
Handler processes one message with cancellation support.
func DecodeHandler ¶
func DecodeHandler[T any](serializer encodingx.Serializer, handler func(context.Context, Message, T) error) Handler
DecodeHandler decodes before invoking the handler; decode failures are returned so the consumer cannot commit the record.
func RequireAck ¶
func RequireAck(h AckHandler) Handler
RequireAck prevents accidental source commits when a handler forgets to acknowledge.
func WithFailure ¶
WithFailure retries an explicitly idempotent handler, then publishes a DLQ message. A nil return after DLQ means the consumer may commit the source offset. DLQ failure leaves it uncommitted. Publish and source commit are separate operations; consumers must deduplicate DLQ deliveries.
type Inspector ¶
type Inspector interface {
Admin
DescribeTopic(context.Context, string) (TopicDescription, error)
ListGroups(context.Context) ([]GroupInfo, error)
DescribeGroup(context.Context, string) (GroupInfo, error)
Offsets(context.Context, string) ([]Offset, error)
}
Inspector extends basic administration with topic, group and committed-offset inspection.
type ManualConsumer ¶
type ManualConsumer interface {
Consumer
ConsumeAcknowledged(context.Context, AckHandler) error
}
ManualConsumer extends consumption with required explicit acknowledgment before successful return.
type Message ¶
type Message struct {
Topic string
Key, Value []byte
Headers map[string][]byte
Timestamp time.Time
Partition int32
Offset int64
}
Message contains transport-independent message data.
type OAuthToken ¶
OAuthToken is an opaque SASL bearer token. The issuing authority determines its authorization scope.
type Offset ¶
Offset is the next offset a consumer group will resume from; -1 indicates no committed offset.
type PartitionInfo ¶
PartitionInfo describes broker placement at one point in time.
type Producer ¶
type Producer interface {
Publish(context.Context, Message) error
PublishBatch(context.Context, []Message) error
Flush(context.Context) error
Close() error
}
Producer owns an acknowledged Kafka producer.
type TokenProvider ¶
type TokenProvider func(context.Context) (OAuthToken, error)
type Topic ¶
type Topic struct {
Name string
Partitions int32
ReplicationFactor int16
Config map[string]*string
}
Topic describes explicit topic creation settings.
type TopicDescription ¶
type TopicDescription struct {
Name string
Internal bool
Partitions []PartitionInfo
}
TopicDescription contains topic metadata and broker partition placement.