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

时间:2021-01-12 18:06:18

For my web application, I need to serve dynamic HTML pages using templates and static css and JavaScript files. Except every one of my dynamic HTML pages would need to pull from a database and block the thread on the event loop. 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?

对于我的Web应用程序,我需要使用模板和静态css和JavaScript文件来提供动态HTML页面。除了我的每个动态HTML页面都需要从数据库中提取并阻止事件循环中的线程。所以在这种情况下,我将不得不为每一个路由/页面使用阻塞处理程序。我的问题是,这是否合适?这对于一次访问该网站的许多用户有帮助吗?

Also, if I want to use my own JDBC client, rather than one provided by Vertx, can I just use that? (E.g. Use HikariCP for my project and use that independent of Vertx)

另外,如果我想使用自己的JDBC客户端,而不是Vertx提供的客户端,我可以使用它吗? (例如,将HikariCP用于我的项目并使用独立于Vertx的项目)

1 个解决方案

#1


0  

First of all HikariCP is just another pool provider for Vertx. So you can just use it with Vertx client.

首先,HikariCP只是Vertx的另一个池提供商。因此,您可以将它与Vertx客户端一起使用。

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

And if you use Vertx JDBC client, you don't need to block anything at all. What it would look like is:

如果您使用Vertx JDBC客户端,则根本不需要阻止任何内容。它看起来像是:

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”)的所有内容,并相应地设置上下文。

#1


0  

First of all HikariCP is just another pool provider for Vertx. So you can just use it with Vertx client.

首先,HikariCP只是Vertx的另一个池提供商。因此,您可以将它与Vertx客户端一起使用。

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

And if you use Vertx JDBC client, you don't need to block anything at all. What it would look like is:

如果您使用Vertx JDBC客户端,则根本不需要阻止任何内容。它看起来像是:

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”)的所有内容,并相应地设置上下文。