gnodet-bot commented on code in PR #30692:
URL: https://github.com/apache/camel/pull/30692#discussion_r4672259179


##########
components/camel-vertx/camel-vertx-websocket/src/main/java/org/apache/camel/component/vertx/websocket/VertxWebsocketClientConsumer.java:
##########
@@ -229,21 +230,50 @@ protected void handleResult(Object result) {
 
     protected void processExchange(Exchange exchange) {
         Vertx vertx = getEndpoint().getVertx();
-        vertx.executeBlocking(() -> {
-            createUoW(exchange);
-            getProcessor().process(exchange);
-            return null;
-        }, false)
-                .onComplete(result -> {
-                    try {
-                        if (result.failed()) {
-                            Throwable cause = result.cause();
-                            getExceptionHandler().handleException(cause);
-                        }
-                    } finally {
-                        doneUoW(exchange);
-                        releaseExchange(exchange, false);
+        // ordered: Vert.x runs the blocking tasks of the WebSocket's context 
one after the other, so the messages reach
+        // the route in the order they are received
+        boolean ordered = 
!getEndpoint().getConfiguration().isParallelProcessing();
+        if (getEndpoint().isSynchronous()) {
+            // synchronous path: run on worker, block until done
+            vertx.executeBlocking(() -> {
+                createUoW(exchange);
+                getProcessor().process(exchange);
+                return null;
+            }, ordered).onComplete(result -> {
+                try {
+                    if (result.failed()) {
+                        Throwable cause = result.cause();
+                        getExceptionHandler().handleException(cause);
                     }
-                });
+                } finally {
+                    doneUoW(exchange);
+                    releaseExchange(exchange, false);
+                }
+            });
+        } else {
+            // async path: Promise + runOnContext
+            Context context = vertx.getOrCreateContext();
+            Promise<Void> done = Promise.promise();
+            try {
+                vertx.executeBlocking(() -> {
+                    createUoW(exchange);
+                    getAsyncProcessor().process(exchange, doneSync -> 
context.runOnContext(v -> done.tryComplete()));
+                    return null;

Review Comment:
   ⚠️ **Ordering concern (async path):** `getAsyncProcessor().process(exchange, 
doneSync -> ...)` dispatches work asynchronously and returns immediately. When 
`ordered=true`, Vert.x only serializes the _dispatch_ of callables into the 
worker pool — not their _completion_. A second message's callable can start as 
soon as the first returns `null`, even if the first exchange is still being 
processed. The ordering guarantee in the comment above (`// ordered: Vert.x 
runs the blocking tasks…`) only holds on the synchronous path where 
`getProcessor().process(exchange)` actually blocks.
   
   This may be intentional for async routes, but it differs from what the 
comment claims. Consider documenting the difference or using a `Promise`-aware 
ordered queue if strict in-order completion is needed.



##########
components/camel-vertx/camel-vertx-websocket/src/test/java/org/apache/camel/component/vertx/websocket/VertxWebsocketConsumerAsClientOrderTest.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.vertx.websocket;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.IntStream;
+
+import io.vertx.core.Vertx;
+import io.vertx.core.http.HttpServer;
+import io.vertx.core.http.ServerWebSocket;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Test;
+
+import static org.awaitility.Awaitility.await;
+
+/**
+ * The client consumer routes the messages of its WebSocket in the order they 
are received, unless parallelProcessing is
+ * set. The server is a plain Vert.x HTTP server, which pushes numbered 
messages when the test asks for them. The route
+ * waits a random few milliseconds for each message, so messages routed in 
parallel would overtake each other.
+ */
+class VertxWebsocketConsumerAsClientOrderTest extends 
VertxWebSocketTestSupport {
+
+    private static final int MESSAGES = 50;
+
+    private final Map<String, ServerWebSocket> open = new 
ConcurrentHashMap<>();
+    private Vertx serverVertx;
+
+    @Override
+    protected void setupResources() throws Exception {
+        serverVertx = Vertx.vertx();
+        HttpServer server = serverVertx.createHttpServer();
+        server.webSocketHandler(webSocket -> {
+            open.put(webSocket.path(), webSocket);
+            webSocket.closeHandler(closed -> open.remove(webSocket.path(), 
webSocket));
+        });
+        server.listen(port.getPort(), 
"localhost").toCompletionStage().toCompletableFuture().get(10, 
TimeUnit.SECONDS);
+    }
+
+    @Override
+    protected void cleanupResources() throws Exception {
+        if (serverVertx != null) {
+            
serverVertx.close().toCompletionStage().toCompletableFuture().get(10, 
TimeUnit.SECONDS);
+        }
+    }
+
+    @Test
+    void routesTheMessagesInTheOrderReceived() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:ordered");
+        mock.expectedBodiesReceived(numbers());
+
+        push("/ordered");
+
+        mock.assertIsSatisfied(context, 30, TimeUnit.SECONDS);
+    }
+
+    @Test
+    void routesTheMessagesInParallelWhenAskedTo() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:parallel");
+        mock.expectedBodiesReceivedInAnyOrder(numbers());
+
+        push("/parallel");

Review Comment:
   💡 **Test coverage note:** `expectedBodiesReceivedInAnyOrder` accepts any 
ordering, including strict in-order delivery — so this test cannot distinguish 
parallel from serial execution. If `parallelProcessing=true` silently became a 
no-op, this test would still pass. The test verifies that all messages arrive, 
which is a useful smoke test, but not proof of actual parallelism. A stronger 
assertion (e.g. verifying that the received order differs from the sent order 
at least once, or measuring wall-clock time) would make the intent clearer.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to