This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new d04b3b934658 CAMEL-27602: camel-event - backpressurePolicy=Fail 
reports a full queue to the consumer exception handler, 
ExchangeAsyncProcessingStarted is received (#30987)
d04b3b934658 is described below

commit d04b3b9346583f08a7a205dbb6ac388c1ae8d10d
Author: allthingssecurity <[email protected]>
AuthorDate: Fri Nov 27 22:15:38 2026 +0530

    CAMEL-27602: camel-event - backpressurePolicy=Fail reports a full queue to 
the consumer exception handler, ExchangeAsyncProcessingStarted is received 
(#30987)
    
    1. With async=true and backpressurePolicy=Fail, the consumer threw an
       IllegalStateException when the queue was full. Camel notifies the event
       notifiers through EventHelper, which logs and ignores any exception of a
       notifier, so Fail behaved like Drop with a WARN log and a stack trace per
       lost event. The consumer now passes the IllegalStateException to its
       exception handler and drops the event. By default that logs at WARN as
       before; with bridgeErrorHandler=true the error handler of the route
       handles it, and a custom exceptionHandler sees it. The option
       description, the enum javadoc and the doc page say this. The component
       JSON, its catalog copy, the catalog copy of the doc page and the endpoint
       DSL are regenerated.
    
       With bridgeErrorHandler=true the report is an exchange that fires
       exchange events of its own, in the same thread. With Exchange* and no
       include filter the consumer accepts them, they do not fit in the full
       queue either, and each one was reported again, until a
       StackOverflowError. A thread local guard now drops the events fired
       while the consumer reports a full queue, if they do not fit, without
       another report. The doc page says so, and the 4.24 upgrade guide has an
       entry for the changed Fail behaviour.
    
    2. An endpoint that subscribed only to the deprecated
       ExchangeAsyncProcessingStarted type got no event: configureEventNotifier
       had no case for it, so the exchange events stayed ignored, and
       EventNotifierSupport also ignores this type by default
       (ignoreExchangeAsyncProcessingStartedEvents=true). So the type was never
       received, also not with Exchange*. The new case turns both on, but only
       when the endpoint names the type: a wildcard such as Exchange* or * still
       does not get these events, as before. The doc page says so.
    
    EventBackpressureFailTest, EventBackpressureFailBridgeTest
    (Exchange*, bridgeErrorHandler=true, a blocked consumer thread) and
    EventAsyncProcessingStartedTest cover the two points.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 .../org/apache/camel/catalog/components/event.json |   2 +-
 .../apache/camel/catalog/docs/event-component.adoc |  11 ++-
 .../apache/camel/component/camelevent/event.json   |   2 +-
 .../camel-event/src/main/docs/event-component.adoc |  11 ++-
 .../component/camelevent/BackpressurePolicy.java   |   5 +-
 .../component/camelevent/CamelEventConsumer.java   |  39 +++++++-
 .../component/camelevent/CamelEventEndpoint.java   |  20 +++-
 .../EventAsyncProcessingStartedTest.java           |  64 +++++++++++++
 .../EventBackpressureFailBridgeTest.java           |  85 +++++++++++++++++
 .../camelevent/EventBackpressureFailTest.java      | 101 +++++++++++++++++++++
 .../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc    |   9 ++
 .../dsl/CamelEventEndpointBuilderFactory.java      |  12 ++-
 12 files changed, 344 insertions(+), 17 deletions(-)

diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/event.json
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/event.json
index c12c710afccb..b77ee26b7cdc 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/event.json
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/event.json
@@ -48,7 +48,7 @@
     "async": { "index": 1, "kind": "parameter", "displayName": "Async", 
"group": "consumer", "label": "", "required": false, "type": "boolean", 
"javaType": "boolean", "deprecated": false, "autowired": false, "secret": 
false, "defaultValue": false, "description": "Whether to put the events in a 
bounded queue that a pool of threads routes, so the thread that fires an event 
does not wait for the route. If false, the event is routed on the thread that 
fires it." },
     "asyncPoolSize": { "index": 2, "kind": "parameter", "displayName": "Async 
Pool Size", "group": "consumer", "label": "", "required": false, "type": 
"integer", "javaType": "int", "deprecated": false, "autowired": false, 
"secret": false, "defaultValue": 10, "description": "The number of threads that 
take the events from the queue and route them. Only used when async is true." },
     "asyncQueueSize": { "index": 3, "kind": "parameter", "displayName": "Async 
Queue Size", "group": "consumer", "label": "", "required": false, "type": 
"integer", "javaType": "int", "deprecated": false, "autowired": false, 
"secret": false, "defaultValue": 1000, "description": "The capacity of the 
bounded event queue used when async is enabled. When the queue is full, the 
backpressure policy determines the behavior. Only used when the async option is 
enabled." },
-    "backpressurePolicy": { "index": 4, "kind": "parameter", "displayName": 
"Backpressure Policy", "group": "consumer", "label": "", "required": false, 
"type": "enum", "javaType": 
"org.apache.camel.component.camelevent.BackpressurePolicy", "enum": [ "Block", 
"Drop", "Fail" ], "deprecated": false, "autowired": false, "secret": false, 
"defaultValue": "Block", "description": "What happens to an event when the 
async queue is full. Block makes the thread that fires the event wait for 
space, D [...]
+    "backpressurePolicy": { "index": 4, "kind": "parameter", "displayName": 
"Backpressure Policy", "group": "consumer", "label": "", "required": false, 
"type": "enum", "javaType": 
"org.apache.camel.component.camelevent.BackpressurePolicy", "enum": [ "Block", 
"Drop", "Fail" ], "deprecated": false, "autowired": false, "secret": false, 
"defaultValue": "Block", "description": "What happens to an event when the 
async queue is full. Block makes the thread that fires the event wait for 
space, D [...]
     "batchSize": { "index": 5, "kind": "parameter", "displayName": "Batch 
Size", "group": "consumer", "label": "", "required": false, "type": "integer", 
"javaType": "int", "deprecated": false, "autowired": false, "secret": false, 
"defaultValue": 0, "description": "The number of events to collect into one 
exchange, whose body is a java.util.List of the events. A batch is sent when it 
is full, and every batchTimeout with the events collected so far. With 0 or 1, 
each event is its own excha [...]
     "batchTimeout": { "index": 6, "kind": "parameter", "displayName": "Batch 
Timeout", "group": "consumer", "label": "", "required": false, "type": 
"integer", "javaType": "long", "deprecated": false, "autowired": false, 
"secret": false, "defaultValue": 1000, "description": "The interval in 
milliseconds at which a timer sends the events collected so far, even if the 
batch is not full. Only used when batchSize is greater than 1." },
     "customEventClass": { "index": 7, "kind": "parameter", "displayName": 
"Custom Event Class", "group": "consumer", "label": "", "required": false, 
"type": "string", "javaType": "java.lang.String", "deprecated": false, 
"autowired": false, "secret": false, "description": "The fully qualified name 
of an event class. The consumer drops an event that is not an instance of this 
class, in addition to the event types of the path. Use it with the Custom event 
type to consume only your own event [...]
diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/event-component.adoc
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/event-component.adoc
index 93a14c6f930d..afa5a7481e9a 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/event-component.adoc
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/event-component.adoc
@@ -98,6 +98,9 @@ The following event types are available (corresponding to 
`org.apache.camel.spi.
 - `ExchangeSending`
 - `ExchangeSent`
 
+The deprecated `ExchangeAsyncProcessingStarted` type is only received when it 
is named in the event types. A wildcard
+such as `Exchange*` or `*` does not turn it on.
+
 === Step Events
 - `StepStarted`
 - `StepCompleted`
@@ -638,7 +641,11 @@ the `backpressurePolicy` option controls the behavior:
 
 * `Block` (default) — blocks the event notifier thread until space is 
available.
 * `Drop` — silently discards the event.
-* `Fail` — throws an exception.
+* `Fail` — discards the event and passes an `IllegalStateException` to the 
exception handler of the consumer. By
+default it is logged at WARN level; with `bridgeErrorHandler=true` the error 
handler of the route handles it. Camel
+ignores an exception that an event notifier throws, so the event that does not 
fit is never processed and the code
+that fired it does not fail. The events fired while a full queue is reported, 
such as the events of the exchange that
+`bridgeErrorHandler=true` routes to the error handler, are dropped without a 
report of their own when they do not fit.
 
 [tabs]
 ====
@@ -650,7 +657,7 @@ Java::
 
from("event:ExchangeCompleted?async=true&asyncQueueSize=100&backpressurePolicy=Drop")
     .log("Exchange completed: ${header.CamelEventExchangeId}");
 
-// Async with Fail policy (fail fast if queue is full)
+// Async with Fail policy (a full queue is reported to the exception handler 
of the consumer)
 from("event:Exchange*?async=true&asyncQueueSize=500&backpressurePolicy=Fail")
     .log("Exchange event: ${header.CamelEventType}");
 ----
diff --git 
a/components/camel-event/src/generated/resources/META-INF/org/apache/camel/component/camelevent/event.json
 
b/components/camel-event/src/generated/resources/META-INF/org/apache/camel/component/camelevent/event.json
index c12c710afccb..b77ee26b7cdc 100644
--- 
a/components/camel-event/src/generated/resources/META-INF/org/apache/camel/component/camelevent/event.json
+++ 
b/components/camel-event/src/generated/resources/META-INF/org/apache/camel/component/camelevent/event.json
@@ -48,7 +48,7 @@
     "async": { "index": 1, "kind": "parameter", "displayName": "Async", 
"group": "consumer", "label": "", "required": false, "type": "boolean", 
"javaType": "boolean", "deprecated": false, "autowired": false, "secret": 
false, "defaultValue": false, "description": "Whether to put the events in a 
bounded queue that a pool of threads routes, so the thread that fires an event 
does not wait for the route. If false, the event is routed on the thread that 
fires it." },
     "asyncPoolSize": { "index": 2, "kind": "parameter", "displayName": "Async 
Pool Size", "group": "consumer", "label": "", "required": false, "type": 
"integer", "javaType": "int", "deprecated": false, "autowired": false, 
"secret": false, "defaultValue": 10, "description": "The number of threads that 
take the events from the queue and route them. Only used when async is true." },
     "asyncQueueSize": { "index": 3, "kind": "parameter", "displayName": "Async 
Queue Size", "group": "consumer", "label": "", "required": false, "type": 
"integer", "javaType": "int", "deprecated": false, "autowired": false, 
"secret": false, "defaultValue": 1000, "description": "The capacity of the 
bounded event queue used when async is enabled. When the queue is full, the 
backpressure policy determines the behavior. Only used when the async option is 
enabled." },
-    "backpressurePolicy": { "index": 4, "kind": "parameter", "displayName": 
"Backpressure Policy", "group": "consumer", "label": "", "required": false, 
"type": "enum", "javaType": 
"org.apache.camel.component.camelevent.BackpressurePolicy", "enum": [ "Block", 
"Drop", "Fail" ], "deprecated": false, "autowired": false, "secret": false, 
"defaultValue": "Block", "description": "What happens to an event when the 
async queue is full. Block makes the thread that fires the event wait for 
space, D [...]
+    "backpressurePolicy": { "index": 4, "kind": "parameter", "displayName": 
"Backpressure Policy", "group": "consumer", "label": "", "required": false, 
"type": "enum", "javaType": 
"org.apache.camel.component.camelevent.BackpressurePolicy", "enum": [ "Block", 
"Drop", "Fail" ], "deprecated": false, "autowired": false, "secret": false, 
"defaultValue": "Block", "description": "What happens to an event when the 
async queue is full. Block makes the thread that fires the event wait for 
space, D [...]
     "batchSize": { "index": 5, "kind": "parameter", "displayName": "Batch 
Size", "group": "consumer", "label": "", "required": false, "type": "integer", 
"javaType": "int", "deprecated": false, "autowired": false, "secret": false, 
"defaultValue": 0, "description": "The number of events to collect into one 
exchange, whose body is a java.util.List of the events. A batch is sent when it 
is full, and every batchTimeout with the events collected so far. With 0 or 1, 
each event is its own excha [...]
     "batchTimeout": { "index": 6, "kind": "parameter", "displayName": "Batch 
Timeout", "group": "consumer", "label": "", "required": false, "type": 
"integer", "javaType": "long", "deprecated": false, "autowired": false, 
"secret": false, "defaultValue": 1000, "description": "The interval in 
milliseconds at which a timer sends the events collected so far, even if the 
batch is not full. Only used when batchSize is greater than 1." },
     "customEventClass": { "index": 7, "kind": "parameter", "displayName": 
"Custom Event Class", "group": "consumer", "label": "", "required": false, 
"type": "string", "javaType": "java.lang.String", "deprecated": false, 
"autowired": false, "secret": false, "description": "The fully qualified name 
of an event class. The consumer drops an event that is not an instance of this 
class, in addition to the event types of the path. Use it with the Custom event 
type to consume only your own event [...]
diff --git a/components/camel-event/src/main/docs/event-component.adoc 
b/components/camel-event/src/main/docs/event-component.adoc
index 93a14c6f930d..afa5a7481e9a 100644
--- a/components/camel-event/src/main/docs/event-component.adoc
+++ b/components/camel-event/src/main/docs/event-component.adoc
@@ -98,6 +98,9 @@ The following event types are available (corresponding to 
`org.apache.camel.spi.
 - `ExchangeSending`
 - `ExchangeSent`
 
+The deprecated `ExchangeAsyncProcessingStarted` type is only received when it 
is named in the event types. A wildcard
+such as `Exchange*` or `*` does not turn it on.
+
 === Step Events
 - `StepStarted`
 - `StepCompleted`
@@ -638,7 +641,11 @@ the `backpressurePolicy` option controls the behavior:
 
 * `Block` (default) — blocks the event notifier thread until space is 
available.
 * `Drop` — silently discards the event.
-* `Fail` — throws an exception.
+* `Fail` — discards the event and passes an `IllegalStateException` to the 
exception handler of the consumer. By
+default it is logged at WARN level; with `bridgeErrorHandler=true` the error 
handler of the route handles it. Camel
+ignores an exception that an event notifier throws, so the event that does not 
fit is never processed and the code
+that fired it does not fail. The events fired while a full queue is reported, 
such as the events of the exchange that
+`bridgeErrorHandler=true` routes to the error handler, are dropped without a 
report of their own when they do not fit.
 
 [tabs]
 ====
@@ -650,7 +657,7 @@ Java::
 
from("event:ExchangeCompleted?async=true&asyncQueueSize=100&backpressurePolicy=Drop")
     .log("Exchange completed: ${header.CamelEventExchangeId}");
 
-// Async with Fail policy (fail fast if queue is full)
+// Async with Fail policy (a full queue is reported to the exception handler 
of the consumer)
 from("event:Exchange*?async=true&asyncQueueSize=500&backpressurePolicy=Fail")
     .log("Exchange event: ${header.CamelEventType}");
 ----
diff --git 
a/components/camel-event/src/main/java/org/apache/camel/component/camelevent/BackpressurePolicy.java
 
b/components/camel-event/src/main/java/org/apache/camel/component/camelevent/BackpressurePolicy.java
index 2b36b0921d92..2634edc823bd 100644
--- 
a/components/camel-event/src/main/java/org/apache/camel/component/camelevent/BackpressurePolicy.java
+++ 
b/components/camel-event/src/main/java/org/apache/camel/component/camelevent/BackpressurePolicy.java
@@ -32,7 +32,10 @@ public enum BackpressurePolicy {
     Drop,
 
     /**
-     * Throw an exception when the queue is full.
+     * Discard the event when the queue is full, and pass an 
IllegalStateException to the exception handler of the
+     * consumer (logged at WARN level by default, or handled by the error 
handler of the route with
+     * bridgeErrorHandler=true). An exception thrown to Camel would only be 
logged and ignored, as Camel ignores the
+     * exceptions of event notifiers.
      */
     Fail
 }
diff --git 
a/components/camel-event/src/main/java/org/apache/camel/component/camelevent/CamelEventConsumer.java
 
b/components/camel-event/src/main/java/org/apache/camel/component/camelevent/CamelEventConsumer.java
index 6bbd33f47277..4f1c2b8f84c2 100644
--- 
a/components/camel-event/src/main/java/org/apache/camel/component/camelevent/CamelEventConsumer.java
+++ 
b/components/camel-event/src/main/java/org/apache/camel/component/camelevent/CamelEventConsumer.java
@@ -50,6 +50,9 @@ public class CamelEventConsumer extends DefaultConsumer {
     private ScheduledExecutorService batchScheduler;
     private final List<CamelEvent> batchBuffer = new ArrayList<>();
     private final ReentrantLock batchBufferLock = new ReentrantLock();
+    // set while this thread reports a full queue (backpressurePolicy=Fail): 
the events fired by the report itself, such
+    // as those of the exchange that bridgeErrorHandler creates, are dropped 
and not reported again
+    private final ThreadLocal<Boolean> reportingFullQueue = new 
ThreadLocal<>();
 
     public CamelEventConsumer(CamelEventEndpoint endpoint, Processor 
processor) {
         super(endpoint, processor);
@@ -209,6 +212,7 @@ public class CamelEventConsumer extends DefaultConsumer {
      * Configures the event notifier to enable only the event categories that 
are needed based on the subscribed event
      * types.
      */
+    @SuppressWarnings("deprecation") // the deprecated 
ExchangeAsyncProcessingStarted type can still be subscribed to
     private void configureEventNotifier() {
         Set<CamelEvent.Type> types = getEndpoint().getEventTypes();
         if (types == null || types.isEmpty()) {
@@ -300,6 +304,14 @@ public class CamelEventConsumer extends DefaultConsumer {
                     // ExchangeSending must also be enabled for the framework 
to generate ExchangeSent events
                     eventNotifier.setIgnoreExchangeSendingEvents(false);
                     break;
+                case ExchangeAsyncProcessingStarted:
+                    // deprecated, and ignored by default by 
EventNotifierSupport: only an endpoint that names the type
+                    // gets these events, a wildcard such as Exchange* does 
not turn them on
+                    if (getEndpoint().getNamedEventTypes().contains(type)) {
+                        eventNotifier.setIgnoreExchangeEvents(false);
+                        
eventNotifier.setIgnoreExchangeAsyncProcessingStartedEvents(false);
+                    }
+                    break;
                 case StepStarted:
                 case StepCompleted:
                 case StepFailed:
@@ -438,14 +450,35 @@ public class CamelEventConsumer extends DefaultConsumer {
                 break;
             case Fail:
                 if (!eventQueue.offer(event)) {
-                    throw new IllegalStateException(
-                            "Event queue full (capacity: " + 
getEndpoint().getAsyncQueueSize()
-                                                    + "), cannot enqueue 
event: " + event.getType());
+                    reportFullQueue(event);
                 }
                 break;
         }
     }
 
+    /**
+     * Reports an event that does not fit in the full queue to the exception 
handler of this consumer, as Camel ignores
+     * (and logs) an exception that an event notifier throws. With 
bridgeErrorHandler=true the report is an exchange
+     * routed to the error handler of the route, which fires events of its own 
in this thread. Those that do not fit in
+     * the queue either are dropped without a report: reporting them would 
fire more events, without end while the queue
+     * stays full.
+     */
+    private void reportFullQueue(CamelEvent event) {
+        if (reportingFullQueue.get() != null) {
+            LOG.debug("Event queue full, dropping event fired while reporting 
a full queue: {}", event.getType());
+            return;
+        }
+        reportingFullQueue.set(Boolean.TRUE);
+        try {
+            handleException("The event is not processed",
+                    new IllegalStateException(
+                            "Event queue full (capacity: " + 
getEndpoint().getAsyncQueueSize()
+                                              + "), cannot enqueue event: " + 
event.getType()));
+        } finally {
+            reportingFullQueue.remove();
+        }
+    }
+
     /**
      * Processes a Camel event by creating an exchange, setting headers, and 
dispatching to the processor.
      */
diff --git 
a/components/camel-event/src/main/java/org/apache/camel/component/camelevent/CamelEventEndpoint.java
 
b/components/camel-event/src/main/java/org/apache/camel/component/camelevent/CamelEventEndpoint.java
index 6c923ee86f69..f47401558f1e 100644
--- 
a/components/camel-event/src/main/java/org/apache/camel/component/camelevent/CamelEventEndpoint.java
+++ 
b/components/camel-event/src/main/java/org/apache/camel/component/camelevent/CamelEventEndpoint.java
@@ -98,8 +98,9 @@ public class CamelEventEndpoint extends DefaultEndpoint {
     private int asyncQueueSize = 1000;
 
     @UriParam(description = "What happens to an event when the async queue is 
full. Block makes the thread that fires the"
-                            + " event wait for space, Drop discards the event 
with a DEBUG log, and Fail throws an exception,"
-                            + " which Camel logs at WARN and ignores, so the 
event is lost.",
+                            + " event wait for space, Drop discards the event 
with a DEBUG log, and Fail discards the event and"
+                            + " passes an IllegalStateException to the 
exception handler of the consumer, which logs it at"
+                            + " WARN by default, or with 
bridgeErrorHandler=true hands it to the error handler of the route.",
               defaultValue = "Block")
     private BackpressurePolicy backpressurePolicy = BackpressurePolicy.Block;
 
@@ -115,6 +116,8 @@ public class CamelEventEndpoint extends DefaultEndpoint {
     private long batchTimeout = 1000;
 
     private Set<CamelEvent.Type> eventTypes;
+    // the types named in events, rather than matched by a wildcard
+    private Set<CamelEvent.Type> namedEventTypes = Collections.emptySet();
     private Set<String> includeValues;
     private Set<String> excludeValues;
     private Class<?> customEventClazz;
@@ -150,17 +153,21 @@ public class CamelEventEndpoint extends DefaultEndpoint {
         // Parse event types (with wildcard support)
         if (events != null && !events.isEmpty()) {
             Set<CamelEvent.Type> types = new LinkedHashSet<>();
+            Set<CamelEvent.Type> named = new LinkedHashSet<>();
             for (String token : events.split(",")) {
                 String name = token.trim();
                 if (!name.isEmpty()) {
                     if (name.contains("*")) {
                         types.addAll(resolveWildcard(name));
                     } else {
-                        types.add(resolveEventType(name));
+                        CamelEvent.Type type = resolveEventType(name);
+                        types.add(type);
+                        named.add(type);
                     }
                 }
             }
             eventTypes = Collections.unmodifiableSet(types);
+            namedEventTypes = Collections.unmodifiableSet(named);
         } else {
             eventTypes = Collections.emptySet();
         }
@@ -305,6 +312,13 @@ public class CamelEventEndpoint extends DefaultEndpoint {
         return eventTypes;
     }
 
+    /**
+     * The event types named in the events option, without the ones only 
matched by a wildcard.
+     */
+    Set<CamelEvent.Type> getNamedEventTypes() {
+        return namedEventTypes;
+    }
+
     public Set<String> getIncludeValues() {
         return includeValues;
     }
diff --git 
a/components/camel-event/src/test/java/org/apache/camel/component/camelevent/EventAsyncProcessingStartedTest.java
 
b/components/camel-event/src/test/java/org/apache/camel/component/camelevent/EventAsyncProcessingStartedTest.java
new file mode 100644
index 000000000000..44cbdbe53045
--- /dev/null
+++ 
b/components/camel-event/src/test/java/org/apache/camel/component/camelevent/EventAsyncProcessingStartedTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.camelevent;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.support.DefaultExchange;
+import org.apache.camel.support.EventHelper;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * An endpoint that subscribes only to the deprecated 
ExchangeAsyncProcessingStarted type gets these events, and a
+ * wildcard does not turn them on.
+ */
+class EventAsyncProcessingStartedTest extends CamelTestSupport {
+
+    @Test
+    @SuppressWarnings("deprecation") // the event type is deprecated, but it 
can still be subscribed to
+    void theOnlySubscribedTypeIsReceived() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:started");
+        mock.expectedMessageCount(1);
+        mock.expectedHeaderReceived(CamelEventConstants.HEADER_EVENT_TYPE, 
"ExchangeAsyncProcessingStarted");
+
+        Exchange exchange = new DefaultExchange(context);
+        EventHelper.notifyExchangeAsyncProcessingStartedEvent(context, 
exchange);
+
+        mock.assertIsSatisfied();
+        // the consumers are not async, so the events are routed before the 
notify returns
+        assertTrue(getMockEndpoint("mock:wildcard").getExchanges().stream()
+                .noneMatch(e -> "ExchangeAsyncProcessingStarted"
+                        
.equals(e.getMessage().getHeader(CamelEventConstants.HEADER_EVENT_TYPE))),
+                "Exchange* got the deprecated event");
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                
from("event:ExchangeAsyncProcessingStarted").to("mock:started");
+                // a wildcard does not turn the deprecated type on
+                from("event:Exchange*").to("mock:wildcard");
+            }
+        };
+    }
+}
diff --git 
a/components/camel-event/src/test/java/org/apache/camel/component/camelevent/EventBackpressureFailBridgeTest.java
 
b/components/camel-event/src/test/java/org/apache/camel/component/camelevent/EventBackpressureFailBridgeTest.java
new file mode 100644
index 000000000000..1115b30f38a9
--- /dev/null
+++ 
b/components/camel-event/src/test/java/org/apache/camel/component/camelevent/EventBackpressureFailBridgeTest.java
@@ -0,0 +1,85 @@
+/*
+ * 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.camelevent;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * With backpressurePolicy=Fail and bridgeErrorHandler=true, a full queue is 
reported by an exchange that goes to the
+ * error handler of the route. That exchange fires exchange events too, which 
Exchange* accepts and which do not fit in
+ * the full queue either. They must not be reported again: each report would 
fire more events in the same thread, until
+ * a StackOverflowError.
+ */
+class EventBackpressureFailBridgeTest extends CamelTestSupport {
+
+    private final AtomicInteger reported = new AtomicInteger();
+    private final CountDownLatch processing = new CountDownLatch(1);
+    private final CountDownLatch release = new CountDownLatch(1);
+
+    @Test
+    // without the guard the sender can be left waiting forever after a 
StackOverflowError
+    @Timeout(value = 60, threadMode = Timeout.ThreadMode.SEPARATE_THREAD)
+    void theReportOfAFullQueueIsNotReportedAgain() throws Exception {
+        // the only consumer thread takes the first event and waits in the 
route, and the next event fills the queue
+        template.sendBody("direct:source", "one");
+        assertTrue(processing.await(20, TimeUnit.SECONDS), "the first event 
was not processed");
+        // the queue is full, so each event of this exchange is reported once
+        template.sendBody("direct:source", "two");
+        release.countDown();
+
+        int count = reported.get();
+        assertTrue(count > 0, "a full queue was not reported to the error 
handler of the route");
+        // a few events for each of the two exchanges, not one more report for 
each event of a report
+        assertTrue(count < 50, "the reports of a full queue were reported 
again (" + count + " reports)");
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                
from("event:Exchange*?async=true&asyncPoolSize=1&asyncQueueSize=1&backpressurePolicy=Fail"
+                     + "&bridgeErrorHandler=true")
+                        .routeId("events")
+                        .onException(IllegalStateException.class).handled(true)
+                        .process(e -> {
+                            // without the guard the reports never stop while 
the queue is full, so the consumer
+                            // thread is let go to end them and fail the test
+                            if (reported.incrementAndGet() >= 50) {
+                                release.countDown();
+                            }
+                        })
+                        .end()
+                        .process(e -> {
+                            processing.countDown();
+                            release.await(20, TimeUnit.SECONDS);
+                        });
+
+                from("direct:source").routeId("source").log("${body}");
+            }
+        };
+    }
+}
diff --git 
a/components/camel-event/src/test/java/org/apache/camel/component/camelevent/EventBackpressureFailTest.java
 
b/components/camel-event/src/test/java/org/apache/camel/component/camelevent/EventBackpressureFailTest.java
new file mode 100644
index 000000000000..f9730b9396e1
--- /dev/null
+++ 
b/components/camel-event/src/test/java/org/apache/camel/component/camelevent/EventBackpressureFailTest.java
@@ -0,0 +1,101 @@
+/*
+ * 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.camelevent;
+
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spi.ExceptionHandler;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.awaitility.Awaitility.await;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * With backpressurePolicy=Fail, an event that does not fit in the full queue 
is reported to the exception handler of
+ * the consumer: an exception thrown to Camel, which fired the event, would 
only be logged and ignored.
+ */
+class EventBackpressureFailTest extends CamelTestSupport {
+
+    private final List<Throwable> handled = new CopyOnWriteArrayList<>();
+    private final CountDownLatch processing = new CountDownLatch(1);
+    private final CountDownLatch release = new CountDownLatch(1);
+
+    @Test
+    void anEventThatDoesNotFitIsReportedToTheExceptionHandler() throws 
Exception {
+        MockEndpoint mock = getMockEndpoint("mock:events");
+        mock.expectedMessageCount(2);
+
+        // the only consumer thread takes the first event and waits in the 
route
+        template.sendBody("direct:source", "one");
+        assertTrue(processing.await(20, TimeUnit.SECONDS), "the first event 
was not processed");
+        // the second one fills the queue of size 1, and the third one does 
not fit
+        template.sendBody("direct:source", "two");
+        template.sendBody("direct:source", "three");
+
+        await().atMost(20, TimeUnit.SECONDS).until(() -> !handled.isEmpty());
+        release.countDown();
+
+        mock.assertIsSatisfied();
+        assertEquals(1, handled.size(), "handled: " + handled);
+        IllegalStateException e = 
assertInstanceOf(IllegalStateException.class, handled.get(0));
+        assertTrue(e.getMessage().contains("Event queue full"), 
e.getMessage());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        context.getRegistry().bind("recorder", new ExceptionHandler() {
+            @Override
+            public void handleException(Throwable exception) {
+                handled.add(exception);
+            }
+
+            @Override
+            public void handleException(String message, Throwable exception) {
+                handled.add(exception);
+            }
+
+            @Override
+            public void handleException(String message, Exchange exchange, 
Throwable exception) {
+                handled.add(exception);
+            }
+        });
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                
from("event:ExchangeCompleted?async=true&asyncPoolSize=1&asyncQueueSize=1&backpressurePolicy=Fail"
+                     + "&include=source&exceptionHandler=#recorder")
+                        .routeId("events")
+                        .process(e -> {
+                            processing.countDown();
+                            release.await(20, TimeUnit.SECONDS);
+                        })
+                        .to("mock:events");
+
+                from("direct:source").routeId("source").log("${body}");
+            }
+        };
+    }
+}
diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index 25708c2cd51b..3593d999c6f3 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -10673,6 +10673,15 @@ Commons Codec 1.23.0 changed how a `quoted-printable` 
part is decoded. The line
 the part are now kept in the decoded payload, as RFC 2045 says. Before, every 
CR and LF was dropped. A soft line break
 written as `=CR` without the LF is now rejected with a `DecoderException`. 
Messages that Camel encodes are not affected.
 
+=== camel-event - backpressurePolicy=Fail reports a full queue to the 
exception handler of the consumer
+
+With `async=true` and `backpressurePolicy=Fail`, an event that did not fit in 
the full queue was thrown as an
+`IllegalStateException` to Camel, which logged it at WARN level and ignored 
it. The consumer now drops the event and
+passes the `IllegalStateException` to its exception handler. By default it is 
still logged at WARN level. With
+`bridgeErrorHandler=true` the error handler of the route handles it, and a 
custom `exceptionHandler` gets it. Code that
+calls `ManagementStrategy.notify()` itself no longer gets the exception. The 
events fired while a full queue is
+reported, such as those of the exchange that `bridgeErrorHandler` routes, are 
dropped without a report of their own.
+
 === camel-file-watch - CamelFileLastModified is the last modified time of the 
file
 
 The `CamelFileLastModified` header is now the last modified time of the file, 
as its documentation says.
diff --git 
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/CamelEventEndpointBuilderFactory.java
 
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/CamelEventEndpointBuilderFactory.java
index b677a0642139..ecf09b372a2a 100644
--- 
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/CamelEventEndpointBuilderFactory.java
+++ 
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/CamelEventEndpointBuilderFactory.java
@@ -148,8 +148,10 @@ public interface CamelEventEndpointBuilderFactory {
         /**
          * What happens to an event when the async queue is full. Block makes
          * the thread that fires the event wait for space, Drop discards the
-         * event with a DEBUG log, and Fail throws an exception, which Camel
-         * logs at WARN and ignores, so the event is lost.
+         * event with a DEBUG log, and Fail discards the event and passes an
+         * IllegalStateException to the exception handler of the consumer, 
which
+         * logs it at WARN by default, or with bridgeErrorHandler=true hands it
+         * to the error handler of the route.
          * 
          * The option is a:
          * 
<code>org.apache.camel.component.camelevent.BackpressurePolicy</code>
@@ -168,8 +170,10 @@ public interface CamelEventEndpointBuilderFactory {
         /**
          * What happens to an event when the async queue is full. Block makes
          * the thread that fires the event wait for space, Drop discards the
-         * event with a DEBUG log, and Fail throws an exception, which Camel
-         * logs at WARN and ignores, so the event is lost.
+         * event with a DEBUG log, and Fail discards the event and passes an
+         * IllegalStateException to the exception handler of the consumer, 
which
+         * logs it at WARN by default, or with bridgeErrorHandler=true hands it
+         * to the error handler of the route.
          * 
          * The option will be converted to a
          * 
<code>org.apache.camel.component.camelevent.BackpressurePolicy</code>

Reply via email to