-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support config reactive datasource with list of database urls for fault tolerance and load balance #31994
Closed
benstonezhang
wants to merge
29
commits into
quarkusio:main
from
benstonezhang:reactive-db-conn-pool
Closed
Support config reactive datasource with list of database urls for fault tolerance and load balance #31994
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
c2bf298
support config reactive datasource with list of urls
benstonezhang f393ecf
revised comments; add test for db2, mssql and pg
benstonezhang f4ac273
Fix OTel exporter headers config
brunobat 075a586
Ensure Dialects initialized by the Hibernate Reactive extension use t…
Sanne 35b333f
Update SmallRye Config to 3.2.0
radcortez 9fb6afd
Update SmallRye Config to 3.2.0
radcortez 378dbb6
DevUI: Liquibase
melloware cf2c950
Bump mariadb-java-client from 3.1.2 to 3.1.3
dependabot[bot] 2e02dcc
Bump smallrye-open-api.version from 3.3.0 to 3.3.1
dependabot[bot] 7adf923
Merge remote-tracking branch 'origin/main' into reactive-db-conn-pool
benstonezhang 478c660
revert change made for db2 and mssql; update warning for multi values…
benstonezhang b3b5c03
Allow using the annotation `@PartFilename` on method parameters
Sgitario e6baa3c
Fix Kotlin formatting
geoand 14d12e8
Merge pull request #32086 from Sanne/HRDialectWrapping
yrodiere 09fb411
Merge pull request #31824 from radcortez/srconfig-3.2.0
gsmet b4a92c8
Merge pull request #32091 from melloware/devui-liquibase
phillip-kruger 125f884
Merge pull request #32100 from geoand/kotlin
gsmet d15dff6
Merge pull request #32073 from brunobat/fix-header-docs
radcortez 1d53bbf
Merge pull request #32099 from Sgitario/32033
Sgitario 66c9dd2
Merge pull request #32094 from quarkusio/dependabot/maven/org.mariadb…
gsmet 2647d64
Merge pull request #32095 from quarkusio/dependabot/maven/smallrye-op…
gsmet 0ddddfb
support config reactive datasource with list of urls
benstonezhang 28ad2ce
revised comments; add test for db2, mssql and pg
benstonezhang 42a6232
revert change made for db2 and mssql; update warning for multi values…
benstonezhang 6eb3c0f
Merge remote-tracking branch 'origin/reactive-db-conn-pool' into reac…
benstonezhang c0f173d
support config reactive datasource with list of urls
benstonezhang 7bed2ce
revised comments; add test for db2, mssql and pg
benstonezhang 8e54ba3
revert change made for db2 and mssql; update warning for multi values…
benstonezhang 5a963dc
Merge branch 'reactive-db-conn-pool' of https://github.com/benstonezh…
benstonezhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...lient/deployment/src/test/java/io.quarkus.reactive.db2.client/DB2PoolLoadBalanceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.quarkus.reactive.db2.client; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusDevModeTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class DB2PoolLoadBalanceTest { | ||
|
||
@RegisterExtension | ||
public static final QuarkusDevModeTest test = new QuarkusDevModeTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClass(DevModeResource.class) | ||
.add(new StringAsset("quarkus.datasource.db-kind=db2\n" + | ||
"quarkus.datasource.reactive.url=vertx-reactive:db2://localhost:6133/load_balance_test," + | ||
"vertx-reactive:db2://localhost:6134/load_balance_test," + | ||
"vertx-reactive:db2://localhost:6135/load_balance_test"), | ||
"application.properties")); | ||
|
||
@Test | ||
public void testLoadBalance() { | ||
RestAssured | ||
.get("/dev/error") | ||
.then() | ||
.statusCode(200) | ||
.body(Matchers.anyOf(Matchers.endsWith(":6133"), Matchers.endsWith(":6134"), Matchers.endsWith(":6135"))); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...e-db2-client/deployment/src/test/java/io.quarkus.reactive.db2.client/DevModeResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.quarkus.reactive.db2.client; | ||
|
||
import java.net.ConnectException; | ||
import java.sql.SQLException; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.CompletionStage; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.Response; | ||
|
||
import io.vertx.db2client.DB2Pool; | ||
|
||
@Path("/dev") | ||
public class DevModeResource { | ||
|
||
@Inject | ||
DB2Pool client; | ||
|
||
@GET | ||
@Path("/error") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public CompletionStage<Response> getErrorMessage() throws SQLException { | ||
CompletableFuture<Response> future = new CompletableFuture<>(); | ||
client.query("SELECT 1").execute(ar -> { | ||
Class<?> expectedExceptionClass = ConnectException.class; | ||
if (ar.succeeded()) { | ||
future.complete(Response.serverError().entity("Expected SQL query to fail").build()); | ||
} else if (!expectedExceptionClass.isAssignableFrom(ar.cause().getClass())) { | ||
ar.cause().printStackTrace(); | ||
future.complete(Response.serverError() | ||
.entity("Expected " + expectedExceptionClass + ", got " + ar.cause().getClass()).build()); | ||
} else { | ||
future.complete(Response.ok(ar.cause().getMessage()).build()); | ||
} | ||
}); | ||
return future; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package io.quarkus.reactive.db2.client; | ||
|
||
import java.util.List; | ||
|
||
import io.quarkus.reactive.datasource.ReactiveDataSource; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.db2client.DB2ConnectOptions; | ||
|
@@ -25,6 +27,6 @@ interface Input { | |
|
||
PoolOptions poolOptions(); | ||
|
||
DB2ConnectOptions db2ConnectOptions(); | ||
List<DB2ConnectOptions> db2ConnectOptionsList(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For DB2, we should do the same as with Oracle (only log a warning if the user provides two or more urls). |
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...t/deployment/src/test/java/io/quarkus/reactive/mssql/client/MSSQLPoolLoadBalanceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.quarkus.reactive.mssql.client; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusDevModeTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class MSSQLPoolLoadBalanceTest { | ||
|
||
@RegisterExtension | ||
public static final QuarkusDevModeTest test = new QuarkusDevModeTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClass(DevModeResource.class) | ||
.add(new StringAsset("quarkus.datasource.db-kind=mssql\n" + | ||
"quarkus.datasource.reactive.url=vertx-reactive:sqlserver://localhost:9434/load_balance_test," + | ||
"vertx-reactive:sqlserver://localhost:9435/load_balance_test," + | ||
"vertx-reactive:sqlserver://localhost:9436/load_balance_test"), | ||
"application.properties")); | ||
|
||
@Test | ||
public void testLoadBalance() { | ||
RestAssured | ||
.get("/dev/error") | ||
.then() | ||
.statusCode(200) | ||
.body(Matchers.anyOf(Matchers.endsWith(":9434"), Matchers.endsWith(":9435"), Matchers.endsWith(":9436"))); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add a comment explaining that if multiple values are set, then the pool will be configured to create new connections using each of the urls, in a round-robin fashion?