Skip to content

📨 Simple Avro Kafka using Golang for Producer and Consumer with Docker

License

Notifications You must be signed in to change notification settings

moemoe89/simple-avro-kafka-golang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple-Avro-Kafka-Golang

demo

This repository created to show the example for using Avro for serialization & Kafka for publish-subscribe messaging with (Golang) as Simple Producer and Consumer

Running Kafka

Download the latest Kafka version from this link Kafka Download Page and choose the binary downloads.

  • Extract the binaries into some folder. For the example in project/kafka.
  • Go to your kafka extract directory.
  • Start the Zookeeper server with this command bin/zookeeper-server-start.sh config/zookeeper.properties
  • Start the Kafka server with this command bin/kafka-server-start.sh config/server.properties
  • Create the topic : bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic simple-avro-kafka-golang
  • If you want to show the topic list, you can using this command bin/kafka-topics.sh --list --zookeeper localhost:2181
  • Start simple producer for publish message to the topic bin/kafka-console-producer.sh --broker-list localhost:9092 --topic simple-avro-kafka-golang
  • For start simple consumer that can consume message from the topic, you can use this command bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic simple-avro-kafka-golang --from-beginning

Running Kafka with Docker

Build

$ docker-compose build

Run

$ docker-compose up

Stop

$ docker-compose down

Running Simple Kafka Producer using Golang

  • Make sure Running Kafka step already done.
  • Go to your kafka producer directory.
  • Copy config-sample.json to config.json and change the value based on your config.
  • Change Kafka address :
    localhost:9092
    
  • start using go run main.go

Running Simple Kafka Consumer using Golang

  • Make sure Running Kafka step already done.
  • Go to your kafka consumer directory.
  • Copy config-sample.json to config.json and change the value based on your config.
  • Change Kafka address :
    localhost:9092
    
  • start using go run main.go

Send Testing Message using POSTMAN

Make sure you already have POSTMAN

  • Open your POSTMAN.
  • Fill the url with localhost:8789 and choose POST method
  • Select Body tab and choose raw JSON (application/json) and then try to send message with JSON data
{
	"role": "user",
	"data": {
		"id": 4,
		"name": "Dekisugi"
	}
}

About

📨 Simple Avro Kafka using Golang for Producer and Consumer with Docker

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages