# go-kafka-example **Repository Path**: piao/go-kafka-example ## Basic Information - **Project Name**: go-kafka-example - **Description**: golang kafka example - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-03-27 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: Go语言, Kafka ## README ## go-kafka-example golang kafka example ## Installation ```sh docker pull bitnami/kafka:latest $ ./run.sh up go run main.go -brokers="127.0.0.1:9092" -topics="sarama" -group="example" ``` ## Run kafkaclient ``` go build kafkaclient.go ./kafkaclient -h 作为producer启动 $ ./kafkaclient -command producer \ -host kafka1:9092,kafka2:9092 ## SASL/PLAIN enable $ ./kafkaclient -command producer \ -sasl -username kafkaclient -password kafkapassword \ -host kafka1:9092,kafka2:9092 ## TLS-enabled $ ./kafkaclient -command producer \ -tls -cert client.pem -key client.key -ca ca.pem \ -host kafka1:9093,kafka2:9093 producer发送消息给kafka: > aaa > bbb > quit 作为consumer启动 $ ./kafkaclient -command consumer \ -host kafka1:9092,kafka2:9092 ## SASL/PLAIN enabled $ ./kafkaclient -command consumer \ -sasl -username kafkaclient -password kafkapassword \ -host kafka1:9092,kafka2:9092 ## TLS-enabled $ ./kafkaclient -command consumer \ -tls -cert client.pem -key client.key -ca ca.pem \ -host kafka1:9093,kafka2:9093 consumer从kafka接受消息: ``` ## 参考 - https://hub.docker.com/r/bitnami/kafka - https://github.com/bitnami/bitnami-docker-kafka - https://studygolang.com/articles/18013