Skip to main content
Reactive SQL Clients
- We use vertex reactive SQL clients to access relational databases
- Reactive SQL client is a high-performance SQL client.
- The client is fully reactive and non-blocking and can handle many database connections within a single thread.
- The SQL client focuses on scalability and row overhead, And it has a simple API to execute SQL statements against the database.
- The vertex reactive SQL client is Currently available for PostgresSQL,MySql, SQL server, And IBM DB2.
- The reactive SQL client uses multiple databases connections on a single event loop thread.
- By default, client uses for connections.
- If we want to override this setting, it is possible to define pool options and specify the amount of database connection per database connection pool.
- Vertex has support for SQL client templates, which is a syntax to create SQL queries.
- It supports parameter mapping and row mapping.
- The database rows Can be mapped easily to Vertex Jason objects over custom objects.
- The SQL client template library also supports vertex data objects
- The forquery method is used to execute a query.
- We define a connection pool.
- We define SQL query.
- We map to An entity class.
- And then, in execute method, we define the query parameters as a collection.
- The query parameters are replaced in the SQL template.
- Configuration an our database pool includes defining some connection options With host, port, database, username, and password.
- We return a PGPool.pool() Object with parameters for Postgres.
- We return a MySqlPool().pool() Object with parameters for MySql.
- The SQL client usage is the same for all supported databases.
- We can configure multiple pool corresponding to different verticals.
- Each vertical contains one pool and runs on the same event loop thread.
- Each vertical is bound to one event loop.
- Vertex also supports JDBC client
- The JDBC client can be used for blocking JDBC access and uses worker threads.
- The JDBC client can be used for non-supported relational databases, which are not supported in the reactive SQL client API.
- The client is deprecated in the vertex version four.
- We should migrate to reactive SQL client API wherever possible.
- PGPool
- Vertex offers a reactive sql client To access relational databases.
- Most of the web applications use JDBC for relational database access, Which does not fit well in a reactive environment.
- The reactive SQL client uses multiple database connections on a single event loop thread.
- Everything is non-blocking and very efficient as the thread context, never changes.
- It’s also very convenient to use as a vertex is bound to an event loop thread.
- We should use one reactive database Connection pool for each vertical.
- By defining the pool options, it is possible to specify how many database connections should be used.
- By default 4 connections are used per thread.
- When we scale the rest API vertical up or down, The database connections scale with it.
- There are no thread Context switches As everything is running in the event loop.
- SQL client template library
- We use vertex SQL client template library to convert DB result-set to Java objects.
- We can use SQL client template library to create sql queries also in an easy way.
- Documentation Of SQL client template library can be found below
Comments
Post a Comment