Skip to content

Commit

Permalink
Update websockets-next-reference.adoc with Tenants
Browse files Browse the repository at this point in the history
Describe how users can access headers in websockets-next and use it in CustomTenantResolver with normal Rest-Calls.
  • Loading branch information
Paul6552 authored and cescoffier committed Sep 12, 2024
1 parent 4636861 commit 2794090
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions docs/src/main/asciidoc/websockets-next-reference.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,47 @@ TIP: You can choose WebSocket endpoints to which the `HttpUpgradeCheck` is appli

As a direct consequence of the fact this extension reuses the _main_ HTTP server, all the relevant server configurations apply. See Refer to the xref:http-reference.adoc#ssl[HTTP guide] for more details.

=== Hibernate multitenancy
The `RoutingContext` is not available after the HTTP upgrade. However, it is possible to inject the `WebSocketConnection` and access the headers of the initial HTTP request.

If a custom `TenantResolver` is used and you would like to combine REST/HTTP and WebSockets, the code may look like this:

Check warning on line 811 in docs/src/main/asciidoc/websockets-next-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.TermsWarnings] Consider using 'want' rather than 'would like' unless updating existing content that uses the term. Raw Output: {"message": "[Quarkus.TermsWarnings] Consider using 'want' rather than 'would like' unless updating existing content that uses the term.", "location": {"path": "docs/src/main/asciidoc/websockets-next-reference.adoc", "range": {"start": {"line": 811, "column": 35}}}, "severity": "WARNING"}

Check warning on line 811 in docs/src/main/asciidoc/websockets-next-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.TermsWarnings] Consider using 'might (for possibility)' or 'can (for ability)' rather than 'may' unless updating existing content that uses the term. Raw Output: {"message": "[Quarkus.TermsWarnings] Consider using 'might (for possibility)' or 'can (for ability)' rather than 'may' unless updating existing content that uses the term.", "location": {"path": "docs/src/main/asciidoc/websockets-next-reference.adoc", "range": {"start": {"line": 811, "column": 92}}}, "severity": "WARNING"}
[source, java]
----
@RequestScoped
@PersistenceUnitExtension
public class CustomTenantResolver implements TenantResolver {
@Inject
RoutingContext context;
@Inject
WebSocketConnection connection;
@Override
public String getDefaultTenantId() {
return "public";
}
@Override
public String resolveTenantId() {
String schema;
try {
//Handle WebSocket
schema = connection.handshakeRequest().header("schema");
} catch ( ContextNotActiveException e) {
// Handle REST/HTTP
schema = context.request().getHeader( "schema" );
}
if ( schema == null || schema.equalsIgnoreCase( "public" ) ) {
return "public";
}
return schema;
}

Check warning on line 844 in docs/src/main/asciidoc/websockets-next-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.HeadingPunctuation] Do not use end punctuation in headings. Raw Output: {"message": "[Quarkus.HeadingPunctuation] Do not use end punctuation in headings.", "location": {"path": "docs/src/main/asciidoc/websockets-next-reference.adoc", "range": {"start": {"line": 844, "column": 3}}}, "severity": "INFO"}
}
----
For more information on Hibernate multitenancy, refer to the https://quarkus.io/guides/hibernate-orm#multitenancy[hibernate documentation].

Check warning on line 847 in docs/src/main/asciidoc/websockets-next-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.Spelling] Use correct American English spelling. Did you really mean 'multitenancy'? Raw Output: {"message": "[Quarkus.Spelling] Use correct American English spelling. Did you really mean 'multitenancy'?", "location": {"path": "docs/src/main/asciidoc/websockets-next-reference.adoc", "range": {"start": {"line": 847, "column": 24}}}, "severity": "WARNING"}

== Client API

[[client-connectors]]
Expand Down

0 comments on commit 2794090

Please sign in to comment.