# canal-test **Repository Path**: freefactor/canal-test ## Basic Information - **Project Name**: canal-test - **Description**: canal-test - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-06-23 - **Last Updated**: 2025-07-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: test ## README # canal-test `canal-test` is a Spring Boot-based project designed to test and demonstrate how to use [Alibaba Canal](https://github.com/alibaba/canal) to subscribe and consume incremental logs (binlog) from a MySQL database. This project provides a simple example showing how to connect to a Canal Server and listen for database change events. ## Features - Quickly set up the application using Spring Boot - Integrate Alibaba Canal client to subscribe to database changes in real-time - Support parsing and printing binlog data for insert, update, and delete operations - Provide basic transaction control and error handling mechanisms ## Project Structure ``` canal-test/ ├── pom.xml ├── src/ │ ├── main/ │ │ ├── java/ │ │ │ └── com/ │ │ │ └── tech/ │ │ │ └── ai/ │ │ │ └── canal_test/ │ │ │ ├── CanalTestApplication.java │ │ │ └── deploy/ │ │ │ └── CanalClient.java │ │ └── resources/ │ │ └── application.properties │ └── test/ │ └── java/ │ └── com/ │ └── tech/ │ └── ai/ │ └── canal_test/ │ ├── CanalTestApplicationTests.java │ └── Test.java ├── mvnw ├── mvnw.cmd ├── .gitignore └── .gitattributes ``` ## Quick Start ### Requirements - Java 8 or higher - Maven 3.x - Installed and running [Canal Server](https://github.com/alibaba/canal) ### Installation and Execution 1. **Clone the project** ```bash git clone https://gitee.com/freefactor/canal-test.git cd canal-test ``` 2. **Build the project** ```bash ./mvnw clean package ``` 3. **Run the application** ```bash java -jar target/canal-test.jar ``` Or directly run the main class: ```bash ./mvnw spring-boot:run ``` 4. **Configure Canal Server** Ensure you have correctly configured and started the Canal Server, and that MySQL binlog is enabled. Modify the connection information in `CanalClient.java` to match your Canal Server configuration: ```java CanalConnector connector = CanalConnectors.newSingleConnector(new InetSocketAddress("127.0.0.1", 11111), "example", "", ""); ``` ## Usage Instructions - After starting the application, `CanalClient` will automatically connect to the Canal Server and begin listening for database changes. - All change events (insert, update, delete) will be parsed and printed to the console. - If no data is received, the program will retry every two seconds. ## Example Output When a database change occurs, the console will output content similar to the following: ``` ================》 binlog[mysql-bin.000001:1234] , name[test_db,test_table] , eventType : INSERT id : 1 update=true name : John Doe update=true ``` ## Contributing Contributions and issue reports are welcome. Please follow these steps: 1. Fork the repository 2. Create a new branch (`git checkout -b feature/new-feature`) 3. Commit your changes (`git commit -am 'Add new feature'`) 4. Push the branch (`git push origin feature/new-feature`) 5. Create a Pull Request ## License This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.