
1. preface
Responsive programming is already Java The field of programming has been around for a long time. It has high-performance, event-driven, makes full use of computing resources, and a more elegant asynchronous programming experience. It also provides a backpressure mechanism to prevent system overloading. a long time Java The response can only be the same MongoDB、Redis Wait for these non-relational databases to interact. At present, most of our data is still stored in relational databases. In most cases, Java use JDBC to operate relational databases, and JDBC is blocking and synchronous. Therefore, there is an urgent need for a database driver protocol that supports responsiveness. There are two responsive database driver protocols currently on the market. Let's take a look at them.
2. ADBA
ADBA is Oracle dominated Java Standards for asynchronous database access API 。Its purpose is to integrate into the future Java Among the standard distribution versions of, the development is relatively slow at present and currently only providesOpenJDKthesandbox characteristicsFor research by developers. It's not intended to be JDBC an extension or replacement of, but a completely independent API, should API provide JDBC Completely non-blocking access to the same database.
3. R2DBC
Spring officials Spring 5 Released a response Web framework Spring WebFlux Database interactions that can satisfy asynchronous responses are urgently needed API 。Due to a lack of standards and drivers,Pivotal (Spring official) The team began exploring reactive relational database connections (Reactive Relational Database Connectivity), and proposed R2DBC specification API To assess feasibility and discuss whether database vendors are interested in supporting reactive asynchronous non-blocking drivers. At the beginning, only PostgreSQL 、H2、MSSQL Three, now MySQL And joined in.R2DBC latest version is0.8.1.RELEASE。In addition to driver implementation, it also provides R2DBC connection pool and **R2DBC Agent**。In addition, it also supports cloud-native applications.
3.1 Available R2DBC driver implementations
Currently available drivers are:
- cloud-spanner-r2dbc: used forGoogle Cloud Spannerthe driver
- jasync-sql:JavaandKotlintheR2DBCPackager, useKotlinpreparedMySQLandPostgreSQLAsynchronous database driver.
- r2dbc-h2: forH2Implement native drivers to facilitate use as a test database.
- r2dbc-postgres: forPostgreSQLNative drivers implemented.
- r2dbc-mssql: forMicrosoft SQL ServerNative drivers implemented.
- r2dbc-mysql: forMySQLNative drivers implemented.
4. summary
We need to be clear whether ADBA or R2DBC none of them are meant to replace JDBC 。Just to fill the gap under responsive programming. As for the future of reactive style, it is not very clear yet, but it is developing rapidly and I am still very optimistic. for now ADBA It has the advantage of official blessing, and R2DBC With the advantage of an active community, I believe it will be revealed soon who is the leader in industry rules. I will also try to use it experimentally in the future R2DBC And share some of these experiences and pay more attention.
Comments0