简体   繁体   中英

How do you use Java connection pooling for MySQL X DevAPI?

I've been exploring the support for non-blocking asynchronous reactive web apps that is coming in the next version of Spring. It struck me that most apps tend to interact with relational databases. So as long as JDBC is a synchronous blocking API, and all the major relational databases still lack even proprietary async drivers, then the whole reactive thing is probably still ahead of its time.

Then almost by accident, I discovered that the latest version of MySQL supported something called " X DevAPI ", which is included with the current MySQL JDBC driver (although it's extra classes, outside of the JDBC spec).

I haven't heard any fanfare about X DevAPI, and what little documentation there is seems to emphasize the use case of replacing MongoDB as a document store. However, the library also includes the ability to access a MySQL relational database in a non-blocking asynchronous way.

Unfortunately, the only documentation examples are basic "Hello World" use cases. A static void main method establishes a new MySQL X session from scratch, and closes it at the end.

I'm curious if this new API is ready for more realistic use. Specifically, is there any support for connection pooling? Either through 3rd-party libraries, or native to the MySQL library through something that isn't well documented?

Or could I be missing something fundamental here, and connection pooling simply isn't necessary at all because X DevAPI multiplexes under the covers or something?

According to documentation there will be two types sessions:

  • XSession. This is the preferable type of session because it stateless according to the dev blog post . Currently it can connect only to one node of mysql but as for MySQL 8 release it is expected to work with multiple nodes :

Although the current version of MySQL X supports XSessions that connect to a single node, future versions could extend this to cover multiple nodes. An application using XSession is prepared to be scaled: change some connect parameters and be done with code changes.

  • NodeSession. As the XSession provides only a subset of sql function there should be a way to execute raw sql. SQL is statefull and so does NodeSession.

An application using NodeSession establishes connections to individual nodes. To scale an application using NodeSession you would have to replace the use of NodeSession with XSession whenever possible.

The X Protocol needs X Plugin to be installed so you can check my sample repo for docker usage with X DevApi in Java.

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