davsclaus opened a new pull request, #3381:
URL: https://github.com/apache/camel-kamelets/pull/3381
## What it does
Two new sources, `debezium-mysql-source` and `debezium-sqlserver-source`, on
the Camel `debezium-mysql` and `debezium-sqlserver` components. They follow the
design of `debezium-postgresql-source` (#3363, #3371). Each one sends a message
for each row inserted, updated or deleted in the tables of a MySQL or SQL
Server database, as it happens (change data capture). Both are `Preview`. Use
them from a route:
```yaml
- route:
from:
uri: "kamelet:debezium-mysql-source"
parameters:
serverName: db.example.com
username: replicator
password: "{{db.password}}"
serverId: 5400
topicPrefix: shop
tableIncludeList: shop.orders
offsetStorageFileName: /data/offsets.dat
schemaHistoryFileName: /data/schema-history.dat
steps:
- to: "kamelet:log-sink"
```
## Options
The same for both:
- Connection: `serverName`, `serverPort` (3306 / 1433), `username`,
`password` (marked `format: password` and `urn:camel:group:credentials`).
- `topicPrefix` (required): the logical name. It is also the connector name,
under which the position is saved. It has the pattern `^[a-zA-Z0-9._-]+$`.
- What is sent: `tableIncludeList`, and `snapshotMode` (`initial`,
`no_data`, `always`, `initial_only`, `when_needed` or `recovery`). `recovery`
is for one start after the schema history is lost.
- Position store, the same as for PostgreSQL: `offsetStorageFileName`
(default `debezium-<db>-offsets.dat`), or `offsetStorage` =
`org.apache.kafka.connect.storage.KafkaOffsetBackingStore` with
`offsetStorageBootstrapServers`, `offsetStorageTopic`,
`offsetStoragePartitions` and `offsetStorageReplicationFactor`.
- Schema history store, a choice like the position store:
`schemaHistoryFileName` (default `debezium-<db>-schema-history.dat`), or
`schemaHistory` = `io.debezium.storage.kafka.history.KafkaSchemaHistory` with
`schemaHistoryTopic`. The Kafka history uses the same brokers,
`offsetStorageBootstrapServers`. The component's own default is the Kafka
history, so the Kamelet sets the file history explicitly.
- Every other connector option can be set as
`camel.component.debezium-mysql.<option>` or
`camel.component.debezium-sqlserver.<option>`.
MySQL only:
- `serverId` (required): the replica id the Kamelet reads the binlog under.
Debezium requires it and has no default.
- `sslMode`: `disabled`, `preferred` (default, the component default) or
`required`.
SQL Server only:
- `databaseName` (required): one database, passed as `databaseNames`.
- `encrypt` (default `true`) and `trustServerCertificate` (default `false`),
the same as in `sqlserver-source`. They are passed to the JDBC driver as
`database.encrypt` and `database.trustServerCertificate`. The default refuses a
self-signed certificate: checked with `camel run`, which fails with `PKIX path
building failed`.
## Input / Output
- **Output:** the body is JSON text in bytes, with the columns in the order
of the table. It is the row after the change, or the row before it for a
delete. MySQL (`binlog_row_image=FULL`) and SQL Server CDC both log the whole
row, so a deleted row has all its columns.
- **Headers:** `debezium-operation` (`c`, `u`, `d` or `r`), `debezium-table`
and `debezium-key` (the primary key as JSON text), plus `Content-Type:
application/json`. `debezium-table` follows the table names of
`tableIncludeList`: `database.table` for MySQL (`shop.orders`) and
`schema.table` for SQL Server (`dbo.orders`). The `CamelDebezium*` headers are
removed.
- Events without a row are filtered out: tombstones, heartbeats and schema
changes.
## Server requirements (in the descriptions, and set up by the tests)
- **MySQL:** `binlog_format=ROW` and `binlog_row_image=FULL`. The user needs
`SELECT, RELOAD, SHOW DATABASES, REPLICATION SLAVE, REPLICATION CLIENT`. The
JDBC driver of MySQL is GPL and is `provided` in `camel-debezium-mysql`, so it
is not in the Kamelet. It must be added, such as with `camel run
--dep=mvn:com.mysql:mysql-connector-j:26.10.0`. Camel JBang does not add it by
itself for Debezium, unlike for `mysql-source`.
- **SQL Server:** CDC is enabled on the database (`sys.sp_cdc_enable_db`)
and on each table (`sys.sp_cdc_enable_table`), and SQL Server Agent runs. The
user is a member of `db_owner`.
Checked by hand with `camel run` (not in the Citrus tests, to keep them
lean):
- With `binlog_format=STATEMENT`, the MySQL Kamelet logs `...is not
configured to use a ROW binlog_format...` and reads nothing. The integration
keeps running.
- With the schema history file deleted, both Kamelets (MySQL and SQL Server)
log `The db history topic is missing` and read nothing. Started once with
`snapshotMode: recovery`, they write the history again and send only the
changes after the saved position.
- With the position file deleted, the MySQL Kamelet sends every row again as
`r`.
- With the CDC capture job stopped, a SQL Server change is not sent. Once
the job runs again, it is sent.
- The SQL Server CDC cleanup job keeps changes for 4320 minutes (3 days) by
default (`msdb.dbo.cdc_jobs`).
## Tests
All three tests are in `DatabaseIT#debezium`, under `database/debezium`:
- `debezium-mysql-source-route-test` (`mysql:8.4.7`, `mysqld
--binlog-format=ROW --binlog-row-image=FULL`, the user with exactly the
privileges the description names) checks:
- The snapshot row (`r`), then an insert, an update and a delete, each
with the right operation, table, key and body. The body is compared as text, so
the column order is checked too.
- The body is `[B` with `Content-Type` `application/json`, and the
`CamelDebezium*` headers are gone.
- `columnExcludeList`, set as a component property, leaves its column out
of the body.
- `sslMode: required` works against the container's own certificate.
- The schema history file goes in a folder that does not exist yet. A
restart with the same files sends only the change made while it was stopped,
and not the change of a table outside `tableIncludeList`.
- `debezium-mysql-source-kafka-route-test`: the same restart check, with the
position and the schema history both in Kafka topics (`apache/kafka` 4.4.0).
- `debezium-sqlserver-source-route-test`
(`mcr.microsoft.com/mssql/server:2022-CU28-ubuntu-22.04`, the image of the
existing SQL Server tests pinned to a CU, with `MSSQL_AGENT_ENABLED=true`, CDC
on `products` only, and a `db_owner` login) checks:
- The same snapshot, insert, update, delete and restart checks.
- A change in a table without CDC is not sent.
Each test stops its own integrations before Citrus removes the containers
(`autoRemove: false` and an explicit `camel stop`), as in #3369.
Local results:
- `./mvnw -o clean install -DskipITs` passes.
- `DatabaseIT#debezium` passes: 5 tests (the 2 PostgreSQL tests and the 3
new ones), 0 failures, 2026-11-23, Camel 4.24.0-SNAPSHOT of today.
- The test logs show that the Kafka test used `KafkaOffsetBackingStore` and
`KafkaSchemaHistory` (topic `shop-schema-history`). They also show that the
history folder of the file test was created.
Fixes #3373.
## Upgrade note
- New Kamelets `debezium-mysql-source` and `debezium-sqlserver-source`
(Preview): send the row changes of MySQL and SQL Server tables as they happen
(change data capture with Debezium), one JSON message per insert, update or
delete, with the `debezium-operation`, `debezium-table` and `debezium-key`
headers. The position and the schema history are saved in files or in Kafka
topics. The MySQL JDBC driver must be added to the integration.
_Claude Code on behalf of Claus Ibsen_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]