davsclaus commented on code in PR #24283:
URL: https://github.com/apache/camel/pull/24283#discussion_r3488343583


##########
core/camel-core-processor/src/main/java/org/apache/camel/processor/PollEnricher.java:
##########
@@ -313,8 +313,13 @@ public boolean process(Exchange exchange, AsyncCallback 
callback) {
                 prototype = false;
             }
 
-            // acquire the consumer from the cache
-            consumer = consumerCache.acquirePollingConsumer(endpoint);
+            // acquire the consumer, either from cache or create a new one
+            if (consumerCache != null) {
+                consumer = consumerCache.acquirePollingConsumer(endpoint);
+            } else {
+                consumer = endpoint.createPollingConsumer();
+                ServiceHelper.startService(consumer);
+            }
         } catch (Exception e) {
             if (isIgnoreInvalidEndpoint()) {
                 if (LOG.isDebugEnabled()) {

Review Comment:
   With `EmptyConsumerCache`, the acquire/release contract stays the same 
regardless of cache mode — this entire `if/else` block would collapse back to:
   ```java
   consumer = consumerCache.acquirePollingConsumer(endpoint);
   ```



##########
core/camel-core-processor/src/main/java/org/apache/camel/processor/PollEnricher.java:
##########
@@ -168,7 +168,7 @@ public Expression getExpression() {
     }
 
     public EndpointUtilizationStatistics getEndpointUtilizationStatistics() {
-        return consumerCache.getEndpointUtilizationStatistics();
+        return consumerCache != null ? 
consumerCache.getEndpointUtilizationStatistics() : null;

Review Comment:
   This null check would not be needed if an `EmptyConsumerCache` class existed 
— analogous to `EmptyProducerCache` in 
`core/camel-support/src/main/java/org/apache/camel/support/cache/EmptyProducerCache.java`.
   
   The `EmptyConsumerCache` would override `acquirePollingConsumer()` to always 
create a new consumer (via `endpoint.createPollingConsumer()` + 
`ServiceHelper.startService()`) and `releasePollingConsumer()` to always 
`ServiceHelper.stopAndShutdownService()`. It should also override 
`getCapacity()` to return `0`.
   
   Then `PollEnricher.doBuild()` would become:
   ```suggestion
           return consumerCache.getEndpointUtilizationStatistics();
   ```



##########
core/camel-core-processor/src/main/java/org/apache/camel/processor/PollEnricher.java:
##########
@@ -543,7 +553,7 @@ protected static String resolveScheme(Exchange exchange, 
String uri) {
 
     @Override
     protected void doBuild() throws Exception {
-        if (consumerCache == null) {
+        if (consumerCache == null && cacheSize >= 0) {

Review Comment:
   Instead of skipping cache creation, use the `EmptyConsumerCache` pattern 
(like `SendDynamicProcessor` does with `EmptyProducerCache`):
   
   ```java
   if (consumerCache == null) {
       if (cacheSize < 0) {
           consumerCache = new EmptyConsumerCache(this, camelContext);
           LOG.debug("PollEnrich {} is not using ConsumerCache", this);
       } else {
           consumerCache = new DefaultConsumerCache(this, camelContext, 
cacheSize);
           LOG.debug("PollEnrich {} using ConsumerCache with cacheSize={}", 
this, cacheSize);
       }
   }
   ```
   
   See `SendDynamicProcessor.doBuild()` for the equivalent producer-side 
pattern.



##########
core/camel-core-processor/src/main/java/org/apache/camel/processor/PollEnricher.java:
##########
@@ -361,8 +366,13 @@ public boolean process(Exchange exchange, AsyncCallback 
callback) {
             callback.done(true);
             return true;
         } finally {
-            // return the consumer back to the cache
-            consumerCache.releasePollingConsumer(endpoint, consumer);
+            if (consumerCache != null) {
+                // return the consumer back to the cache
+                consumerCache.releasePollingConsumer(endpoint, consumer);
+            } else {
+                // consumer cache disabled, stop the consumer immediately
+                ServiceHelper.stopAndShutdownService(consumer);
+            }
             // and stop prototype endpoints
             if (prototype) {
                 ServiceHelper.stopAndShutdownService(endpoint);

Review Comment:
   Same here — with `EmptyConsumerCache` this collapses back to:
   ```java
   consumerCache.releasePollingConsumer(endpoint, consumer);
   ```



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