Golang Sarama: How to Get List of Topics in Kafka Topic

In this example, we are using sarama library to list all the available topic at kafka broker



There are different library available in Golang to publish and subscribe topics in kafka. In this example, we are using sarama library to list all the available topic at kafka broker.

To get sarama library, run below command.
go get github.com/Shopify/sarama

Here is the Code to list all topics from kafka topic:
Running above code produces below output on my machine. Because, I have two topics(Test – 1 and Test-2) available with my kafka broker.
Test-1 Test-2
. . .

Never miss a post from Snehal Kumar, when you sign up for Ednsquare.