使用 kafka-go 实现消息生产与消费

介绍 kafka-go 的安装与使用,并通过 Go 示例实现消息生产、消费和偏移量读取。

docker安装kafka

配置节点

image-20251028112001997

安装kafka-go

bash
go get github.com/segmentio/kafka-go

writer写入

reader读入

执行结果

bash
root@pzj:/code/demo/kafka/reader# go run main.go 
message at offset 0 key: Key-A value: Hello World!
message at offset 1 key: Key-B value: One!
message at offset 2 key: Key-C value: Two!
Go Zap实现日志双写和切割
Canal 安装配置与 Go 客户端实践