Skip to content

shaikrasheed99/golang-kafka-producer-consumer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kafka Producer & Consumer applications in Golang

This is a simple example of a Kafka producer and consumer written in Go using the Sarama library. The producer sends messages to a Kafka topic, and the consumer reads and processes those messages.

Prerequisites

Before running this application, ensure that you have the following installed:

  • Go (Golang) - You can download and install Go from the official website.
  • Kafka - You need a running Kafka broker. You can download and set up Apache Kafka from the official website.

Setup

  1. Clone this repository to your local machine
git clone https://github.com/shaikrasheed99/golang-kafka-producer-consumer.git
  1. Install the required Go packages
go get .
  1. Update the Kafka broker URL in the producer and consumer code if your Kafka broker is running on a different host and port.

  2. Build the producer and consumer executables

go build producer.go
go build consumer.go

Running the Producer

  1. Start the Kafka producer by running the producer executable
./producer
  1. The producer will prompt you to enter messages. Type a message and press Enter. To exit the producer, type "exit" and press Enter.

  2. The producer will send the messages to the Kafka topic specified in the code (default is "test").

Running the Consumer

  1. Start the Kafka consumer by running the consumer executable
./consumer
  1. The consumer will subscribe to the Kafka topic specified in the code (default is "test") and start reading messages.

  2. The consumer will print received messages to the console, or it will log any errors encountered during message processing.

  3. To stop the consumer, press Ctrl+C.