Git Product home page Git Product logo

kafka2mysql's Introduction

Kafka2MySQL

Kafka2MySQL is a Go-based project that demonstrates how to consume messages from an Apache Kafka topic and store them in a MySQL database. It uses several powerful libraries including Watermill for message processing, GORM for ORM (Object-Relational Mapping), and Gin for HTTP server routing.

Table of Contents

Features

  • Consume messages from a Kafka topic.
  • Store consumed messages in a MySQL database.
  • Expose a REST API to publish messages to the Kafka topic.
  • Automatic schema migration for the MySQL database.

Prerequisites

  • Go 1.20+
  • Docker and Docker Compose
  • MySQL
  • Apache Kafka

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/kafka2mysql.git
    cd kafka2mysql
  2. Install dependencies:

    go mod tidy
  3. Set up MySQL and Kafka using Docker Compose: Ensure you have Docker and Docker Compose installed. Run the following command to start MySQL and Kafka:

    docker-compose up -d

Usage

  1. Run the application:

    go run main.go
  2. Publish a message to Kafka: Use an HTTP GET request to publish a message to Kafka.

    curl "http://localhost:8080/api/v1/kafka2mysql?message=HelloKafka"
  3. Check MySQL: The message should be stored in the MySQL database.

Project Structure

kafka2mysql/
├── configs/
│   └── config.go            # Configuration loading logic
├── providers/
│   ├── gin.go               # Gin server setup
│   ├── mysql.go             # MySQL setup
│   └── watermill.go         # Watermill router setup
├── subscriber/
│   └── kafka_subscriber.go  # Kafka subscriber implementation
├── publisher/
│   └── kafka_publisher.go   # Kafka publisher implementation
├── main.go                  # Main entry point
└── go.mod                   # Go modules file

Libraries Used

  • Watermill: A library for building event-driven applications.
  • GORM: An ORM library for Go.
  • Gin: A web framework for Go.
  • Go-JSON: A JSON library for Go, used for marshalling and unmarshalling JSON.

Contributing

Contributions are welcome! Please submit a pull request or open an issue to discuss what you would like to change.

License

This project is licensed under the MIT License. See the LICENSE file for details.

kafka2mysql's People

Contributors

sepehrsoh avatar

Watchers

 avatar  avatar

Forkers

aliheydarabadii

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.