produce

package
v0.0.0-...-e61764d Latest Latest
Warning

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

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

Documentation

Overview

Package produce implements a toy producer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Producer

type Producer[M proto.Message] struct {
	// contains filtered or unexported fields
}

Producer is an example producer to a given topic using given Protobuf message type.

A Producer takes a Kafka client and a topic, and sends one of two types of data:

  • A Protobuf message of the given type.
  • Invalid data that could not be parsed as any Protobuf message.

This is a toy example, but shows the basics you need to send Protobuf messages to Kafka using franz-go.

func NewProducer

func NewProducer[M proto.Message](
	client *kgo.Client,
	serializer serde.Serializer,
	topic string,
) *Producer[M]

NewProducer returns a new Producer.

Always use this constructor to construct Producers.

func (*Producer[M]) ProduceInvalid

func (p *Producer[M]) ProduceInvalid(ctx context.Context, key string) error

ProduceInvalid synchronously sends data to the Producer's topic that could never be intererpreted as a Protobuf message.

func (*Producer[M]) ProduceProtobufMessage

func (p *Producer[M]) ProduceProtobufMessage(ctx context.Context, key string, message M) error

ProduceProtobufMessage serializes the given Protobuf messages, and synchronously sends it to the Producer's topic with the given key.

Jump to

Keyboard shortcuts

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