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


##########
components/camel-knative/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpConsumer.java:
##########
@@ -236,55 +239,83 @@ private void handleRequest(RoutingContext routingContext) 
{
         // from("knative:event/my.event")
         //        
.to("http://{{env:PROJECT}}.{{env:NAMESPACE}}.svc.cluster.local/service";);
         //
-        routingContext.vertx().executeBlocking(() -> {
-            createUoW(exchange);
-            getAsyncProcessor().process(exchange);
-            return null;
-        },
-                false)
-                .onComplete(result -> {
-                    try {
-                        Throwable failure = null;
-
-                        if (result.succeeded()) {
-                            try {
-                                HttpServerResponse response = 
toHttpResponse(request, exchange.getMessage());
-                                Buffer body = null;
-
-                                if (request.response().getStatusCode() != 204 
&& configuration.isReply()) {
-                                    body = 
computeResponseBody(exchange.getMessage());
-
-                                    String contentType = 
MessageHelper.getContentType(exchange.getMessage());
-                                    if (contentType != null) {
-                                        
response.putHeader(Exchange.CONTENT_TYPE, contentType);
-                                    }
-                                }
-
-                                if (body != null) {
-                                    request.response().end(body);
-                                } else {
-                                    // 204 tells the caller that the event has 
been delivered: a failed exchange
-                                    // without reply keeps its error status, 
so that the event is sent again
-                                    if (!exchange.isFailed()) {
-                                        request.response().setStatusCode(204);
-                                    }
-                                    request.response().end();
-                                }
-                            } catch (Exception e) {
-                                failure = e;
-                            }
-                        } else if (result.failed()) {
-                            failure = result.cause();
+        // The route runs with the asynchronous processor: the worker thread 
is free once the route
+        // continues on another thread, so a route that calls an asynchronous 
producer on the same
+        // Vert.x (such as vertx-http in Camel Quarkus) does not exhaust the 
worker pool.
+        // With the endpoint option synchronous=true, the worker thread runs 
the route with the
+        // synchronous processor, so it is held until the route completes, and 
the worker pool
+        // bounds the requests in flight.
+        Context context = routingContext.vertx().getOrCreateContext();

Review Comment:
   `context` is captured before the `if/else` branch but is only used in the 
`else` (async) path — the synchronous path (`executeBlocking` at line 251) 
never references it.
   
   The two sibling consumers (`VertxWebsocketConsumer`, 
`VertxWebsocketClientConsumer`) correctly scope the variable inside the `else` 
block. Move the declaration into the `else` branch:
   
   ```suggestion
           if (((KnativeEndpoint) getEndpoint()).isSynchronous()) {
   ```
   
   (Remove line 248, and add `Context context = 
routingContext.vertx().getOrCreateContext();` on the first line of the `else` 
block after `} else {`.)



##########
components/camel-vertx/camel-vertx-websocket/src/main/java/org/apache/camel/component/vertx/websocket/VertxWebsocketEndpoint.java:
##########
@@ -82,6 +82,14 @@ public class VertxWebsocketEndpoint extends DefaultEndpoint 
implements EndpointS
 
     @UriParam
     private VertxWebsocketConfiguration configuration;
+    @UriParam(label = "consumer",
+              description = "Whether the consumer routes each message 
synchronously. When true, the route runs on a thread of the"
+                            + " Vert.x worker pool, which waits until the 
route is complete, so the size of the worker pool limits"
+                            + " how many messages are routed at the same time. 
When false, the route starts on a worker thread"
+                            + " with the asynchronous routing engine, and the 
worker thread is free as soon as the route continues"
+                            + " on another thread (such as an asynchronous 
producer), so the worker pool no longer limits the"
+                            + " messages in flight.")
+    private boolean synchronous;

Review Comment:
   Same issue as `KnativeConfiguration.java`: `@UriParam` on `synchronous` 
omits `defaultValue = "false"`.
   
   ```suggestion
       @UriParam(label = "consumer", defaultValue = "false",
                 description = "Whether the consumer routes each message 
synchronously. When true, the route runs on a thread of the"
                               + " Vert.x worker pool, which waits until the 
route is complete, so the size of the worker pool limits"
                               + " how many messages are routed at the same 
time. When false, the route starts on a worker thread"
                               + " with the asynchronous routing engine, and 
the worker thread is free as soon as the route continues"
                               + " on another thread (such as an asynchronous 
producer), so the worker pool no longer limits the"
                               + " messages in flight.")
       private boolean synchronous;
   ```



##########
components/camel-knative/camel-knative-component/src/main/java/org/apache/camel/component/knative/KnativeConfiguration.java:
##########
@@ -56,6 +56,14 @@ public class KnativeConfiguration implements Cloneable {
     private Boolean reply;
     @UriParam(label = "consumer", defaultValue = "true")
     private boolean muteException = true;
+    @UriParam(label = "consumer",
+              description = "Whether the consumer routes each request 
synchronously. When true, the route runs on a thread of the"
+                            + " Vert.x worker pool, which waits until the 
route is complete, so the size of the worker pool limits"
+                            + " how many requests are routed at the same time. 
When false, the route starts on a worker thread"
+                            + " with the asynchronous routing engine, and the 
worker thread is free as soon as the route continues"
+                            + " on another thread (such as an asynchronous 
producer), so the worker pool no longer limits the"
+                            + " requests in flight.")
+    private boolean synchronous;

Review Comment:
   The new `@UriParam` annotation on `synchronous` omits `defaultValue`. The 
adjacent `muteException` field (line 58) uses `@UriParam(..., defaultValue = 
"true")`, establishing the convention for boolean fields in this class.
   
   ```suggestion
       @UriParam(label = "consumer", defaultValue = "false",
                 description = "Whether the consumer routes each request 
synchronously. When true, the route runs on a thread of the"
                               + " Vert.x worker pool, which waits until the 
route is complete, so the size of the worker pool limits"
                               + " how many requests are routed at the same 
time. When false, the route starts on a worker thread"
                               + " with the asynchronous routing engine, and 
the worker thread is free as soon as the route continues"
                               + " on another thread (such as an asynchronous 
producer), so the worker pool no longer limits the"
                               + " requests in flight.")
       private boolean synchronous;
   ```



##########
components/camel-knative/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpConsumer.java:
##########
@@ -236,55 +239,83 @@ private void handleRequest(RoutingContext routingContext) 
{
         // from("knative:event/my.event")
         //        
.to("http://{{env:PROJECT}}.{{env:NAMESPACE}}.svc.cluster.local/service";);
         //
-        routingContext.vertx().executeBlocking(() -> {
-            createUoW(exchange);
-            getAsyncProcessor().process(exchange);
-            return null;
-        },
-                false)
-                .onComplete(result -> {
-                    try {
-                        Throwable failure = null;
-
-                        if (result.succeeded()) {
-                            try {
-                                HttpServerResponse response = 
toHttpResponse(request, exchange.getMessage());
-                                Buffer body = null;
-
-                                if (request.response().getStatusCode() != 204 
&& configuration.isReply()) {
-                                    body = 
computeResponseBody(exchange.getMessage());
-
-                                    String contentType = 
MessageHelper.getContentType(exchange.getMessage());
-                                    if (contentType != null) {
-                                        
response.putHeader(Exchange.CONTENT_TYPE, contentType);
-                                    }
-                                }
-
-                                if (body != null) {
-                                    request.response().end(body);
-                                } else {
-                                    // 204 tells the caller that the event has 
been delivered: a failed exchange
-                                    // without reply keeps its error status, 
so that the event is sent again
-                                    if (!exchange.isFailed()) {
-                                        request.response().setStatusCode(204);
-                                    }
-                                    request.response().end();
-                                }
-                            } catch (Exception e) {
-                                failure = e;
-                            }
-                        } else if (result.failed()) {
-                            failure = result.cause();
+        // The route runs with the asynchronous processor: the worker thread 
is free once the route
+        // continues on another thread, so a route that calls an asynchronous 
producer on the same
+        // Vert.x (such as vertx-http in Camel Quarkus) does not exhaust the 
worker pool.
+        // With the endpoint option synchronous=true, the worker thread runs 
the route with the
+        // synchronous processor, so it is held until the route completes, and 
the worker pool
+        // bounds the requests in flight.
+        Context context = routingContext.vertx().getOrCreateContext();

Review Comment:
   `context` is captured before the `if/else` branch but is only used in the 
`else` (async) path — the synchronous path (`executeBlocking` at line 251) 
never references it.
   
   The two sibling consumers (`VertxWebsocketConsumer`, 
`VertxWebsocketClientConsumer`) correctly scope the variable inside the `else` 
block. Move the declaration into the `else` branch:
   
   ```suggestion
           if (((KnativeEndpoint) getEndpoint()).isSynchronous()) {
   ```
   
   (Remove line 248, and add `Context context = 
routingContext.vertx().getOrCreateContext();` on the first line of the `else` 
block after `} else {`.)



##########
components/camel-knative/camel-knative-component/src/main/java/org/apache/camel/component/knative/KnativeConfiguration.java:
##########
@@ -56,6 +56,14 @@ public class KnativeConfiguration implements Cloneable {
     private Boolean reply;
     @UriParam(label = "consumer", defaultValue = "true")
     private boolean muteException = true;
+    @UriParam(label = "consumer",
+              description = "Whether the consumer routes each request 
synchronously. When true, the route runs on a thread of the"
+                            + " Vert.x worker pool, which waits until the 
route is complete, so the size of the worker pool limits"
+                            + " how many requests are routed at the same time. 
When false, the route starts on a worker thread"
+                            + " with the asynchronous routing engine, and the 
worker thread is free as soon as the route continues"
+                            + " on another thread (such as an asynchronous 
producer), so the worker pool no longer limits the"
+                            + " requests in flight.")
+    private boolean synchronous;

Review Comment:
   The new `@UriParam` annotation on `synchronous` omits `defaultValue`. The 
adjacent `muteException` field (line 58) uses `@UriParam(..., defaultValue = 
"true")`, establishing the convention for boolean fields in this class.
   
   ```suggestion
       @UriParam(label = "consumer", defaultValue = "false",
                 description = "Whether the consumer routes each request 
synchronously. When true, the route runs on a thread of the"
                               + " Vert.x worker pool, which waits until the 
route is complete, so the size of the worker pool limits"
                               + " how many requests are routed at the same 
time. When false, the route starts on a worker thread"
                               + " with the asynchronous routing engine, and 
the worker thread is free as soon as the route continues"
                               + " on another thread (such as an asynchronous 
producer), so the worker pool no longer limits the"
                               + " requests in flight.")
       private boolean synchronous;
   ```



-- 
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