Documentation
¶
Index ¶
- Variables
- func ConvertAnyToBytes[T NumberOrString](v T) []byte
- func GenerateUUID() string
- type BatchHandlerFunc
- type Consumer
- type ConsumerConfig
- type ConsumerOption
- func WithConsumeResetOffset(offset kgo.Offset) ConsumerOption
- func WithConsumerBatchHandler(handlerFunc BatchHandlerFunc) ConsumerOption
- func WithConsumerClientID(v string) ConsumerOption
- func WithConsumerConfig(cfg *ConsumerConfig) ConsumerOption
- func WithConsumerGroupBalancers(balancers ...kgo.GroupBalancer) ConsumerOption
- func WithConsumerHandler(handlerFunc HandlerFunc) ConsumerOption
- func WithConsumerLogger(v *slog.Logger) ConsumerOption
- func WithConsumerMeterProvider(provider metric.MeterProvider) ConsumerOption
- func WithConsumerMetricsNamespace(ns string) ConsumerOption
- func WithConsumerTLS(tls *tls.Config) ConsumerOption
- func WithConsumerTracerPropagator(propagator propagation.TextMapPropagator) ConsumerOption
- func WithConsumerTracerProvider(provider trace.TracerProvider) ConsumerOption
- func WithFetchIsolationLevel(level kgo.IsolationLevel) ConsumerOption
- type HandlerFunc
- type MarshalFunc
- type NumberOrString
- type Producer
- type ProducerConfig
- type ProducerOption
- func WithProducerBatchCompression(preference ...kgo.CompressionCodec) ProducerOption
- func WithProducerCB(cb func(record *kgo.Record, err error)) ProducerOption
- func WithProducerClientID(v string) ProducerOption
- func WithProducerConfig(cfg *ProducerConfig) ProducerOption
- func WithProducerLogger(v *slog.Logger) ProducerOption
- func WithProducerMeterProvider(provider metric.MeterProvider) ProducerOption
- func WithProducerMetricsNamespace(ns string) ProducerOption
- func WithProducerPartitioner(partitioner kgo.Partitioner) ProducerOption
- func WithProducerRequiredAcks(acks kgo.Acks) ProducerOption
- func WithProducerTLS(tls *tls.Config) ProducerOption
- func WithProducerTracerPropagator(propagator propagation.TextMapPropagator) ProducerOption
- func WithProducerTracerProvider(provider trace.TracerProvider) ProducerOption
- type UnmarshalFunc
Constants ¶
This section is empty.
Variables ¶
var ( ProtoMarshal = MarshalProto() ProtoUnmarshal = UnmarshalProto() JSONMarshal = MarshalJSON() JSONUnmarshal = UnmarshalJSON() )
Functions ¶
func ConvertAnyToBytes ¶
func ConvertAnyToBytes[T NumberOrString](v T) []byte
func GenerateUUID ¶
func GenerateUUID() string
Types ¶
type Consumer ¶
type Consumer struct {
// contains filtered or unexported fields
}
func NewConsumer ¶
func NewConsumer(opts ...ConsumerOption) (*Consumer, error)
type ConsumerConfig ¶
type ConsumerConfig struct {
// SeedBrokers sets the seed brokers for the client to use, overriding the
// default 127.0.0.1:9092.
//
// Any seeds that are missing a port use the default Kafka port 9092.
Brokers string `envconfig:"KAFKA_BROKERS"`
// SaslMechanism SASL mechanism to use for authentication.
// Supported: PLAIN, SCRAM-SHA-256, SCRAM-SHA-512.
// NOTE: Despite the name only one mechanism must be configured.
SASLMechanism string `envconfig:"KAFKA_SASL_MECHANISM"`
// User sasl username for use with the PLAIN and SASL-SCRAM-.. mechanisms.
User string `envconfig:"KAFKA_USER"`
// Password sasl password for use with the PLAIN and SASL-SCRAM-.. mechanism.
Password string `envconfig:"KAFKA_PASSWORD"`
// Enabled custom option: detecting enabling.
Enabled bool `envconfig:"KAFKA_ENABLED"`
// SkipFatalErrors custom option: skip fatal errors while fetching records,
// otherwise leave the process.
SkipFatalErrors bool `envconfig:"KAFKA_SKIP_FATAL_ERRORS"`
// ConsumeRegex sets the client to parse all topics passed to Topics as
// regular expressions.
ConsumeRegex bool `envconfig:"KAFKA_CONSUME_REGEX"`
// Topics adds topics to use for consuming.
Topics string `envconfig:"KAFKA_TOPICS"`
// Group sets the consumer group for the client to join and consume in.
// This option is required if using any other group options.
Group string `envconfig:"KAFKA_GROUP"`
// MaxPollRecords maximum of maxPollRecords total across all fetches.
MaxPollRecords int `envconfig:"KAFKA_MAX_POLL_RECORDS"`
// InstanceID sets the group consumer's instance ID, switching the group member
// from "dynamic" to "static".
InstanceID string `envconfig:"KAFKA_INSTANCE_ID"`
// PollInterval interval between handle batches.
PollInterval time.Duration `envconfig:"KAFKA_POLL_INTERVAL"`
// SuspendProcessingTimeout waiting timeout after batch processing failed (custom property).
SuspendProcessingTimeout time.Duration `envconfig:"KAFKA_SUSPEND_PROCESSING_TIMEOUT"`
// SuspendCommitingTimeout waiting timeout after committing failed (custom property).
SuspendCommitingTimeout time.Duration `envconfig:"KAFKA_SUSPEND_COMMITTING_TIMEOUT"`
// FetchMaxWait sets the maximum amount of time a broker will wait for a
// fetch response to hit the minimum number of required bytes before returning.
FetchMaxWait time.Duration `envconfig:"KAFKA_FETCH_MAX_WAIT"`
// FetchMaxBytes sets the maximum amount of bytes a broker will try to send
// during a fetch.
FetchMaxBytes int32 `envconfig:"KAFKA_FETCH_MAX_BYTES"`
// FetchMinBytes sets the minimum amount of bytes a broker will try to send
// during a fetch.
FetchMinBytes int32 `envconfig:"KAFKA_FETCH_MIN_BYTES"`
// FetchMaxPartitionBytes sets the maximum amount of bytes that will be
// consumed for a single partition in a fetch request.
FetchMaxPartitionBytes int32 `envconfig:"KAFKA_FETCH_MAX_PARTITION_BYTES"`
// DisableFetchSessions sets the client to not use fetch sessions (Kafka 1.0+).
DisableFetchSessions bool `envconfig:"KAFKA_DISABLE_FETCH_SESSIONS"`
// SessionTimeout sets how long a member in the group can go between
// heartbeats, overriding the default 45,000ms. If a member does not heartbeat
// in this timeout, the broker will remove the member from the group and
// initiate a rebalance.
SessionTimeout time.Duration `envconfig:"KAFKA_SESSION_TIMEOUT"`
// RebalanceTimeout sets how long group members are allowed to take when a
// rebalance has begun.
RebalanceTimeout time.Duration `envconfig:"KAFKA_REBALANCE_TIMEOUT"`
// HeartbeatInterval sets how long a group member goes between heartbeats to
// Kafka.
HeartbeatInterval time.Duration `envconfig:"KAFKA_HEARTBEAT_INTERVAL"`
// RequireStableFetchOffsets sets the group consumer to require "stable" fetch
// offsets before consuming from the group.
RequireStableFetchOffsets bool `envconfig:"KAFKA_REQUIRE_STABLE_FETCH_OFFS"`
// RequestTimeoutOverhead uses the given time as overhead while deadlining
// requests.
RequestTimeoutOverhead time.Duration `envconfig:"KAFKA_REQUEST_TIMEOUT_OVERHEAD"`
// ConnIdleTimeout is a rough amount of time to allow connections to idle
// before they are closed.
ConnIdleTimeout time.Duration `envconfig:"KAFKA_CONN_IDLE_TIMEOUT"`
// DialTimeout sets the dial timeout.
DialTimeout time.Duration `envconfig:"KAFKA_DIAL_TIMEOUT"`
// RequestRetries sets the number of tries that retryable requests are allowed.
RequestRetries *int `envconfig:"KAFKA_REQUEST_RETRIES"`
// RetryTimeout sets the upper limit on how long we allow a request to be
// issued and then reissued on failure. That is, this control the total
// end-to-end maximum time we allow for trying a request.
RetryTimeout time.Duration `envconfig:"KAFKA_RETRY_TIMEOUT"`
// BrokerMaxWriteBytes upper bounds the number of bytes written to a broker
// connection in a single write.
BrokerMaxWriteBytes *int32 `envconfig:"KAFKA_MAX_WRITE_BYTES"`
// BrokerMaxReadBytes sets the maximum response size that can be read from
// Kafka.
BrokerMaxReadBytes *int32 `envconfig:"KAFKA_MAX_READ_BYTES"`
// MetadataMaxAge sets the maximum age for the client's cached metadata.
MetadataMaxAge time.Duration `envconfig:"KAFKA_METADATA_MAX_AGE"`
// MetadataMinAge sets the minimum time between metadata queries.
MetadataMinAge time.Duration `envconfig:"KAFKA_METADATA_MIN_AGE"`
}
type ConsumerOption ¶
type ConsumerOption interface {
// contains filtered or unexported methods
}
func WithConsumeResetOffset ¶
func WithConsumeResetOffset(offset kgo.Offset) ConsumerOption
WithConsumeResetOffset sets the offset to start consuming from, or if OffsetOutOfRange is seen while fetching, to restart consuming from.
func WithConsumerBatchHandler ¶
func WithConsumerBatchHandler(handlerFunc BatchHandlerFunc) ConsumerOption
WithConsumerBatchHandler set batch message handler
func WithConsumerClientID ¶
func WithConsumerClientID(v string) ConsumerOption
func WithConsumerConfig ¶
func WithConsumerConfig(cfg *ConsumerConfig) ConsumerOption
func WithConsumerGroupBalancers ¶
func WithConsumerGroupBalancers(balancers ...kgo.GroupBalancer) ConsumerOption
WithConsumerGroupBalancers sets the group balancers to use for dividing topic partitions among group members, overriding the current default [cooperative-sticky]. This option is equivalent to Kafka's partition.assignment.strategies option.
For balancing, Kafka chooses the first protocol that all group members agree to support.
Note that if you opt into cooperative-sticky rebalancing, cooperative group balancing is incompatible with eager (classical) rebalancing and requires a careful rollout strategy (see KIP-429).
func WithConsumerHandler ¶
func WithConsumerHandler(handlerFunc HandlerFunc) ConsumerOption
WithConsumerHandler set message handler
func WithConsumerLogger ¶
func WithConsumerLogger(v *slog.Logger) ConsumerOption
func WithConsumerMeterProvider ¶
func WithConsumerMeterProvider(provider metric.MeterProvider) ConsumerOption
func WithConsumerMetricsNamespace ¶
func WithConsumerMetricsNamespace(ns string) ConsumerOption
func WithConsumerTLS ¶
func WithConsumerTLS(tls *tls.Config) ConsumerOption
WithConsumerTLS opts into dialing brokers with the given TLS config with a 10s dial timeout.
Every dial, the input config is cloned. If the config's ServerName is not specified, this function uses net.SplitHostPort to extract the host from the broker being dialed and sets the ServerName. In short, it is not necessary to set the ServerName.
func WithConsumerTracerPropagator ¶
func WithConsumerTracerPropagator(propagator propagation.TextMapPropagator) ConsumerOption
func WithConsumerTracerProvider ¶
func WithConsumerTracerProvider(provider trace.TracerProvider) ConsumerOption
func WithFetchIsolationLevel ¶
func WithFetchIsolationLevel(level kgo.IsolationLevel) ConsumerOption
WithFetchIsolationLevel sets the "isolation level" used for fetching records.
type MarshalFunc ¶
func MarshalJSON ¶
func MarshalJSON() MarshalFunc
func MarshalProto ¶
func MarshalProto() MarshalFunc
type NumberOrString ¶
type Producer ¶
type Producer struct {
// contains filtered or unexported fields
}
func NewProducer ¶
func NewProducer(opts ...ProducerOption) (*Producer, error)
func (*Producer) ProduceAsync ¶
func (*Producer) ProduceSync ¶
type ProducerConfig ¶
type ProducerConfig struct {
// Brokers sets the seed brokers for the client to use, overriding the
// default 127.0.0.1:9092.
//
// Any seeds that are missing a port use the default Kafka port 9092.
Brokers string `envconfig:"KAFKA_BROKERS"`
// SaslMechanism SASL mechanism to use for authentication.
// Supported: PLAIN, SCRAM-SHA-256, SCRAM-SHA-512.
// NOTE: Despite the name only one mechanism must be configured.
SASLMechanism string `envconfig:"KAFKA_SASL_MECHANISM"`
// User sasl username for use with the PLAIN and SASL-SCRAM-.. mechanisms.
User string `envconfig:"KAFKA_USER"`
// Password sasl password for use with the PLAIN and SASL-SCRAM-.. mechanism.
Password string `envconfig:"KAFKA_PASSWORD"`
// RequestTimeoutOverhead uses the given time as overhead while deadlining
// requests.
RequestTimeoutOverhead time.Duration `envconfig:"KAFKA_REQUEST_TIMEOUT_OVERHEAD"`
// ConnIdleTimeout is a rough amount of time to allow connections to idle
// before they are closed.
ConnIdleTimeout time.Duration `envconfig:"KAFKA_CONN_IDLE_TIMEOUT"`
// DialTimeout sets the dial timeout.
DialTimeout time.Duration `envconfig:"KAFKA_DIAL_TIMEOUT"`
// RequestRetries sets the number of tries that retryable requests are allowed.
RequestRetries *int `envconfig:"KAFKA_REQUEST_RETRIES"`
// RetryTimeout sets the upper limit on how long we allow a request to be
// issued and then reissued on failure. That is, this control the total
// end-to-end maximum time we allow for trying a request.
RetryTimeout time.Duration `envconfig:"KAFKA_RETRY_TIMEOUT"`
// BrokerMaxWriteBytes upper bounds the number of bytes written to a broker
// connection in a single write.
BrokerMaxWriteBytes *int32 `envconfig:"KAFKA_MAX_WRITE_BYTES"`
// BrokerMaxReadBytes sets the maximum response size that can be read from
// Kafka.
BrokerMaxReadBytes *int32 `envconfig:"KAFKA_MAX_READ_BYTES"`
// MetadataMaxAge sets the maximum age for the client's cached metadata.
MetadataMaxAge time.Duration `envconfig:"KAFKA_METADATA_MAX_AGE"`
// MetadataMinAge sets the minimum time between metadata queries.
MetadataMinAge time.Duration `envconfig:"KAFKA_METADATA_MIN_AGE"`
// DefaultProduceTopic sets the default topic to produce to if the topic field
// is empty in a Record.
DefaultProduceTopic string `envconfig:"KAFKA_DEFAULT_PRODUCE_TOPIC"`
// ProducerBatchMaxBytes upper bounds the size of a record batch.
ProducerBatchMaxBytes int32 `envconfig:"KAFKA_PRODUCER_BATCH_MAX_BYTES"`
// MaxBufferedRecords sets the max amount of records the client will buffer,
// blocking produces until records are finished if this limit is reached.
MaxBufferedRecords int `envconfig:"KAFKA_MAX_BUFFERED_RECORDS"`
// MaxBufferedBytes sets the max amount of bytes that the client will buffer
// while producing, blocking produces until records are finished if this limit
// is reached.
MaxBufferedBytes int `envconfig:"KAFKA_MAX_BUFFERED_BYTES"`
// ProduceRequestTimeout sets how long Kafka broker's are allowed to respond to
// produce requests, overriding the default 10s. If a broker exceeds this
// duration, it will reply with a request timeout error.
ProduceRequestTimeout time.Duration `envconfig:"KAFKA_PRODUCE_REQUEST_TIMEOUT"`
// RecordRetries sets the number of tries for producing records.
RecordRetries int `envconfig:"KAFKA_RECORD_RETRIES"`
// ProducerLinger sets how long individual topic partitions will linger waiting
// for more records before triggering a request to be built.
ProducerLinger time.Duration `envconfig:"KAFKA_PRODUCER_LINGER"`
// RecordDeliveryTimeout sets a rough time of how long a record can sit around
// in a batch before timing out.
RecordDeliveryTimeout time.Duration `envconfig:"KAFKA_RECORD_DELIVERY_TIMEOUT"`
// TransactionalID sets a transactional ID for the client, ensuring that
// records are produced transactionally under this ID (exactly once semantics).
TransactionalID string `envconfig:"KAFKA_TRANSACTIONAL_ID"`
// TransactionTimeout sets the allowed for a transaction.
TransactionTimeout time.Duration `envconfig:"KAFKA_TRANSACTION_TIMEOUT"`
}
type ProducerOption ¶
type ProducerOption interface {
// contains filtered or unexported methods
}
func WithProducerBatchCompression ¶
func WithProducerBatchCompression(preference ...kgo.CompressionCodec) ProducerOption
func WithProducerCB ¶
func WithProducerCB(cb func(record *kgo.Record, err error)) ProducerOption
WithProducerCB set callback func which calls after attempt to send message in topic
func WithProducerClientID ¶
func WithProducerClientID(v string) ProducerOption
func WithProducerConfig ¶
func WithProducerConfig(cfg *ProducerConfig) ProducerOption
func WithProducerLogger ¶
func WithProducerLogger(v *slog.Logger) ProducerOption
func WithProducerMeterProvider ¶
func WithProducerMeterProvider(provider metric.MeterProvider) ProducerOption
func WithProducerMetricsNamespace ¶
func WithProducerMetricsNamespace(ns string) ProducerOption
func WithProducerPartitioner ¶
func WithProducerPartitioner(partitioner kgo.Partitioner) ProducerOption
func WithProducerRequiredAcks ¶
func WithProducerRequiredAcks(acks kgo.Acks) ProducerOption
func WithProducerTLS ¶
func WithProducerTLS(tls *tls.Config) ProducerOption
WithProducerTLS opts into dialing brokers with the given TLS config with a 10s dial timeout.
Every dial, the input config is cloned. If the config's ServerName is not specified, this function uses net.SplitHostPort to extract the host from the broker being dialed and sets the ServerName. In short, it is not necessary to set the ServerName.
func WithProducerTracerPropagator ¶
func WithProducerTracerPropagator(propagator propagation.TextMapPropagator) ProducerOption
func WithProducerTracerProvider ¶
func WithProducerTracerProvider(provider trace.TracerProvider) ProducerOption
type UnmarshalFunc ¶
func UnmarshalJSON ¶
func UnmarshalJSON() UnmarshalFunc
func UnmarshalProto ¶
func UnmarshalProto() UnmarshalFunc