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


##########
components/camel-sjms/src/main/java/org/apache/camel/component/sjms/consumer/BatchEndpointMessageListener.java:
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.sjms.consumer;
+
+import java.util.List;
+
+import jakarta.jms.Message;
+import jakarta.jms.Session;
+
+import org.apache.camel.AggregationStrategy;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.component.sjms.SjmsConstants;
+import org.apache.camel.component.sjms.SjmsEndpoint;
+import org.apache.camel.component.sjms.SjmsHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class BatchEndpointMessageListener {
+
+    public static final String SJMS_BATCH_SIZE_HEADER = "CamelSjmsBatchSize";
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(BatchEndpointMessageListener.class);
+
+    private final SjmsEndpoint endpoint;
+    private final Processor processor;
+    private final AggregationStrategy aggregationStrategy;
+
+    public BatchEndpointMessageListener(SjmsEndpoint endpoint, Processor 
processor, AggregationStrategy aggregationStrategy) {
+        this.endpoint = endpoint;
+        this.processor = processor;
+
+        this.aggregationStrategy = aggregationStrategy;
+    }
+
+    private Exchange aggregate(List<Message> rawMessages, Session session) {
+        Exchange result = null;
+        for (Message m : rawMessages) {
+            Exchange e = endpoint.createExchange(m, session);
+            // Populate the headers and body of the Exchange in message
+            e.getIn().getHeaders();
+            e.getIn().getBody();
+
+            result = aggregationStrategy.aggregate(result, e);
+        }
+            // Force eager materialization of JMS message headers and body 
into the
+            // Camel Exchange, before the session is committed/closed after 
dispatch.
+            e.getIn().getHeaders();
+            e.getIn().getBody();
+        return result;
+    }

Review Comment:
   🔴 **Critical: compilation error and deleted `onCompletion` call.** The 
suggestion from my previous review was misapplied via GitHub's "Apply 
suggestion" button — it replaced the `aggregationStrategy.onCompletion(result)` 
block instead of adding the comment to the existing eager-loading lines inside 
the for loop.
   
   As written:
   1. `e` at lines 62-63 is referenced **outside** the for loop where it was 
declared → **will not compile**
   2. `aggregationStrategy.onCompletion(result)` was deleted → behavioral 
regression (the strategy's completion callback is never invoked)
   3. The eager-loading calls appear twice: inside the loop (correct) and 
outside it (broken)
   
   The correct version of this method should be:
   
   ```suggestion
               // Force eager materialization of JMS message headers and body 
into the
               // Camel Exchange, before the session is committed/closed after 
dispatch.
               e.getIn().getHeaders();
               e.getIn().getBody();
   
               result = aggregationStrategy.aggregate(result, e);
           }
           if (result != null) {
               aggregationStrategy.onCompletion(result);
           }
           return result;
       }
   ```



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