https://github.com/pythonista7/go-kafka-consumer
Starter template for a simple kafka consumer written in golang.
https://github.com/pythonista7/go-kafka-consumer
go kafka-consumer starter-template
Last synced: 5 months ago
JSON representation
Starter template for a simple kafka consumer written in golang.
- Host: GitHub
- URL: https://github.com/pythonista7/go-kafka-consumer
- Owner: Pythonista7
- Created: 2022-08-24T08:04:59.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-10-27T17:29:26.000Z (over 3 years ago)
- Last Synced: 2025-04-01T16:55:24.318Z (10 months ago)
- Topics: go, kafka-consumer, starter-template
- Language: Go
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Simple Kafka Consumer in Go
This is a template repository for a simple Kafka consumer in Go. It uses the [confluent pkg](https://github.com/confluentinc/confluent-kafka-go).
## Instructions
1. Clone this repository into your `$GOPATH/src` directory.
2. Make sure your imports are correct and run `go mod tidy` to update the `go.sum` file.
3. Start up a local kafka instance using the below command. This docker compose file will automatically create a topic called `test-topic-1`.Kafka-REST is also included to make it easy to interact with the kafka instance vua HTTP.
```bash
docker-compose up -d
```
You can check that the topic was created by running the following command:
```bash
curl --request GET --url http://localhost:38082/topics
```
4. Run `go run main.go` to start the consumer.
*Note: If you are using a different kafka instance, you will need to update the properties in the `config/config.go` file.*
5. Send a message to the topic using the following command:
```bash
curl --request POST \
--url http://localhost:38082/topics/test-topic-1 \
--header 'content-type: application/vnd.kafka.json.v2+json' \
--data '{
"records": [
{
"value": {
"taskType":"taskType1",
"data":{
"id":1,
"name": "John Doe"
}
}
}
]
}'
```
You should see the message printed to the console.