You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "Croway (via GitHub)" <gi...@apache.org> on 2025/07/25 14:51:13 UTC

[PR] CAMEL-22278: Improve rabbitmq producer performance [camel]

Croway opened a new pull request, #18735:
URL: https://github.com/apache/camel/pull/18735

   # Description
   
   <!--
   - Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
   -->
   
   # Target
   
   - [ ] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch)
   
   # Tracking
   - [ ] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it).
   
   <!--
   # *Note*: trivial changes like, typos, minor documentation fixes and other small items do not require a JIRA issue. In this case your pull request should address just this issue, without pulling in other changes.
   -->
   
   # Apache Camel coding standards and style
   
   - [ ] I checked that each commit in the pull request has a meaningful subject line and body.
   
   <!--
   If you're unsure, you can format the pull request title like `[CAMEL-XXX] Fixes bug in camel-file component`, where you replace `CAMEL-XXX` with the appropriate JIRA issue.
   -->
   
   - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes.
   
   <!--
   You can run the aforementioned command in your module so that the build auto-formats your code. This will also be verified as part of the checks and your PR may be rejected if if there are uncommited changes after running `mvn clean install -DskipTests`.
   
   You can learn more about the contribution guidelines at https://github.com/apache/camel/blob/main/CONTRIBUTING.md
   -->
   
   


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-22278: Improve rabbitmq producer performance [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #18735:
URL: https://github.com/apache/camel/pull/18735#discussion_r2231366712


##########
components/camel-spring-parent/camel-spring-rabbitmq/src/test/java/org/apache/camel/component/springrabbit/integration/RabbitMQProducerIT.java:
##########
@@ -40,6 +46,92 @@
 
 public class RabbitMQProducerIT extends RabbitMQITSupport {
 
+    @Disabled("Load test used to verify producer performance CAMEL-22278")
+    @Test
+    public void testProducerLoadAndReceive() throws Exception {
+        // --- 1. AMQP Setup ---
+        // Ensures the RabbitMQ queue, exchange, and binding exist before the test.
+        ConnectionFactory cf = context.getRegistry().lookupByNameAndType("myCF", ConnectionFactory.class);
+        Queue q = new Queue("myqueue");
+        TopicExchange t = new TopicExchange("foo");
+        AmqpAdmin admin = new RabbitAdmin(cf);
+        admin.declareQueue(q);
+        admin.declareExchange(t);
+        admin.declareBinding(BindingBuilder.bind(q).to(t).with("foo.bar.#"));
+
+        // --- 2. Test Configuration ---
+        final int numThreads = 10;
+        final int totalDurationSeconds = 10;
+        final int snapshotTimeSeconds = 5;
+
+        // --- 3. Concurrency Tools ---
+        ExecutorService executor = Executors.newFixedThreadPool(numThreads);
+        final AtomicInteger messageCounter = new AtomicInteger(0);
+        final AtomicBoolean running = new AtomicBoolean(true);
+
+        // --- 4. Define the Message Sending Task ---
+        Runnable senderTask = () -> {
+            while (running.get()) {
+                template.sendBody("direct:start", "Load test message #" + messageCounter.get());
+                messageCounter.incrementAndGet();
+            }
+        };
+
+        // --- 5. Start the Load Test ---
+        System.out.println(
+                String.format("Starting load test with %d threads for %d seconds...", numThreads, totalDurationSeconds));
+        for (int i = 0; i < numThreads; i++) {
+            executor.submit(senderTask);
+        }
+
+        // --- 6. Wait and Count at 5 Seconds ---
+        Thread.sleep(TimeUnit.SECONDS.toMillis(snapshotTimeSeconds));
+
+        int countAfter5Seconds = messageCounter.get();
+        System.out.println(String.format(">>> Messages sent after %d seconds: %d", snapshotTimeSeconds, countAfter5Seconds));
+        Assertions.assertTrue(countAfter5Seconds > 0, "No messages were sent after 5 seconds.");
+
+        // --- 7. Wait for the Remaining Time ---
+        Thread.sleep(TimeUnit.SECONDS.toMillis(totalDurationSeconds - snapshotTimeSeconds));
+
+        // --- 8. Stop Threads and Gather Final Sent Count ---
+        System.out.println("Stopping threads...");
+        running.set(false);
+        executor.shutdown();
+        executor.awaitTermination(5, TimeUnit.SECONDS);
+
+        int finalSentCount = messageCounter.get();
+        System.out.println(String.format(">>> Total messages sent in %d seconds: %d", totalDurationSeconds, finalSentCount));

Review Comment:
   no system out in tests - use log.debug / log.info and so on



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-22278: Improve rabbitmq producer performance [camel]

Posted by "Croway (via GitHub)" <gi...@apache.org>.
Croway commented on code in PR #18735:
URL: https://github.com/apache/camel/pull/18735#discussion_r2231399359


##########
components/camel-spring-parent/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/SpringRabbitMQProducer.java:
##########
@@ -212,19 +212,22 @@ protected boolean processInOnly(Exchange exchange, AsyncCallback callback) {
         }
         final long timeout = getEndpoint().getConfirmTimeout() <= 0 ? Long.MAX_VALUE : getEndpoint().getConfirmTimeout();
         try {
-            Boolean sent = getInOnlyTemplate().invoke(t -> {
-                t.send(ex, rk, msg);
-                if (confirm) {
+            boolean sent;
+            if (confirm) {
+                sent = getInOnlyTemplate().invoke(t -> {
+                    t.send(ex, rk, msg);
                     return t.waitForConfirms(timeout);
-                } else {
-                    return true;
-                }
-            });
+                });
+            } else {
+                getInOnlyTemplate().send(ex, rk, msg);
+                sent = true;
+            }
+
             if (Boolean.FALSE == sent) {
                 exchange.setException(new TimeoutException("Message not sent within " + timeout + " millis"));
             }
         } catch (Exception e) {
-            exchange.setException(e);
+            exchange.setException(e.getCause());

Review Comment:
   you are right, no need, it was a letfover.



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-22278: Improve rabbitmq producer performance [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #18735:
URL: https://github.com/apache/camel/pull/18735#issuecomment-3118296712

   :star2: Thank you for your contribution to the Apache Camel project! :star2: 
   
   :robot: CI automation will test this PR automatically.
   
   :camel: Apache Camel Committers, please review the following items:
   
   * First-time contributors **require MANUAL approval** for the GitHub Actions to run
   
   * You can use the command `/component-test (camel-)component-name1 (camel-)component-name2..` to request a test from the test bot.
   
   * You can label PRs using `build-all`, `build-dependents`, `skip-tests` and `test-dependents` to fine-tune the checks executed by this PR.
   
   * Build and test logs are available in the Summary page. **Only** [Apache Camel committers](https://camel.apache.org/community/team/#committers) have access to the summary. 
   
   * :warning: Be careful when sharing logs. Review their contents before sharing them publicly.


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-22278: Improve rabbitmq producer performance [camel]

Posted by "Croway (via GitHub)" <gi...@apache.org>.
Croway merged PR #18735:
URL: https://github.com/apache/camel/pull/18735


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-22278: Improve rabbitmq producer performance [camel]

Posted by "Croway (via GitHub)" <gi...@apache.org>.
Croway commented on code in PR #18735:
URL: https://github.com/apache/camel/pull/18735#discussion_r2231400270


##########
components/camel-spring-parent/camel-spring-rabbitmq/src/test/java/org/apache/camel/component/springrabbit/integration/RabbitMQProducerIT.java:
##########
@@ -40,6 +46,92 @@
 
 public class RabbitMQProducerIT extends RabbitMQITSupport {
 
+    @Disabled("Load test used to verify producer performance CAMEL-22278")
+    @Test
+    public void testProducerLoadAndReceive() throws Exception {
+        // --- 1. AMQP Setup ---
+        // Ensures the RabbitMQ queue, exchange, and binding exist before the test.
+        ConnectionFactory cf = context.getRegistry().lookupByNameAndType("myCF", ConnectionFactory.class);
+        Queue q = new Queue("myqueue");
+        TopicExchange t = new TopicExchange("foo");
+        AmqpAdmin admin = new RabbitAdmin(cf);
+        admin.declareQueue(q);
+        admin.declareExchange(t);
+        admin.declareBinding(BindingBuilder.bind(q).to(t).with("foo.bar.#"));
+
+        // --- 2. Test Configuration ---
+        final int numThreads = 10;
+        final int totalDurationSeconds = 10;
+        final int snapshotTimeSeconds = 5;
+
+        // --- 3. Concurrency Tools ---
+        ExecutorService executor = Executors.newFixedThreadPool(numThreads);
+        final AtomicInteger messageCounter = new AtomicInteger(0);
+        final AtomicBoolean running = new AtomicBoolean(true);
+
+        // --- 4. Define the Message Sending Task ---
+        Runnable senderTask = () -> {
+            while (running.get()) {
+                template.sendBody("direct:start", "Load test message #" + messageCounter.get());
+                messageCounter.incrementAndGet();
+            }
+        };
+
+        // --- 5. Start the Load Test ---
+        System.out.println(
+                String.format("Starting load test with %d threads for %d seconds...", numThreads, totalDurationSeconds));
+        for (int i = 0; i < numThreads; i++) {
+            executor.submit(senderTask);
+        }
+
+        // --- 6. Wait and Count at 5 Seconds ---
+        Thread.sleep(TimeUnit.SECONDS.toMillis(snapshotTimeSeconds));
+
+        int countAfter5Seconds = messageCounter.get();
+        System.out.println(String.format(">>> Messages sent after %d seconds: %d", snapshotTimeSeconds, countAfter5Seconds));
+        Assertions.assertTrue(countAfter5Seconds > 0, "No messages were sent after 5 seconds.");
+
+        // --- 7. Wait for the Remaining Time ---
+        Thread.sleep(TimeUnit.SECONDS.toMillis(totalDurationSeconds - snapshotTimeSeconds));
+
+        // --- 8. Stop Threads and Gather Final Sent Count ---
+        System.out.println("Stopping threads...");
+        running.set(false);
+        executor.shutdown();
+        executor.awaitTermination(5, TimeUnit.SECONDS);
+
+        int finalSentCount = messageCounter.get();
+        System.out.println(String.format(">>> Total messages sent in %d seconds: %d", totalDurationSeconds, finalSentCount));

Review Comment:
   ops, yeah, I was in hurry



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-22278: Improve rabbitmq producer performance [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #18735:
URL: https://github.com/apache/camel/pull/18735#discussion_r2231365668


##########
components/camel-spring-parent/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/SpringRabbitMQProducer.java:
##########
@@ -212,19 +212,22 @@ protected boolean processInOnly(Exchange exchange, AsyncCallback callback) {
         }
         final long timeout = getEndpoint().getConfirmTimeout() <= 0 ? Long.MAX_VALUE : getEndpoint().getConfirmTimeout();
         try {
-            Boolean sent = getInOnlyTemplate().invoke(t -> {
-                t.send(ex, rk, msg);
-                if (confirm) {
+            boolean sent;
+            if (confirm) {
+                sent = getInOnlyTemplate().invoke(t -> {
+                    t.send(ex, rk, msg);
                     return t.waitForConfirms(timeout);
-                } else {
-                    return true;
-                }
-            });
+                });
+            } else {
+                getInOnlyTemplate().send(ex, rk, msg);
+                sent = true;
+            }
+
             if (Boolean.FALSE == sent) {
                 exchange.setException(new TimeoutException("Message not sent within " + timeout + " millis"));
             }
         } catch (Exception e) {
-            exchange.setException(e);
+            exchange.setException(e.getCause());

Review Comment:
   Is there a reason this needs to be the cause, what if e is something else - we dont do this elsehwhere unless for a special reason



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org