You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2021/07/27 19:44:04 UTC

[GitHub] [camel] klevy-toast opened a new pull request #5872: CAMEL-16790 Pulsar consumer can use external thread pool to receive messages to fix uneven message distribution

klevy-toast opened a new pull request #5872:
URL: https://github.com/apache/camel/pull/5872


   
   - [ ] Make sure there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it).  Trivial changes like typos do not require a JIRA issue.  Your pull request should address just this issue, without pulling in other changes.
   - [ ] Each commit in the pull request should have 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.
   - [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
   - [ ] Run `mvn clean install -Psourcecheck` in your module with source check enabled to make sure basic checks pass and there are no checkstyle violations. A more thorough check will be performed on your pull request automatically.
   Below are the contribution guidelines:
   https://github.com/apache/camel/blob/main/CONTRIBUTING.md
   
   I noticed a pulsar bug where a 2nd consumer on a shared subscription will not be able to process messages in a large backlog when it uses the `messageListener` interface. It is being patched in pulsar 2.9.0 (see https://github.com/apache/pulsar/issues/11008), but in the short-term it would be useful to have a way of consuming these messages in camel without relying on the `messageListener` interface. This PR adds an option to the pulsar component to use a threadpool that continuously receives and handles messages, which does distribute messages properly, as demonstrated by the new integration test.
   


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



[GitHub] [camel] davsclaus merged pull request #5872: CAMEL-16790 Pulsar consumer can use external thread pool to receive messages to fix uneven message distribution

Posted by GitBox <gi...@apache.org>.
davsclaus merged pull request #5872:
URL: https://github.com/apache/camel/pull/5872


   


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



[GitHub] [camel] davsclaus commented on a change in pull request #5872: CAMEL-16790 Pulsar consumer can use external thread pool to receive messages to fix uneven message distribution

Posted by GitBox <gi...@apache.org>.
davsclaus commented on a change in pull request #5872:
URL: https://github.com/apache/camel/pull/5872#discussion_r677968641



##########
File path: components/camel-pulsar/src/main/java/org/apache/camel/component/pulsar/PulsarConsumer.java
##########
@@ -76,4 +90,31 @@ protected void doResume() throws Exception {
         return strategy.create(endpoint);
     }
 
+    private Collection<ExecutorService> subscribeWithThreadPool(Collection<Consumer<byte[]>> consumers, PulsarEndpoint endpoint)
+            throws Exception {
+        int numThreads = endpoint.getPulsarConfiguration().getNumberOfConsumerThreads();
+        return consumers.stream().map(consumer -> {
+            ExecutorService executor = Executors.newFixedThreadPool(numThreads);
+            for (int i = 0; i < numThreads; i++) {
+                executor.submit(() -> {

Review comment:
       Also it may be worth to move this into its own private inner class so it has a class name that makes stacktraces and logging/debugging easier.

##########
File path: components/camel-pulsar/src/main/java/org/apache/camel/component/pulsar/utils/PulsarUtils.java
##########
@@ -31,6 +33,20 @@
     private PulsarUtils() {
     }
 
+    public static Queue<ExecutorService> stopExecutors(final Queue<ExecutorService> executors) {
+        for (ExecutorService executor : executors) {

Review comment:
       Use Camel's ExecutorServiceManager which has API for stopping thread pools

##########
File path: components/camel-pulsar/src/main/java/org/apache/camel/component/pulsar/PulsarConsumer.java
##########
@@ -76,4 +90,31 @@ protected void doResume() throws Exception {
         return strategy.create(endpoint);
     }
 
+    private Collection<ExecutorService> subscribeWithThreadPool(Collection<Consumer<byte[]>> consumers, PulsarEndpoint endpoint)
+            throws Exception {
+        int numThreads = endpoint.getPulsarConfiguration().getNumberOfConsumerThreads();
+        return consumers.stream().map(consumer -> {
+            ExecutorService executor = Executors.newFixedThreadPool(numThreads);

Review comment:
       Use Camel's executor service API for this, see getExecutorServiceManager on CamelContext

##########
File path: components/camel-pulsar/src/main/java/org/apache/camel/component/pulsar/PulsarConsumer.java
##########
@@ -76,4 +90,31 @@ protected void doResume() throws Exception {
         return strategy.create(endpoint);
     }
 
+    private Collection<ExecutorService> subscribeWithThreadPool(Collection<Consumer<byte[]>> consumers, PulsarEndpoint endpoint)
+            throws Exception {
+        int numThreads = endpoint.getPulsarConfiguration().getNumberOfConsumerThreads();
+        return consumers.stream().map(consumer -> {
+            ExecutorService executor = Executors.newFixedThreadPool(numThreads);
+            for (int i = 0; i < numThreads; i++) {
+                executor.submit(() -> {
+                    PulsarMessageListener listener = new PulsarMessageListener(endpoint, this);
+                    while (true) {
+                        try {
+                            Message<byte[]> msg = consumer.receive();
+                            listener.received(consumer, msg);
+                        } catch (PulsarClientException e) {
+                            if (e.getCause() instanceof InterruptedException) {
+                                // propagate interrupt
+                                LOGGER.info("Received shutdown signal, exiting");
+                                break;
+                            }
+                            LOGGER.error("Encountered exception while receiving message", e);

Review comment:
       Use getExceptionHandler to handle this exception.
   
   Also you would need to catch Exception to have a general catch and handle to keep the thread up and running.




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



[GitHub] [camel] klevy-toast commented on pull request #5872: CAMEL-16790 Pulsar consumer can use external thread pool to receive messages to fix uneven message distribution

Posted by GitBox <gi...@apache.org>.
klevy-toast commented on pull request #5872:
URL: https://github.com/apache/camel/pull/5872#issuecomment-888606323


   Thanks for the comments @davsclaus, didn't know about Camel's ExecutorServiceManager. I think that I addressed everything.


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