Skip to content

Retry for Failed Kafka Messages (Spring Boot) When a Kafka consumer fails to process a message (e.g., due to an exception), Spring Kafka allows automatic retry and optionally sending the failed message to a Dead Letter Topic (DLT) after all retry attempts are exhausted.

Notifications You must be signed in to change notification settings

rtpuja/kafka-retry-springboot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kafka Spring Boot Application

This is a Spring Boot application that demonstrates the use of Apache Kafka for producing and consuming messages.

Features

  • Producer: Sends messages to a Kafka topic.
  • Consumer: Listens to messages from a Kafka topic and processes them.
  • Dead Letter Queue (DLQ): Handles failed messages by redirecting them to a DLQ.

Project Structure

  • KafkaProducer: Sends messages to the Kafka topic.
  • KafkaConsumer: Consumes messages from the Kafka topic and handles failures.
  • KafkaController: REST API to send messages to Kafka.

Prerequisites

  • Java 17+
  • Apache Kafka
  • Maven

Getting Started

  1. Clone the repository:
    git clone https://github.com/pooja-maersk/kafka-spring-boot-app.git
    cd kafka-spring-boot-app
    
  2. Build the project:
    mvn clean install Run the application:
    mvn spring-boot:run
  3. API Endpoints POST /kafka/send: Sends a message to the Kafka topic. Request Body: Plain text message. Example Usage Start Kafka and create the following topics:
    test-topic test-topic.DLT Use the following curl command to send a message:
    curl -X POST -H "Content-Type: text/plain" -d "Hello Kafka" http://localhost:8080/kafka/send Check the logs to see the message being consumed.

About

Retry for Failed Kafka Messages (Spring Boot) When a Kafka consumer fails to process a message (e.g., due to an exception), Spring Kafka allows automatic retry and optionally sending the failed message to a Dead Letter Topic (DLT) after all retry attempts are exhausted.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages