A Spring Boot application that uses Debezium and Kafka for change data capture (CDC) from MySQL databases.
This project demonstrates how to use Debezium's embedded connector to capture data changes from a MySQL database. It uses Debezium's event-driven architecture to listen for database changes and process them in real-time without using Kafka Connect.
- Real-time database change capture using Debezium
- Embedded Debezium engine configuration
- MySQL connector setup
- Processing of CDC events (CREATE, UPDATE, DELETE operations)
- Spring Boot REST API for monitoring status
- Java 17 or higher
- MySQL 5.7 or higher
- Maven 3.6 or higher
- Create a MySQL database named
debezium_test
- Create a table named
customer
in thedebezium_test
database - Make sure the MySQL user has the appropriate permissions for CDC (binlog access)
The application is pre-configured with the following settings in DebeziumConfig.java
:
- MySQL Host: localhost
- MySQL Port: 3306
- MySQL Username: root
- MySQL Password: root
- Database Name: debezium_test
- Table Include List: debezium_test.customer
Modify these settings in DebeziumConfig.java
if your setup differs.
# Clone the repository
git clone <repository-url>
cd kafaka_debezium
# Build the application
./mvnw clean package
# Run the application
./mvnw spring-boot:run
GET /status
: Check if the Debezium engine is running
- The application starts a Debezium engine when the Spring context is initialized
- Debezium connects to MySQL and starts monitoring the binlog for changes
- When a change occurs (INSERT, UPDATE, DELETE) in the monitored table, Debezium captures it
- The
CustomerService.handleChangeEvent()
method processes these events - The processed events can be used for various purposes (sent to another system, stored, etc.)
To customize the event handling, modify the CustomerService.handleChangeEvent()
method to implement your business logic.
This project uses:
- Spring Boot 3.3.2
- Debezium 2.5.0.Final
- MySQL Connector for Debezium
- Ensure MySQL binlog is enabled
- Check that the MySQL user has sufficient permissions
- Verify that the MySQL connection details are correct
- Examine the logs for any Debezium-related errors