This example uses the sarama library to interact with Kafka both as a producer of messages and a consumer.
go get github.com/Shopify/sarama
go build main.go producer_example.go client.go consumer_example.go
Note: You can find the connection details in the "Overview" tab in the Aiven Console.
- Use the Aiven Client to create a topic in your Kafka cluster:
avn service topic-create <kafka-service-name> go_example_topic --partitions 3 --replication 3
- Open two shells. In the first, create a consumer:
./main -service-uri <host>:<port> -ca-path <ca.pem path> -key-path <service.key path> -cert-path <service.cert path> -consumer
- Once you see the message "Ready to consume messages", execute the producer in the second shell:
./main -service-uri <host>:<port> -ca-path <ca.pem path> -key-path <service.key path> -cert-path <service.cert path> -producer