简体   繁体   中英

R2DBC can be used for change data capture in Spring boot?

I have a classic Spring Boot Application connected to a MySQL database.

Can I use r2dbc driver and spring data r2dbc to develop another application that listens to the database changes like a change data capture?

I've studied the r2dbc driver documentation, but I don't understand if they produces reactive hot streams or only cold streams. If it is not possible I believe that I should use Debezium , like I found in this article .

Thanks a lot

TL;DR

R2DBC is primarily a specification to enable reactive/non-blocking communication with your database. What an R2DBC driver is capable of pretty much depends on your database.

The Longer Version

R2DBC specifies a set of interfaces including methods where every database conversation is activated through a Publisher . R2DBC has no opinion on the underlying wire protocol . Instead, a database driver implementing R2DBC has to stick to its database communication protocol. What you get through JDBC or ODBC is pretty much the same as what you can expect from an R2DBC driver.

There are smaller differences: some JDBC drivers require polling for data (such as Postgres Pub/Sub notification) whereas, in R2DBC, a notification stream can be consumed without a polling thread as all I/O is based on listening on the receive buffers and emitting data once the driver receives data. In contrast, JDBC (and pretty much all imperative API) require someone to call a method to consume/obtain data.

I'm not sure how CDC works with MySQL; I think you need to scan (poll) the BINLOG using MySQL commands or the MySQL protocol. Right now, the R2DBC MySQL driver doesn't support BINLOG polling.

Postgres has similar functionality (Logical Decode). It is supported by R2DBC Postgres (see the documentation of Logical Decode using R2DBC Postgres ). In Postgres, the server pushes the replication log to the client, which gives you a hot stream as logical decode subscribes to the replication log.

The gist is pretty much that it depends on the actual database technology.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM