Giter VIP home page Giter VIP logo

kafka-spring-boot's Introduction

Guide to using Kafka with Spring Boot

Java 17 Spring Docker Kafka

This guide covers setting up a Kafka environment with Spring Boot, detailing the creation of a producer and a consumer. We will use Docker Compose to orchestrate Kafka, Zookeeper and Kafdrop.

Requirements

  • Java-17
  • Docker

Apache Kafka: An Overview

Apache Kafka is an open source platform widely known for its distributed event streaming capabilities. It stands out for its scalability and resilience to failures.

Kafka Fundamentals

Unlike traditional messaging systems like RabbitMQ, Kafka operates on the following concepts:

  • Topics: They are responsible for storing messages.
  • Partitions: Optimize the message reading process.
  • Producers: These are systems that produce and send messages to topics.
  • Consumers: These are systems that consume and process messages.
  • Clusters: Consist of a set of machines (brokers) that run Kafka.

Consumer Groups

Consumers are grouped into consumption groups. Each consumer within a group is responsible for reading a partition of the topic. The number of consumers must be equal to or less than the number of partitions.

Zookeeper

Zookeeper acts as a service discovery and orchestration system for Kafka brokers. It manages errors and failure recovery, playing a critical role in Kafka's reliability.

Kafdrop

Kafdrop is an interface that offers a detailed view of topics and messages within Kafka.

Configuring the Producer

In the producer project, we employ Spring Web, Lombok and Kafka dependencies. Configuration properties can be found in application.yml. The ProducerConfig class manages the serialization, while the KafkaTemplate is used to send messages to the "user-topic" topic.

Configuring the Consumer

In the consumer project, we configure the same dependencies and properties. The @EnableKafka annotation on the main class enables the use of Kafka. The ConsumerConfig class manages deserialization. The User model and service are configured to process messages using the @KafkaListener annotation.

Getting Started

  1. Clone this repository on your local machine:
 git clone 'https://github.com/matheuslara01/kafka-spring-boot.git'
  1. Navigate to the project directory:
 cd kafka-springboot
  1. Run the following command to build and run the project:
docker-compose up -d
  1. To check running containers:
docker ps
  1. The Kafdrop interface will be accessible at:
localhost:19000

Running the example

To observe the exchange of messages between the producer and the consumer, send requests to localhost:8081/user. The consumer will automatically be associated with the topic's partitions.


License

This project is licensed under the MIT License.

kafka-spring-boot's People

Contributors

matheuslara01 avatar matheuslara23 avatar

Stargazers

 avatar

Watchers

 avatar

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.