简体   繁体   English

如何将Java连接池用于MySQL X DevAPI?

[英]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. 我一直在探索Spring下一版本中对非阻塞异步反应式Web应用程序的支持。 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. 因此,只要JDBC是一个同步阻止API,并且所有主要的关系数据库甚至都缺少专有的异步驱动程序,那么整个反应式事物可能仍会超前。

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). 然后,几乎是偶然地,我发现MySQL的最新版本支持称为“ X DevAPI ”的东西,该东西包含在当前的MySQL JDBC驱动程序中(尽管它是JDBC规范之外的附加类)。

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. 我还没有听说过有关X DevAPI的夸夸其谈,而且几乎没有什么文档似乎强调了将MongoDB替换为文档存储的用例。 However, the library also includes the ability to access a MySQL relational database in a non-blocking asynchronous way. 但是,该库还具有以非阻塞异步方式访问MySQL关系数据库的功能。

Unfortunately, the only documentation examples are basic "Hello World" use cases. 不幸的是,唯一的文档示例是基本的“ Hello World”用例。 A static void main method establishes a new MySQL X session from scratch, and closes it at the end. static void main方法从头开始建立一个新的MySQL X会话,并在最后将其关闭。

I'm curious if this new API is ready for more realistic use. 我很好奇这个新的API是否已准备好用于更实际的使用。 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? 是通过第三方库,还是通过没有充分记录的东西对MySQL库而言是本地的?

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? 还是我可能会在这里遗漏一些基本知识,而根本不需要连接池,因为X DevAPI是在底层进行多路复用的?

According to documentation there will be two types sessions: 根据文档 ,将有两种类型的会话:

  • XSession. 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 : 当前它只能连接到mysql的一个节点,但是对于MySQL 8版本,它有望与多个节点一起使用

Although the current version of MySQL X supports XSessions that connect to a single node, future versions could extend this to cover multiple nodes. 尽管当前版本的MySQL X支持连接到单个节点的XSession,但是以后的版本可能会将其扩展为涵盖多个节点。 An application using XSession is prepared to be scaled: change some connect parameters and be done with code changes. 使用XSession的应用程序已准备好进行缩放:更改一些连接参数,并通过更改代码来完成。

  • NodeSession. NodeSession。 As the XSession provides only a subset of sql function there should be a way to execute raw sql. 由于XSession仅提供sql函数的子集,因此应该有一种执行原始sql的方法。 SQL is statefull and so does NodeSession. SQL是全状态的,NodeSession也是如此。

An application using NodeSession establishes connections to individual nodes. 使用NodeSession的应用程序建立到各个节点的连接。 To scale an application using NodeSession you would have to replace the use of NodeSession with XSession whenever possible. 为了使用NodeSession扩展应用程序,您必须尽可能地用XSession代替NodeSession的使用。

The X Protocol needs X Plugin to be installed so you can check my sample repo for docker usage with X DevApi in Java. X协议需要安装X插件,因此您可以使用Java中的X DevApi检查示例存储库中的docker使用情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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