简体   繁体   English

从数据库中提取时的Vertx阻止处理程序

[英]Vertx blocking handler when pulling from a database

For my web application, I need to serve dynamic HTML pages using templates and static css and JavaScript files. 对于我的Web应用程序,我需要使用模板以及静态CSS和JavaScript文件来提供动态HTML页面。 Except every one of my dynamic HTML pages would need to pull from a database and block the thread on the event loop. 除了我的每个动态HTML页面之外,都需要从数据库中提取并阻塞事件循环中的线程。 So in this case I would have to use a blocking handler for every single one of the routes/pages. 因此,在这种情况下,我将不得不对每个路由/页面使用阻塞处理程序。 My question is, is this proper at all? 我的问题是,这完全合适吗? And would this help for many users accessing the website at one time? 这对一次访问该网站的许多用户有帮助吗?

Also, if I want to use my own JDBC client, rather than one provided by Vertx, can I just use that? 另外,如果我想使用自己的JDBC客户端,而不是Vertx提供的客户端,可以使用吗? (Eg Use HikariCP for my project and use that independent of Vertx) (例如,将HikariCP用于我的项目,并将其独立于Vertx使用)

First of all HikariCP is just another pool provider for Vertx. 首先,HikariCP只是Vertx的另一个池提供程序。 So you can just use it with Vertx client. 因此,您可以将其与Vertx客户端一起使用。

http://vertx.io/docs/vertx-jdbc-client/java/ http://vertx.io/docs/vertx-jdbc-client/java/

And if you use Vertx JDBC client, you don't need to block anything at all. 而且,如果您使用Vertx JDBC客户端,则根本不需要阻止任何操作。 What it would look like is: 它看起来像是:

router
   db (callback)
      freemaker (callback)
         puts the result back on response

See this official example: 参见以下官方示例:
https://github.com/vert-x3/vertx-examples/blob/3.3.0/web-examples/src/main/java/io/vertx/example/web/templating/freemarker/Server.java https://github.com/vert-x3/vertx-examples/blob/3.3.0/web-examples/src/main/java/io/vertx/example/web/templating/freemarker/Server.java

Notice how engine is being used. 请注意如何使用引擎。 In your case, you may wrap everything from ctx.put("name", "Vert.x Web") in a DB callback, and set context accordingly. 就您而言,您可以将ctx.put("name", "Vert.x Web")中的所有内容包装在数据库回调中,并相应地设置上下文。

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

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