Chisle
The coding-agent plugin that bills 52% of a bare model across 20 live tasks. Terse persona + tool-output compressor + context diet.
翻訳待ち
Confluent's Apache Kafka Golang client
翻訳待ち
開発ツールHTML · GoGitHub @confluentinc自分でインストール所有者未確認
Paste into Claude or ChatGPT for installation instructions suited to your environment.
Have you tried it? One tap is enough. No sign-in needed.
The maker's introduction consists of the line above. Read the repository README for more details. Repository README ↗
Loading the full README.
Read the full README ↗confluent-kafka-go is Confluent's Golang client for Apache Kafka and the Confluent Platform.
Features:
High performance - confluent-kafka-go is a lightweight wrapper around librdkafka, a finely tuned C client.
Reliability - There are a lot of details to get right when writing an Apache Kafka client. We get them right in one place (librdkafka) and leverage this work across all of our clients (also confluent-kafka-python and confluent-kafka-dotnet).
Supported - Commercial support is offered by Confluent.
Future proof - Confluent, founded by the original creator/co-creator of Kafka, is building a streaming platform with Apache Kafka at its core. It's high priority for us that client features keep pace with core Apache Kafka and components of the Confluent Platform.
The Golang bindings provides a high-level Producer and Consumer with support for the balanced consumer groups of Apache Kafka 0.9 and above.
See the API documentation for more information.
For a step-by-step guide on using the client see Getting Started with Apache Kafka and Golang.
High-level balanced consumer
import (
"fmt"
"time"
"github.com/confluentinc/confluent-kafka-go/v2/kafka"
)
func main() {
c, err := kafka.NewConsumer(&kafka.ConfigMap{
"bootstrap.servers": "localhost",
"group.id": "myGroup",
"auto.offset.reset": "earliest",
})
if err != nil {
panic(err)
}
err = c.SubscribeTopics([]string{"myTopic", "^aRegex.*[Tt]opic"}, nil)
if err != nil {
panic(err)
}
// A signal handler or similar could be used to set this to false to break the loop.
run := true
for run {
msg, err := c.ReadMessage(time.Second)
if err == nil {
fmt.Printf("Message on %s: %s\n", msg.TopicPartition, string(msg.Value))
} else if !err.(kafka.Error).IsTimeout() {
// The client will automatically try to recover from all errors.
// Timeout is not considered an error because it is raised by
// ReadMessage in absence of messages.
fmt.Printf("Consumer error: %v (%v)\n", err, msg)
}
}
c.Close()
}
Producer
Production applications should serialize with Schema Registry. Producing raw bytes leads to data-quality issues, broken consumers, and ungovernable data.
import (
"fmt"
"github.com/confluentinc/confluent-kafka-go/v2/kafka"
"github.com/confluentinc/confluent-kafka-go/v2/schemaregistry"
"github.com/confluentinc/confluent-kafka-go/v2/schemaregistry/serde"
"github.com/confluentinc/confluent-kafka-go/v2/schemaregistry/serde/jsonschema"
)
type User struct {
Name string `json:"name"`
FavoriteNumber int `json:"favorite_number"`
}
func main() {
topic := "myTopic"
p, err := kafka.NewProducer(&kafka.ConfigMap{"bootstrap.servers": "localhost"})
if err != nil {
panic(err)
}
defer p.Close()
// Schema Registry serializer: registers and validates the schema on produce.
client, err := schemaregistry.NewClient(schemaregistry.NewConfig("http://localhost:8081"))
if err != nil {
panic(err)
}
ser, err := jsonschema.NewSerializer(client, serde.ValueSerde, jsonschema.NewSerializerConfig())
if err != nil {
panic(err)
}
// Delivery report handler for produced messages
go func() {
for e := range p.Events() {
switch ev := e.(type) {
case *kafka.Message:
if ev.TopicPartition.Error != nil {
fmt.Printf("Delivery failed: %v\n", ev.TopicPartition)
} else {
fmt.Printf("Delivered message to %v\n", ev.TopicPartition)
}
}
}
}()
// Produce a message to the topic (asynchronously)
value := User{Name: "Confluent", FavoriteNumber: 42}
payload, err := ser.Serialize(topic, &value)
if err != nil {
panic(err)
}
p.Produce(&kafka.Message{
TopicPartition: kafka.TopicPartition{Topic: &topic, Partition: kafka.PartitionAny},
Value: payload,
}, nil)
// Wait for message deliveries before shutting down
p.Flush(15 * 1000)
}
Avro and Protocol Buffers serializers are also available; see json_producer_example, avrov3_producer_example, and protobuf_producer_example.
More elaborate examples are available in the examples directory, including how to configure the Go client for use with Confluent Cloud.
Supports Go 1.26.10+ (or 1.27.3+) and librdkafka 2.16.0+.
You can use Go Modules to install confluent-kafka-go.
Import the kafka package from GitHub in your code:
import "github.com/confluentinc/confluent-kafka-go/v2/kafka"
Build your project:
go build ./...
If you are building for Alpine Linux (musl), -tags musl must be specified.
go build -tags musl ./...
A dependency to the latest stable version of confluent-kafka-go should be automatically added to
your go.mod file.
Manual install:
go get -u github.com/confluentinc/confluent-kafka-go/v2/kafka
Golang import:
import "github.com/confluentinc/confluent-kafka-go/v2/kafka"
This is the beginning of the README. Read the rest at the original. Read the full README ↗