-
Notifications
You must be signed in to change notification settings - Fork 5.1k
CAMEL-24126 - Ensure no message sent before the VertxWebsocket is fully configured #24740
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -152,6 +152,16 @@ protected Vertx getVertx() { | |||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| protected WebSocket getWebSocket() throws Exception { | ||||||||||||||||||||
| return getWebSocket((java.util.function.Consumer<WebSocket>) null); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| /** | ||||||||||||||||||||
| * Connects to the WebSocket server, optionally invoking a setup callback on the socket <em>before</em> the blocking | ||||||||||||||||||||
| * {@code future.get()} returns. This guarantees that any message/close/exception handlers supplied by the callback | ||||||||||||||||||||
| * are registered atomically with the connection, so no messages sent by the server immediately after the handshake | ||||||||||||||||||||
| * can be missed. | ||||||||||||||||||||
| */ | ||||||||||||||||||||
| protected WebSocket getWebSocket(java.util.function.Consumer<WebSocket> setupCallback) throws Exception { | ||||||||||||||||||||
| if (client == null) { | ||||||||||||||||||||
| resolvedClientOptions = configuration.getClientOptions(); | ||||||||||||||||||||
| if (resolvedClientOptions == null) { | ||||||||||||||||||||
|
|
@@ -171,8 +181,17 @@ protected WebSocket getWebSocket() throws Exception { | |||||||||||||||||||
| CompletableFuture<WebSocket> future = new CompletableFuture<>(); | ||||||||||||||||||||
| client.connect(connectOptions).onComplete(result -> { | ||||||||||||||||||||
| if (result.succeeded()) { | ||||||||||||||||||||
| LOG.info("Connected to WebSocket on {}", result.result().remoteAddress()); | ||||||||||||||||||||
| future.complete(result.result()); | ||||||||||||||||||||
| WebSocket ws = result.result(); | ||||||||||||||||||||
| LOG.info("Connected to WebSocket on {}", ws.remoteAddress()); | ||||||||||||||||||||
| if (setupCallback != null) { | ||||||||||||||||||||
| try { | ||||||||||||||||||||
| setupCallback.accept(ws); | ||||||||||||||||||||
| } catch (Exception e) { | ||||||||||||||||||||
| future.completeExceptionally(e); | ||||||||||||||||||||
| return; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| future.complete(ws); | ||||||||||||||||||||
|
Contributor
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. Minor robustness suggestion: if
Suggested change
Low-risk in practice since |
||||||||||||||||||||
| } else { | ||||||||||||||||||||
| webSocket = null; | ||||||||||||||||||||
| future.completeExceptionally(result.cause()); | ||||||||||||||||||||
|
|
||||||||||||||||||||
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.
Minor formatting nit — missing space before the parenthesis: