producer

package
v0.0.0-...-1a88b7f Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewProducer

func NewProducer(config *config.Kafka) (*kafka.Producer, error)

NewProducer This is used by composition for all the producers into this package. config Reference to the KafkaConfig struct that will be used to define the client library configuration. Return a reference to the kafka.Producer, which is returned by the client library used under the hood and nil when success, else it returns a nil reference to the producer and an error with the information of the situation.

func Produce

func Produce(producer *kafka.Producer, topic string, key string, value interface{}, headers ...kafka.Header) error

Produce a kafka message given a producer, topic, key, headers, and the value with the message information. The message is serialized as a json document. producer is the reference to a kafka.Producer (see NewProducer). topic is the name of the topic where the message will be published key is the key to be assigned to the message; this value is important because it is used to distribute the load in kafka; Actually it is checked that it is not an empty string, but if we assign always the same value, we avoid the messages to be distributed properly between the partitions. Internally it makes something like: target_partition = hash(key) % number_of_partitions value it could be any structure; the message structures are defined at pkg/event/message and are self-generated from the schema defined at pkg/event/schema package. headers is a variadic argument that contain all the headers to be added to the message. Return nil if the message is registered to be produced, which is not the same as the message is added to the kafka topic queue. If some error happens before register the message to be produced, an error is returned with information about the situation.

Types

This section is empty.

Jump to

Keyboard shortcuts

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