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 b3c31d40168a CAMEL-27448: camel-debezium - fail the start of the
consumer when the Debezium engine cannot start (#30661)
b3c31d40168a is described below
commit b3c31d40168a24c6b842c54997599fb2ebf643ee
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Nov 23 15:49:20 2026 +0100
CAMEL-27448: camel-debezium - fail the start of the consumer when the
Debezium engine cannot start (#30661)
The consumer ran the embedded engine on its own thread and returned from
doStart at once. When the engine then failed to start (MySQL with
binlog_format=STATEMENT, a lost schema history, a refused TLS connection),
the route stayed started and never ready, and the only sign was the WARN of
the consumer exception handler (CAMEL-24889, CAMEL-24919).
doStart now waits until the engine calls pollingStarted, which it does once
all connector tasks have started and before an initial snapshot is done (the
snapshot runs while the engine polls), or until the completion callback
reports that the engine stopped. A failure meanwhile fails the start with
"Debezium engine failed to start, route: <id> (<uri>): <error of Debezium>"
and the error as the cause, so the route and the application fail to start
(or the supervising route controller starts it again later). An invalid
configuration, which the engine reports while it is built, fails the same
way.
The wait needs no new option: the engine already gives each task
internal.task.management.timeout.ms (40 seconds by default) to start, and
the
consumer waits that long for each task (tasks.max) and once more for the
connector and its offset store, which Debezium does not bound. An engine
that
has not reported back by then leaves the start as it was before: the route
starts with a WARN, the health check stays at its initial state until the
engine polls.
A failure after the start still goes to the consumer exception handler (the
error handler of the route with bridgeErrorHandler=true) and turns the
health
check DOWN. A lock makes sure each failure is either thrown by the start or
handed to the exception handler, never both.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../camel/catalog/docs/debezium-db2-component.adoc | 15 +-
.../catalog/docs/debezium-mongodb-component.adoc | 15 +-
.../catalog/docs/debezium-mysql-component.adoc | 15 +-
.../catalog/docs/debezium-oracle-component.adoc | 15 +-
.../catalog/docs/debezium-postgres-component.adoc | 15 +-
.../catalog/docs/debezium-sqlserver-component.adoc | 15 +-
.../camel/component/debezium/DebeziumConsumer.java | 208 +++++++++++++++++----
...ebeziumConsumerEngineFailureAfterStartTest.java | 184 ++++++++++++++++++
.../DebeziumConsumerEngineFailureTest.java | 56 ++++--
.../debezium/DebeziumConsumerReadinessTest.java | 21 ++-
.../debezium/DebeziumConsumerStartTimeoutTest.java | 136 ++++++++++++++
.../src/main/docs/debezium-db2-component.adoc | 15 +-
.../src/main/docs/debezium-mongodb-component.adoc | 15 +-
.../src/main/docs/debezium-mysql-component.adoc | 15 +-
.../src/main/docs/debezium-oracle-component.adoc | 15 +-
.../src/main/docs/debezium-postgres-component.adoc | 15 +-
.../main/docs/debezium-sqlserver-component.adoc | 15 +-
.../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc | 14 ++
18 files changed, 694 insertions(+), 105 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-db2-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-db2-component.adoc
index bbb52dab3932..eb90d935fd87 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-db2-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-db2-component.adoc
@@ -33,10 +33,17 @@ Before the engine starts polling, the consumer health check
reports the configur
(`DOWN` by default). It reports `UP` once the connector tasks have started and
the engine enters its polling phase,
even if no change events have arrived. This does not indicate that an initial
snapshot has completed.
-If the embedded engine stops with an error, for example because the connector
cannot reach the database or
-the offset store cannot be read, it is not restarted: the route stays started
but receives no further events.
-The failure is reported to the consumer exception handler and turns the route
health check `DOWN`, so it can
-be picked up by a readiness probe.
+The consumer starts when the engine has started the connector tasks, which is
before an initial snapshot is done,
+so a long snapshot does not delay the start. If the engine fails while it
starts, for example because the connector
+cannot reach the database, the database is not set up for change data capture,
or the offset store cannot be read,
+the consumer fails to start, and so does the route, with the error of Debezium
as the cause.
+Debezium gives each task `internal.task.management.timeout.ms` (40 seconds by
default, set with
+`additionalProperties.internal.task.management.timeout.ms`) to start, and the
start waits that long for each task and
+once more for the connector; if the engine has not reported back by then, the
route starts anyway, with a `WARN` in the log.
+
+If the embedded engine stops with an error later, it is not restarted: the
route stays started but receives no further
+events. The failure is reported to the consumer exception handler (with
`bridgeErrorHandler=true`, to the error handler
+of the route) and turns the route health check `DOWN`, so it can be picked up
by a readiness probe.
====
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-mongodb-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-mongodb-component.adoc
index a29c8d3b54dc..bf0653c120d0 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-mongodb-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-mongodb-component.adoc
@@ -39,10 +39,17 @@ Before the engine starts polling, the consumer health check
reports the configur
(`DOWN` by default). It reports `UP` once the connector tasks have started and
the engine enters its polling phase,
even if no change events have arrived. This does not indicate that an initial
snapshot has completed.
-If the embedded engine stops with an error, for example because the connector
cannot reach the database or
-the offset store cannot be read, it is not restarted: the route stays started
but receives no further events.
-The failure is reported to the consumer exception handler and turns the route
health check `DOWN`, so it can
-be picked up by a readiness probe.
+The consumer starts when the engine has started the connector tasks, which is
before an initial snapshot is done,
+so a long snapshot does not delay the start. If the engine fails while it
starts, for example because the connector
+cannot reach the database, the database is not set up for change data capture,
or the offset store cannot be read,
+the consumer fails to start, and so does the route, with the error of Debezium
as the cause.
+Debezium gives each task `internal.task.management.timeout.ms` (40 seconds by
default, set with
+`additionalProperties.internal.task.management.timeout.ms`) to start, and the
start waits that long for each task and
+once more for the connector; if the engine has not reported back by then, the
route starts anyway, with a `WARN` in the log.
+
+If the embedded engine stops with an error later, it is not restarted: the
route stays started but receives no further
+events. The failure is reported to the consumer exception handler (with
`bridgeErrorHandler=true`, to the error handler
+of the route) and turns the route health check `DOWN`, so it can be picked up
by a readiness probe.
====
Maven users will need to add the following dependency to their `pom.xml`
for this component.
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-mysql-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-mysql-component.adoc
index 8f3db6306db0..38996494c21e 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-mysql-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-mysql-component.adoc
@@ -32,10 +32,17 @@ Before the engine starts polling, the consumer health check
reports the configur
(`DOWN` by default). It reports `UP` once the connector tasks have started and
the engine enters its polling phase,
even if no change events have arrived. This does not indicate that an initial
snapshot has completed.
-If the embedded engine stops with an error, for example because the connector
cannot reach the database or
-the offset store cannot be read, it is not restarted: the route stays started
but receives no further events.
-The failure is reported to the consumer exception handler and turns the route
health check `DOWN`, so it can
-be picked up by a readiness probe.
+The consumer starts when the engine has started the connector tasks, which is
before an initial snapshot is done,
+so a long snapshot does not delay the start. If the engine fails while it
starts, for example because the connector
+cannot reach the database, the database is not set up for change data capture,
or the offset store cannot be read,
+the consumer fails to start, and so does the route, with the error of Debezium
as the cause.
+Debezium gives each task `internal.task.management.timeout.ms` (40 seconds by
default, set with
+`additionalProperties.internal.task.management.timeout.ms`) to start, and the
start waits that long for each task and
+once more for the connector; if the engine has not reported back by then, the
route starts anyway, with a `WARN` in the log.
+
+If the embedded engine stops with an error later, it is not restarted: the
route stays started but receives no further
+events. The failure is reported to the consumer exception handler (with
`bridgeErrorHandler=true`, to the error handler
+of the route) and turns the route health check `DOWN`, so it can be picked up
by a readiness probe.
====
Maven users will need to add the following dependency to their `pom.xml`
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-oracle-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-oracle-component.adoc
index 1176215fd839..05793caa08cf 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-oracle-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-oracle-component.adoc
@@ -33,10 +33,17 @@ Before the engine starts polling, the consumer health check
reports the configur
(`DOWN` by default). It reports `UP` once the connector tasks have started and
the engine enters its polling phase,
even if no change events have arrived. This does not indicate that an initial
snapshot has completed.
-If the embedded engine stops with an error, for example because the connector
cannot reach the database or
-the offset store cannot be read, it is not restarted: the route stays started
but receives no further events.
-The failure is reported to the consumer exception handler and turns the route
health check `DOWN`, so it can
-be picked up by a readiness probe.
+The consumer starts when the engine has started the connector tasks, which is
before an initial snapshot is done,
+so a long snapshot does not delay the start. If the engine fails while it
starts, for example because the connector
+cannot reach the database, the database is not set up for change data capture,
or the offset store cannot be read,
+the consumer fails to start, and so does the route, with the error of Debezium
as the cause.
+Debezium gives each task `internal.task.management.timeout.ms` (40 seconds by
default, set with
+`additionalProperties.internal.task.management.timeout.ms`) to start, and the
start waits that long for each task and
+once more for the connector; if the engine has not reported back by then, the
route starts anyway, with a `WARN` in the log.
+
+If the embedded engine stops with an error later, it is not restarted: the
route stays started but receives no further
+events. The failure is reported to the consumer exception handler (with
`bridgeErrorHandler=true`, to the error handler
+of the route) and turns the route health check `DOWN`, so it can be picked up
by a readiness probe.
====
Maven users will need to add the following dependency to their `pom.xml` for
this component.
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-postgres-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-postgres-component.adoc
index 288385b57d43..01b136a9e453 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-postgres-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-postgres-component.adoc
@@ -33,10 +33,17 @@ Before the engine starts polling, the consumer health check
reports the configur
(`DOWN` by default). It reports `UP` once the connector tasks have started and
the engine enters its polling phase,
even if no change events have arrived. This does not indicate that an initial
snapshot has completed.
-If the embedded engine stops with an error, for example because the connector
cannot reach the database or
-the offset store cannot be read, it is not restarted: the route stays started
but receives no further events.
-The failure is reported to the consumer exception handler and turns the route
health check `DOWN`, so it can
-be picked up by a readiness probe.
+The consumer starts when the engine has started the connector tasks, which is
before an initial snapshot is done,
+so a long snapshot does not delay the start. If the engine fails while it
starts, for example because the connector
+cannot reach the database, the database is not set up for change data capture,
or the offset store cannot be read,
+the consumer fails to start, and so does the route, with the error of Debezium
as the cause.
+Debezium gives each task `internal.task.management.timeout.ms` (40 seconds by
default, set with
+`additionalProperties.internal.task.management.timeout.ms`) to start, and the
start waits that long for each task and
+once more for the connector; if the engine has not reported back by then, the
route starts anyway, with a `WARN` in the log.
+
+If the embedded engine stops with an error later, it is not restarted: the
route stays started but receives no further
+events. The failure is reported to the consumer exception handler (with
`bridgeErrorHandler=true`, to the error handler
+of the route) and turns the route health check `DOWN`, so it can be picked up
by a readiness probe.
====
Maven users will need to add the following dependency to their `pom.xml` for
this component.
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-sqlserver-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-sqlserver-component.adoc
index 9f11c676af6a..e301141b3d5b 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-sqlserver-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-sqlserver-component.adoc
@@ -32,10 +32,17 @@ Before the engine starts polling, the consumer health check
reports the configur
(`DOWN` by default). It reports `UP` once the connector tasks have started and
the engine enters its polling phase,
even if no change events have arrived. This does not indicate that an initial
snapshot has completed.
-If the embedded engine stops with an error, for example because the connector
cannot reach the database or
-the offset store cannot be read, it is not restarted: the route stays started
but receives no further events.
-The failure is reported to the consumer exception handler and turns the route
health check `DOWN`, so it can
-be picked up by a readiness probe.
+The consumer starts when the engine has started the connector tasks, which is
before an initial snapshot is done,
+so a long snapshot does not delay the start. If the engine fails while it
starts, for example because the connector
+cannot reach the database, the database is not set up for change data capture,
or the offset store cannot be read,
+the consumer fails to start, and so does the route, with the error of Debezium
as the cause.
+Debezium gives each task `internal.task.management.timeout.ms` (40 seconds by
default, set with
+`additionalProperties.internal.task.management.timeout.ms`) to start, and the
start waits that long for each task and
+once more for the connector; if the engine has not reported back by then, the
route starts anyway, with a `WARN` in the log.
+
+If the embedded engine stops with an error later, it is not restarted: the
route stays started but receives no further
+events. The failure is reported to the consumer exception handler (with
`bridgeErrorHandler=true`, to the error handler
+of the route) and turns the route health check `DOWN`, so it can be picked up
by a readiness probe.
====
Maven users will need to add the following dependency to their `pom.xml`
diff --git
a/components/camel-debezium/camel-debezium-common/camel-debezium-common-component/src/main/java/org/apache/camel/component/debezium/DebeziumConsumer.java
b/components/camel-debezium/camel-debezium-common/camel-debezium-common-component/src/main/java/org/apache/camel/component/debezium/DebeziumConsumer.java
index eccc69dfd7b1..aa727c199e92 100644
---
a/components/camel-debezium/camel-debezium-common/camel-debezium-common-component/src/main/java/org/apache/camel/component/debezium/DebeziumConsumer.java
+++
b/components/camel-debezium/camel-debezium-common/camel-debezium-common-component/src/main/java/org/apache/camel/component/debezium/DebeziumConsumer.java
@@ -16,9 +16,13 @@
*/
package org.apache.camel.component.debezium;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
+import java.util.concurrent.TimeUnit;
+import io.debezium.config.Configuration;
import io.debezium.embedded.Connect;
+import io.debezium.embedded.async.AsyncEngineConfig;
import io.debezium.engine.ChangeEvent;
import io.debezium.engine.DebeziumEngine;
import org.apache.camel.Exchange;
@@ -35,6 +39,8 @@ public class DebeziumConsumer extends DefaultConsumer {
private static final Logger LOG =
LoggerFactory.getLogger(DebeziumConsumer.class);
+ private static final String TASKS_MAX = "tasks.max";
+
private final DebeziumEndpoint endpoint;
private final EmbeddedDebeziumConfiguration configuration;
@@ -44,6 +50,13 @@ public class DebeziumConsumer extends DefaultConsumer {
private volatile boolean engineStopped;
private volatile boolean engineReady;
+ // guards waitingForStart and startFailure, so that an engine failure is
either thrown by doStart or handed to the
+ // exception handler, never both and never neither
+ private final Object startLock = new Object();
+ private boolean waitingForStart;
+ private Throwable startFailure;
+ private volatile CountDownLatch startLatch;
+
public DebeziumConsumer(DebeziumEndpoint endpoint, Processor processor) {
super(endpoint, processor);
this.endpoint = endpoint;
@@ -66,23 +79,132 @@ public class DebeziumConsumer extends DefaultConsumer {
super.doStart();
- // start a single threaded pool to monitor events
- executorService = endpoint.createExecutor(this);
-
- // create engine
- dbzEngine = createDbzEngine();
-
- // submit task to the thread pool
- executorService.submit(
- () -> {
- try {
- dbzEngine.run();
- } catch (Throwable e) {
- // the engine reports its own failures through the
completion callback and is not
- // expected to throw, so this is only a safety net
- onEngineCompleted(false, e.getMessage(), e);
- }
- });
+ final Configuration dbzConfiguration =
configuration.createDebeziumConfiguration();
+ final CountDownLatch latch = new CountDownLatch(1);
+ synchronized (startLock) {
+ startLatch = latch;
+ startFailure = null;
+ waitingForStart = true;
+ }
+
+ boolean started = false;
+ try {
+ // start a single threaded pool to monitor events
+ executorService = endpoint.createExecutor(this);
+
+ // create engine, which reports an invalid configuration to the
completion callback and throws
+ try {
+ dbzEngine = createDbzEngine(dbzConfiguration);
+ } catch (RuntimeException e) {
+ final Throwable failure = endWaitingForStart();
+ throw failedToStart(failure != null ? failure : e);
+ }
+
+ // submit task to the thread pool
+ executorService.submit(
+ () -> {
+ try {
+ dbzEngine.run();
+ } catch (Throwable e) {
+ // the engine reports its own failures through the
completion callback and is not
+ // expected to throw, so this is only a safety net
+ onEngineCompleted(false, e.getMessage(), e);
+ }
+ });
+
+ awaitEngineStarted(latch, startTimeout(dbzConfiguration));
+ started = true;
+ } finally {
+ if (!started) {
+ endWaitingForStart();
+ stopExecutor();
+ }
+ }
+ }
+
+ /**
+ * Ends the start: from now on a failure of the engine goes to the
exception handler.
+ *
+ * @return the failure of the engine that the start has to throw, or
<tt>null</tt>
+ */
+ private Throwable endWaitingForStart() {
+ synchronized (startLock) {
+ waitingForStart = false;
+ final Throwable answer = startFailure;
+ startFailure = null;
+ return answer;
+ }
+ }
+
+ /**
+ * Waits until the engine has started its connector tasks or has stopped,
and fails the start of this consumer when
+ * the engine failed meanwhile. The engine calls pollingStarted once all
its tasks have started, which is before an
+ * initial snapshot is done, as the snapshot runs while the engine polls,
so a long snapshot does not delay the
+ * start. The engine bounds the start of each task by its
<tt>internal.task.management.timeout.ms</tt>, so the wait
+ * only ends by timeout when the engine hangs before that, for example
while it opens its offset store; the consumer
+ * then starts as it did before: the health check stays at its initial
state until the engine polls, and a later
+ * failure goes to the exception handler and the health check.
+ */
+ private void awaitEngineStarted(CountDownLatch latch, long timeoutMillis) {
+ boolean done = false;
+ boolean interrupted = false;
+ try {
+ done = latch.await(timeoutMillis, TimeUnit.MILLISECONDS);
+ } catch (InterruptedException e) {
+ interrupted = true;
+ Thread.currentThread().interrupt();
+ }
+
+ final Throwable failure = endWaitingForStart();
+ if (failure != null) {
+ throw failedToStart(failure);
+ }
+ if (interrupted) {
+ LOG.debug("Interrupted while waiting for the Debezium engine to
start, route: {}", getRouteId());
+ } else if (!done) {
+ LOG.warn("Debezium engine has not reported that it started within
{} ms, route: {} ({}) starts anyway, and a"
+ + " later failure of the engine is reported to the
exception handler and the health check",
+ timeoutMillis, getRouteId(),
URISupport.sanitizeUri(endpoint.getEndpointUri()));
+ } else if (engineStopped) {
+ LOG.debug("Debezium engine stopped while starting, without a
failure, route: {}", getRouteId());
+ }
+ }
+
+ private RuntimeCamelException failedToStart(Throwable failure) {
+ return new RuntimeCamelException(
+ "Debezium engine failed to start, route: " + getRouteId() + "
("
+ +
URISupport.sanitizeUri(endpoint.getEndpointUri()) + "): " + describe(failure),
+ failure);
+ }
+
+ /**
+ * How long the start waits for the engine: the engine waits up to
<tt>internal.task.management.timeout.ms</tt> for
+ * each task to start, and the same again is given to starting the
connector and its offset store before that.
+ */
+ static long startTimeout(Configuration dbzConfiguration) {
+ final long taskTimeout =
dbzConfiguration.getLong(AsyncEngineConfig.TASK_MANAGEMENT_TIMEOUT_MS.name(),
+ AsyncEngineConfig.DEFAULT_TASK_MANAGEMENT_TIMEOUT_MS);
+ final int tasks = Math.max(1, dbzConfiguration.getInteger(TASKS_MAX,
1));
+ return Math.max(1, taskTimeout) * (tasks + 1L);
+ }
+
+ private static String describe(Throwable failure) {
+ Throwable root = failure;
+ while (root.getCause() != null && root.getCause() != root) {
+ root = root.getCause();
+ }
+ final String message = failure.getMessage() != null ?
failure.getMessage() : failure.getClass().getName();
+ if (root != failure && root.getMessage() != null &&
!message.contains(root.getMessage())) {
+ return message + " (caused by: " + root.getMessage() + ")";
+ }
+ return message;
+ }
+
+ private void stopExecutor() {
+ if (executorService != null) {
+
getEndpoint().getCamelContext().getExecutorServiceManager().shutdownGraceful(executorService);
+ executorService = null;
+ }
}
@Override
@@ -103,7 +225,7 @@ public class DebeziumConsumer extends DefaultConsumer {
}
// shutdown the thread pool gracefully
-
getEndpoint().getCamelContext().getExecutorServiceManager().shutdownGraceful(executorService);
+ stopExecutor();
// shutdown camel consumer
super.doStop();
@@ -121,14 +243,20 @@ public class DebeziumConsumer extends DefaultConsumer {
return engineReady;
}
- private DebeziumEngine<ChangeEvent<SourceRecord, SourceRecord>>
createDbzEngine() {
+ private DebeziumEngine<ChangeEvent<SourceRecord, SourceRecord>>
createDbzEngine(Configuration dbzConfiguration) {
return DebeziumEngine.create(Connect.class)
-
.using(configuration.createDebeziumConfiguration().asProperties())
+ .using(dbzConfiguration.asProperties())
.using(this::onEngineCompleted)
.using(new DebeziumEngine.ConnectorCallback() {
@Override
public void pollingStarted() {
+ // called once all the tasks have started, before an
initial snapshot is done; the start
+ // has succeeded, so a failure from now on goes to the
exception handler
+ synchronized (startLock) {
+ waitingForStart = false;
+ }
engineReady = true;
+ startLatch.countDown();
}
@Override
@@ -144,24 +272,40 @@ public class DebeziumConsumer extends DefaultConsumer {
/**
* Called by the embedded engine once it has stopped, either because it
was closed or because it failed. The engine
- * does not restart itself, so a failure means this consumer is
permanently dead while the route still reports as
- * started, hence the failure is reported to the exception handler and
kept for the health check.
+ * does not restart itself. A failure while the consumer starts fails that
start; a later failure means this
+ * consumer is permanently dead while the route still reports as started,
hence the failure is reported to the
+ * exception handler and kept for the health check.
*/
private void onEngineCompleted(boolean success, String message, Throwable
error) {
- engineStopped = true;
+ final boolean reportToExceptionHandler;
+ final Throwable cause;
+ synchronized (startLock) {
+ engineStopped = true;
+ if (success) {
+ cause = null;
+ reportToExceptionHandler = false;
+ } else {
+ cause = error != null ? error : new
RuntimeCamelException(message);
+ engineFailure = cause;
+ if (waitingForStart) {
+ // the consumer is starting, so doStart throws the failure
instead
+ startFailure = cause;
+ reportToExceptionHandler = false;
+ } else {
+ reportToExceptionHandler = true;
+ }
+ }
+ }
+ startLatch.countDown();
if (success) {
LOG.debug("Debezium engine stopped: {}", message);
- return;
+ } else if (reportToExceptionHandler) {
+ getExceptionHandler().handleException(
+ "Debezium engine has failed and stopped, no more change
events are consumed from "
+ +
URISupport.sanitizeUri(endpoint.getEndpointUri()),
+ cause);
}
-
- final Throwable cause = error != null ? error : new
RuntimeCamelException(message);
- engineFailure = cause;
-
- getExceptionHandler().handleException(
- "Debezium engine has failed and stopped, no more change events
are consumed from "
- +
URISupport.sanitizeUri(endpoint.getEndpointUri()),
- cause);
}
private void onEventListener(final ChangeEvent<SourceRecord, SourceRecord>
event) {
diff --git
a/components/camel-debezium/camel-debezium-common/camel-debezium-common-component/src/test/java/org/apache/camel/component/debezium/DebeziumConsumerEngineFailureAfterStartTest.java
b/components/camel-debezium/camel-debezium-common/camel-debezium-common-component/src/test/java/org/apache/camel/component/debezium/DebeziumConsumerEngineFailureAfterStartTest.java
new file mode 100644
index 000000000000..dd7a609698da
--- /dev/null
+++
b/components/camel-debezium/camel-debezium-common/camel-debezium-common-component/src/test/java/org/apache/camel/component/debezium/DebeziumConsumerEngineFailureAfterStartTest.java
@@ -0,0 +1,184 @@
+/*
+ * 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.debezium;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.ServiceStatus;
+import org.apache.camel.builder.RouteBuilder;
+import
org.apache.camel.component.debezium.configuration.FileConnectorEmbeddedDebeziumConfiguration;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.health.HealthCheck;
+import org.apache.camel.spi.ExceptionHandler;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.apache.kafka.connect.connector.Task;
+import org.apache.kafka.connect.file.FileStreamSourceConnector;
+import org.apache.kafka.connect.file.FileStreamSourceTask;
+import org.apache.kafka.connect.source.SourceRecord;
+import org.junit.jupiter.api.AfterEach;
+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.assertTrue;
+
+/**
+ * A failure of the engine after it has started cannot fail the start of the
route any more, so it goes to the exception
+ * handler of the consumer and turns the health check DOWN.
+ */
+class DebeziumConsumerEngineFailureAfterStartTest extends CamelTestSupport {
+
+ private static final String ROUTE_ID = "debezium-failing-after-start";
+ private static final String BRIDGED_ROUTE_ID =
"debezium-failing-after-start-bridged";
+ private static final Path TEST_FILE_PATH
+ = Paths.get("target/data",
"camel-debezium-failure-after-start-input.txt").toAbsolutePath();
+ private static final Path TEST_OFFSET_STORE_PATH
+ = Paths.get("target/data",
"camel-debezium-failure-after-start-offset-store.dat").toAbsolutePath();
+
+ @Test
+ void
engineFailureAfterTheStartIsReportedToTheExceptionHandlerAndTheHealthCheck()
throws Exception {
+ final DebeziumConsumer consumer = (DebeziumConsumer)
context.getRoute(ROUTE_ID).getConsumer();
+
+ final CapturingExceptionHandler exceptionHandler = new
CapturingExceptionHandler();
+ consumer.setExceptionHandler(exceptionHandler);
+
+ // the engine starts its task, so the start of the route succeeds; the
task fails when it polls
+ context.getRouteController().startRoute(ROUTE_ID);
+ assertEquals(ServiceStatus.Started,
context.getRouteController().getRouteStatus(ROUTE_ID));
+
+ assertTrue(exceptionHandler.latch.await(30, TimeUnit.SECONDS),
+ "the engine failure should be handed to the consumer exception
handler");
+ assertTrue(exceptionHandler.message.get().startsWith("Debezium engine
has failed and stopped"),
+ exceptionHandler.message.get());
+
+ final HealthCheck healthCheck = consumer.getHealthCheck();
+ await().atMost(10, TimeUnit.SECONDS)
+ .untilAsserted(() -> assertEquals(HealthCheck.State.DOWN,
healthCheck.call().getState(),
+ "a consumer whose engine has died should not report as
healthy"));
+ assertEquals(1, exceptionHandler.count.get(), "the failure should be
reported once");
+ }
+
+ @Test
+ void
engineFailureAfterTheStartGoesToTheErrorHandlerOfTheRouteWithBridgeErrorHandler()
throws Exception {
+ final MockEndpoint failures = getMockEndpoint("mock:engineFailure");
+ failures.expectedMessageCount(1);
+
failures.message(0).exchangeProperty(Exchange.EXCEPTION_CAUGHT).isInstanceOf(IllegalStateException.class);
+
+ context.getRouteController().startRoute(BRIDGED_ROUTE_ID);
+
+ failures.assertIsSatisfied();
+
assertTrue(failures.getExchanges().get(0).getMessage().getBody(String.class)
+ .startsWith("Debezium engine has failed and stopped"));
+ }
+
+ @AfterEach
+ void cleanup() throws IOException {
+ Files.deleteIfExists(TEST_FILE_PATH);
+ Files.deleteIfExists(TEST_OFFSET_STORE_PATH);
+ }
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ final CamelContext context = super.createCamelContext();
+ Files.createDirectories(TEST_FILE_PATH.getParent());
+ Files.deleteIfExists(TEST_FILE_PATH);
+ Files.deleteIfExists(TEST_OFFSET_STORE_PATH);
+ Files.createFile(TEST_FILE_PATH);
+
+ final FileConnectorEmbeddedDebeziumConfiguration configuration = new
FileConnectorEmbeddedDebeziumConfiguration() {
+ @Override
+ protected Class<?> configureConnectorClass() {
+ return FailingPollConnector.class;
+ }
+ };
+ configuration.setName("failure_after_start");
+ configuration.setTopicConfig("failure_after_start");
+ configuration.setTestFilePath(TEST_FILE_PATH);
+
configuration.setOffsetStorageFileName(TEST_OFFSET_STORE_PATH.toString());
+
+ final DebeziumTestComponent component = new
DebeziumTestComponent(context);
+ component.setConfiguration(configuration);
+ context.addComponent("debezium", component);
+ context.disableJMX();
+ return context;
+ }
+
+ @Override
+ protected RoutesBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ // started by the test, so that the exception handler is in
place before the engine runs
+ from("debezium:dummy").routeId(ROUTE_ID).autoStartup(false)
+ .to("mock:result");
+
+
from("debezium:bridged?bridgeErrorHandler=true").routeId(BRIDGED_ROUTE_ID).autoStartup(false)
+
.onException(Exception.class).handled(true).to("mock:engineFailure").end()
+ .to("mock:result");
+ }
+ };
+ }
+
+ public static class FailingPollConnector extends FileStreamSourceConnector
{
+ @Override
+ public Class<? extends Task> taskClass() {
+ return FailingPollTask.class;
+ }
+ }
+
+ public static class FailingPollTask extends FileStreamSourceTask {
+ @Override
+ public List<SourceRecord> poll() {
+ throw new IllegalStateException("The source went away");
+ }
+ }
+
+ private static final class CapturingExceptionHandler implements
ExceptionHandler {
+
+ private final CountDownLatch latch = new CountDownLatch(1);
+ private final AtomicReference<String> message = new
AtomicReference<>();
+ private final AtomicInteger count = new AtomicInteger();
+
+ @Override
+ public void handleException(Throwable exception) {
+ handleException(null, null, exception);
+ }
+
+ @Override
+ public void handleException(String message, Throwable exception) {
+ handleException(message, null, exception);
+ }
+
+ @Override
+ public void handleException(String message, Exchange exchange,
Throwable exception) {
+ count.incrementAndGet();
+ this.message.compareAndSet(null, message);
+ latch.countDown();
+ }
+ }
+}
diff --git
a/components/camel-debezium/camel-debezium-common/camel-debezium-common-component/src/test/java/org/apache/camel/component/debezium/DebeziumConsumerEngineFailureTest.java
b/components/camel-debezium/camel-debezium-common/camel-debezium-common-component/src/test/java/org/apache/camel/component/debezium/DebeziumConsumerEngineFailureTest.java
index be9dab502ad3..3e2fa268eadb 100644
---
a/components/camel-debezium/camel-debezium-common/camel-debezium-common-component/src/test/java/org/apache/camel/component/debezium/DebeziumConsumerEngineFailureTest.java
+++
b/components/camel-debezium/camel-debezium-common/camel-debezium-common-component/src/test/java/org/apache/camel/component/debezium/DebeziumConsumerEngineFailureTest.java
@@ -21,17 +21,17 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
+import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
+import io.debezium.config.Configuration;
import io.debezium.util.IoUtil;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.RoutesBuilder;
+import org.apache.camel.ServiceStatus;
import org.apache.camel.builder.RouteBuilder;
import
org.apache.camel.component.debezium.configuration.FileConnectorEmbeddedDebeziumConfiguration;
-import org.apache.camel.health.HealthCheck;
import org.apache.camel.spi.ExceptionHandler;
import org.apache.camel.test.junit6.CamelTestSupport;
import org.junit.jupiter.api.AfterEach;
@@ -40,12 +40,16 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
- * The embedded engine runs on its own thread and reports a failure only
through its completion callback, so without
- * that callback a connector that cannot start leaves the route started,
healthy and silent.
+ * The embedded engine runs on its own thread and reports a failure only
through its completion callback. A failure
+ * while the engine starts, here an offset store it cannot read, must fail the
start of the route instead of leaving the
+ * route started and silent.
*/
public class DebeziumConsumerEngineFailureTest extends CamelTestSupport {
@@ -77,22 +81,44 @@ public class DebeziumConsumerEngineFailureTest extends
CamelTestSupport {
}
@Test
- void engineFailureIsReportedToTheExceptionHandlerAndTheHealthCheck()
throws Exception {
+ void engineFailureWhileStartingFailsTheStartOfTheRoute() throws Exception {
final DebeziumConsumer consumer = (DebeziumConsumer)
context.getRoute(ROUTE_ID).getConsumer();
final CapturingExceptionHandler exceptionHandler = new
CapturingExceptionHandler();
consumer.setExceptionHandler(exceptionHandler);
- context.getRouteController().startRoute(ROUTE_ID);
+ final Exception e = assertThrows(Exception.class, () ->
context.getRouteController().startRoute(ROUTE_ID));
+
+ final Throwable failure = findStartFailure(e);
+ assertNotNull(failure, "the start should fail with the failure of the
engine, but got: " + e);
+ assertTrue(failure.getMessage().contains("route: " + ROUTE_ID),
failure.getMessage());
+ assertNotNull(failure.getCause(), "the failure of the engine should be
the cause");
+
assertTrue(failure.getMessage().contains(failure.getCause().getMessage()),
+ "the message should carry the failure of the engine: " +
failure.getMessage());
+ // the offset store cannot be read: the root cause from Kafka Connect
is in the message
+ assertTrue(failure.getMessage().contains("invalid stream header"),
failure.getMessage());
+
+ assertNotEquals(ServiceStatus.Started,
context.getRouteController().getRouteStatus(ROUTE_ID));
+ assertNull(exceptionHandler.captured.get(),
+ "a failure that fails the start should not also be handed to
the exception handler");
+ assertNotNull(consumer.getEngineFailure(), "the failure should be kept
for the health check");
+ }
- assertTrue(exceptionHandler.latch.await(30, TimeUnit.SECONDS),
- "the engine failure should be handed to the consumer exception
handler");
- assertNotNull(exceptionHandler.captured.get(), "the failure cause
should be reported");
+ @Test
+ void theStartWaitsAsLongAsTheEngineWaitsForItsTasks() {
+ assertEquals(80000L,
DebeziumConsumer.startTimeout(Configuration.empty()),
+ "by default 40 seconds for the task and as much for the
connector");
+ assertEquals(4000L, DebeziumConsumer.startTimeout(Configuration.from(
+ Map.of("internal.task.management.timeout.ms", "1000",
"tasks.max", "3"))));
+ }
- final HealthCheck healthCheck = consumer.getHealthCheck();
- assertNotNull(healthCheck, "the consumer should expose a health
check");
- assertEquals(HealthCheck.State.DOWN, healthCheck.call().getState(),
- "a consumer whose engine has died should not report as
healthy");
+ private static Throwable findStartFailure(Throwable e) {
+ for (Throwable t = e; t != null; t = t.getCause()) {
+ if (t.getMessage() != null && t.getMessage().startsWith("Debezium
engine failed to start")) {
+ return t;
+ }
+ }
+ return null;
}
@Override
@@ -132,7 +158,6 @@ public class DebeziumConsumerEngineFailureTest extends
CamelTestSupport {
private static final class CapturingExceptionHandler implements
ExceptionHandler {
- private final CountDownLatch latch = new CountDownLatch(1);
private final AtomicReference<Throwable> captured = new
AtomicReference<>();
@Override
@@ -148,7 +173,6 @@ public class DebeziumConsumerEngineFailureTest extends
CamelTestSupport {
@Override
public void handleException(String message, Exchange exchange,
Throwable exception) {
captured.compareAndSet(null, exception);
- latch.countDown();
}
}
}
diff --git
a/components/camel-debezium/camel-debezium-common/camel-debezium-common-component/src/test/java/org/apache/camel/component/debezium/DebeziumConsumerReadinessTest.java
b/components/camel-debezium/camel-debezium-common/camel-debezium-common-component/src/test/java/org/apache/camel/component/debezium/DebeziumConsumerReadinessTest.java
index 2b21da39101d..de1405d9b660 100644
---
a/components/camel-debezium/camel-debezium-common/camel-debezium-common-component/src/test/java/org/apache/camel/component/debezium/DebeziumConsumerReadinessTest.java
+++
b/components/camel-debezium/camel-debezium-common/camel-debezium-common-component/src/test/java/org/apache/camel/component/debezium/DebeziumConsumerReadinessTest.java
@@ -20,6 +20,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
+import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -38,7 +39,6 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
-import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
@@ -64,17 +64,19 @@ class DebeziumConsumerReadinessTest extends
CamelTestSupport {
for (int i = 0; i < 2; i++) {
starting = new CountDownLatch(1);
release = new CountDownLatch(1);
- consumer.start();
+ // the start waits until the engine has started its task, so it
runs on another thread here
+ CompletableFuture<Void> start =
CompletableFuture.runAsync(consumer::start);
try {
assertTrue(starting.await(30, TimeUnit.SECONDS), "the source
task should enter startup");
+ assertFalse(start.isDone(), "the start should wait for the
source task to start");
assertEquals(initialState, check.call().getState());
check.setEnabled(false);
assertEquals(HealthCheck.State.UNKNOWN,
check.call().getState());
check.setEnabled(true);
release.countDown();
- await().atMost(30,
TimeUnit.SECONDS).until(consumer::isEngineReady);
- await().atMost(30, TimeUnit.SECONDS)
- .untilAsserted(() ->
assertEquals(HealthCheck.State.UP, check.call().getState()));
+ start.get(30, TimeUnit.SECONDS);
+ assertTrue(consumer.isEngineReady(), "the start should return
once the engine polls");
+ assertEquals(HealthCheck.State.UP, check.call().getState());
assertEquals(0,
getMockEndpoint("mock:result").getReceivedCounter(),
"readiness must not require a change event");
} finally {
@@ -89,8 +91,9 @@ class DebeziumConsumerReadinessTest extends CamelTestSupport {
DebeziumConsumer consumer = (DebeziumConsumer)
context.getRoute("readiness").getConsumer();
starting = new CountDownLatch(1);
release = new CountDownLatch(1);
- // no setHealthCheck() here: starting the consumer runs doBuild(),
which creates the check itself
- consumer.start();
+ // no setHealthCheck() here: starting the consumer runs doBuild(),
which creates the check itself; the start
+ // waits until the engine has started its task, so it runs on another
thread here
+ CompletableFuture<Void> start =
CompletableFuture.runAsync(consumer::start);
try {
assertTrue(starting.await(30, TimeUnit.SECONDS), "the source task
should enter startup");
HealthCheck check = consumer.getHealthCheck();
@@ -100,8 +103,8 @@ class DebeziumConsumerReadinessTest extends
CamelTestSupport {
// DOWN is the registry initial state stubbed in
createCamelContext, read when doBuild() ran
assertEquals(HealthCheck.State.DOWN, check.call().getState());
release.countDown();
- await().atMost(30, TimeUnit.SECONDS)
- .untilAsserted(() -> assertEquals(HealthCheck.State.UP,
check.call().getState()));
+ start.get(30, TimeUnit.SECONDS);
+ assertEquals(HealthCheck.State.UP, check.call().getState());
} finally {
release.countDown();
consumer.stop();
diff --git
a/components/camel-debezium/camel-debezium-common/camel-debezium-common-component/src/test/java/org/apache/camel/component/debezium/DebeziumConsumerStartTimeoutTest.java
b/components/camel-debezium/camel-debezium-common/camel-debezium-common-component/src/test/java/org/apache/camel/component/debezium/DebeziumConsumerStartTimeoutTest.java
new file mode 100644
index 000000000000..c119e3d7a2c5
--- /dev/null
+++
b/components/camel-debezium/camel-debezium-common/camel-debezium-common-component/src/test/java/org/apache/camel/component/debezium/DebeziumConsumerStartTimeoutTest.java
@@ -0,0 +1,136 @@
+/*
+ * 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.debezium;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.ServiceStatus;
+import org.apache.camel.builder.RouteBuilder;
+import
org.apache.camel.component.debezium.configuration.FileConnectorEmbeddedDebeziumConfiguration;
+import org.apache.camel.health.HealthCheck;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.apache.kafka.connect.file.FileStreamSourceConnector;
+import org.junit.jupiter.api.AfterEach;
+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.assertFalse;
+
+/**
+ * An engine that does not report within the time it gives itself to start its
tasks must not hang the start of the
+ * route: the consumer starts as it did before, and reports ready once the
engine polls.
+ */
+class DebeziumConsumerStartTimeoutTest extends CamelTestSupport {
+
+ private static final String ROUTE_ID = "debezium-slow-connector";
+ private static volatile CountDownLatch release;
+
+ private Path input;
+ private Path offsets;
+
+ @Test
+ void theStartDoesNotWaitForeverForAnEngineThatDoesNotReport() throws
Exception {
+ release = new CountDownLatch(1);
+ final DebeziumConsumer consumer = (DebeziumConsumer)
context.getRoute(ROUTE_ID).getConsumer();
+
+ // the connector does not start until released, and the start waits 2
x 500 ms
+ context.getRouteController().startRoute(ROUTE_ID);
+ try {
+ assertEquals(ServiceStatus.Started,
context.getRouteController().getRouteStatus(ROUTE_ID));
+ assertFalse(consumer.isEngineReady(), "the engine has not started
its tasks yet");
+ assertEquals(HealthCheck.State.DOWN,
consumer.getHealthCheck().call().getState());
+
+ release.countDown();
+ await().atMost(30,
TimeUnit.SECONDS).until(consumer::isEngineReady);
+ assertEquals(HealthCheck.State.UP,
consumer.getHealthCheck().call().getState());
+ } finally {
+ release.countDown();
+ }
+ }
+
+ @AfterEach
+ void cleanup() throws Exception {
+ if (release != null) {
+ release.countDown();
+ }
+ context.stop();
+ Files.deleteIfExists(input);
+ Files.deleteIfExists(offsets);
+ }
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ final CamelContext context = super.createCamelContext();
+ input = Paths.get("target/data",
"camel-debezium-start-timeout-input.txt").toAbsolutePath();
+ offsets = Paths.get("target/data",
"camel-debezium-start-timeout-offset-store.dat").toAbsolutePath();
+ Files.createDirectories(input.getParent());
+ Files.deleteIfExists(input);
+ Files.deleteIfExists(offsets);
+ Files.createFile(input);
+
+ final FileConnectorEmbeddedDebeziumConfiguration configuration = new
FileConnectorEmbeddedDebeziumConfiguration() {
+ @Override
+ protected Class<?> configureConnectorClass() {
+ return SlowConnector.class;
+ }
+ };
+ configuration.setName("start_timeout");
+ configuration.setTopicConfig("start_timeout");
+ configuration.setTestFilePath(input);
+ configuration.setOffsetStorageFileName(offsets.toString());
+
configuration.setAdditionalProperties(Map.of("internal.task.management.timeout.ms",
"500"));
+
+ final DebeziumTestComponent component = new
DebeziumTestComponent(context);
+ component.setConfiguration(configuration);
+ context.addComponent("debezium", component);
+ context.disableJMX();
+ return context;
+ }
+
+ @Override
+ protected RoutesBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+
from("debezium:dummy").routeId(ROUTE_ID).autoStartup(false).to("mock:result");
+ }
+ };
+ }
+
+ public static class SlowConnector extends FileStreamSourceConnector {
+ @Override
+ public void start(Map<String, String> props) {
+ try {
+ if (!release.await(30, TimeUnit.SECONDS)) {
+ throw new IllegalStateException("Timed out waiting to
release the connector startup");
+ }
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new IllegalStateException(e);
+ }
+ super.start(props);
+ }
+ }
+}
diff --git
a/components/camel-debezium/camel-debezium-db2/src/main/docs/debezium-db2-component.adoc
b/components/camel-debezium/camel-debezium-db2/src/main/docs/debezium-db2-component.adoc
index bbb52dab3932..eb90d935fd87 100644
---
a/components/camel-debezium/camel-debezium-db2/src/main/docs/debezium-db2-component.adoc
+++
b/components/camel-debezium/camel-debezium-db2/src/main/docs/debezium-db2-component.adoc
@@ -33,10 +33,17 @@ Before the engine starts polling, the consumer health check
reports the configur
(`DOWN` by default). It reports `UP` once the connector tasks have started and
the engine enters its polling phase,
even if no change events have arrived. This does not indicate that an initial
snapshot has completed.
-If the embedded engine stops with an error, for example because the connector
cannot reach the database or
-the offset store cannot be read, it is not restarted: the route stays started
but receives no further events.
-The failure is reported to the consumer exception handler and turns the route
health check `DOWN`, so it can
-be picked up by a readiness probe.
+The consumer starts when the engine has started the connector tasks, which is
before an initial snapshot is done,
+so a long snapshot does not delay the start. If the engine fails while it
starts, for example because the connector
+cannot reach the database, the database is not set up for change data capture,
or the offset store cannot be read,
+the consumer fails to start, and so does the route, with the error of Debezium
as the cause.
+Debezium gives each task `internal.task.management.timeout.ms` (40 seconds by
default, set with
+`additionalProperties.internal.task.management.timeout.ms`) to start, and the
start waits that long for each task and
+once more for the connector; if the engine has not reported back by then, the
route starts anyway, with a `WARN` in the log.
+
+If the embedded engine stops with an error later, it is not restarted: the
route stays started but receives no further
+events. The failure is reported to the consumer exception handler (with
`bridgeErrorHandler=true`, to the error handler
+of the route) and turns the route health check `DOWN`, so it can be picked up
by a readiness probe.
====
diff --git
a/components/camel-debezium/camel-debezium-mongodb/src/main/docs/debezium-mongodb-component.adoc
b/components/camel-debezium/camel-debezium-mongodb/src/main/docs/debezium-mongodb-component.adoc
index a29c8d3b54dc..bf0653c120d0 100644
---
a/components/camel-debezium/camel-debezium-mongodb/src/main/docs/debezium-mongodb-component.adoc
+++
b/components/camel-debezium/camel-debezium-mongodb/src/main/docs/debezium-mongodb-component.adoc
@@ -39,10 +39,17 @@ Before the engine starts polling, the consumer health check
reports the configur
(`DOWN` by default). It reports `UP` once the connector tasks have started and
the engine enters its polling phase,
even if no change events have arrived. This does not indicate that an initial
snapshot has completed.
-If the embedded engine stops with an error, for example because the connector
cannot reach the database or
-the offset store cannot be read, it is not restarted: the route stays started
but receives no further events.
-The failure is reported to the consumer exception handler and turns the route
health check `DOWN`, so it can
-be picked up by a readiness probe.
+The consumer starts when the engine has started the connector tasks, which is
before an initial snapshot is done,
+so a long snapshot does not delay the start. If the engine fails while it
starts, for example because the connector
+cannot reach the database, the database is not set up for change data capture,
or the offset store cannot be read,
+the consumer fails to start, and so does the route, with the error of Debezium
as the cause.
+Debezium gives each task `internal.task.management.timeout.ms` (40 seconds by
default, set with
+`additionalProperties.internal.task.management.timeout.ms`) to start, and the
start waits that long for each task and
+once more for the connector; if the engine has not reported back by then, the
route starts anyway, with a `WARN` in the log.
+
+If the embedded engine stops with an error later, it is not restarted: the
route stays started but receives no further
+events. The failure is reported to the consumer exception handler (with
`bridgeErrorHandler=true`, to the error handler
+of the route) and turns the route health check `DOWN`, so it can be picked up
by a readiness probe.
====
Maven users will need to add the following dependency to their `pom.xml`
for this component.
diff --git
a/components/camel-debezium/camel-debezium-mysql/src/main/docs/debezium-mysql-component.adoc
b/components/camel-debezium/camel-debezium-mysql/src/main/docs/debezium-mysql-component.adoc
index 8f3db6306db0..38996494c21e 100644
---
a/components/camel-debezium/camel-debezium-mysql/src/main/docs/debezium-mysql-component.adoc
+++
b/components/camel-debezium/camel-debezium-mysql/src/main/docs/debezium-mysql-component.adoc
@@ -32,10 +32,17 @@ Before the engine starts polling, the consumer health check
reports the configur
(`DOWN` by default). It reports `UP` once the connector tasks have started and
the engine enters its polling phase,
even if no change events have arrived. This does not indicate that an initial
snapshot has completed.
-If the embedded engine stops with an error, for example because the connector
cannot reach the database or
-the offset store cannot be read, it is not restarted: the route stays started
but receives no further events.
-The failure is reported to the consumer exception handler and turns the route
health check `DOWN`, so it can
-be picked up by a readiness probe.
+The consumer starts when the engine has started the connector tasks, which is
before an initial snapshot is done,
+so a long snapshot does not delay the start. If the engine fails while it
starts, for example because the connector
+cannot reach the database, the database is not set up for change data capture,
or the offset store cannot be read,
+the consumer fails to start, and so does the route, with the error of Debezium
as the cause.
+Debezium gives each task `internal.task.management.timeout.ms` (40 seconds by
default, set with
+`additionalProperties.internal.task.management.timeout.ms`) to start, and the
start waits that long for each task and
+once more for the connector; if the engine has not reported back by then, the
route starts anyway, with a `WARN` in the log.
+
+If the embedded engine stops with an error later, it is not restarted: the
route stays started but receives no further
+events. The failure is reported to the consumer exception handler (with
`bridgeErrorHandler=true`, to the error handler
+of the route) and turns the route health check `DOWN`, so it can be picked up
by a readiness probe.
====
Maven users will need to add the following dependency to their `pom.xml`
diff --git
a/components/camel-debezium/camel-debezium-oracle/src/main/docs/debezium-oracle-component.adoc
b/components/camel-debezium/camel-debezium-oracle/src/main/docs/debezium-oracle-component.adoc
index 1176215fd839..05793caa08cf 100644
---
a/components/camel-debezium/camel-debezium-oracle/src/main/docs/debezium-oracle-component.adoc
+++
b/components/camel-debezium/camel-debezium-oracle/src/main/docs/debezium-oracle-component.adoc
@@ -33,10 +33,17 @@ Before the engine starts polling, the consumer health check
reports the configur
(`DOWN` by default). It reports `UP` once the connector tasks have started and
the engine enters its polling phase,
even if no change events have arrived. This does not indicate that an initial
snapshot has completed.
-If the embedded engine stops with an error, for example because the connector
cannot reach the database or
-the offset store cannot be read, it is not restarted: the route stays started
but receives no further events.
-The failure is reported to the consumer exception handler and turns the route
health check `DOWN`, so it can
-be picked up by a readiness probe.
+The consumer starts when the engine has started the connector tasks, which is
before an initial snapshot is done,
+so a long snapshot does not delay the start. If the engine fails while it
starts, for example because the connector
+cannot reach the database, the database is not set up for change data capture,
or the offset store cannot be read,
+the consumer fails to start, and so does the route, with the error of Debezium
as the cause.
+Debezium gives each task `internal.task.management.timeout.ms` (40 seconds by
default, set with
+`additionalProperties.internal.task.management.timeout.ms`) to start, and the
start waits that long for each task and
+once more for the connector; if the engine has not reported back by then, the
route starts anyway, with a `WARN` in the log.
+
+If the embedded engine stops with an error later, it is not restarted: the
route stays started but receives no further
+events. The failure is reported to the consumer exception handler (with
`bridgeErrorHandler=true`, to the error handler
+of the route) and turns the route health check `DOWN`, so it can be picked up
by a readiness probe.
====
Maven users will need to add the following dependency to their `pom.xml` for
this component.
diff --git
a/components/camel-debezium/camel-debezium-postgres/src/main/docs/debezium-postgres-component.adoc
b/components/camel-debezium/camel-debezium-postgres/src/main/docs/debezium-postgres-component.adoc
index 288385b57d43..01b136a9e453 100644
---
a/components/camel-debezium/camel-debezium-postgres/src/main/docs/debezium-postgres-component.adoc
+++
b/components/camel-debezium/camel-debezium-postgres/src/main/docs/debezium-postgres-component.adoc
@@ -33,10 +33,17 @@ Before the engine starts polling, the consumer health check
reports the configur
(`DOWN` by default). It reports `UP` once the connector tasks have started and
the engine enters its polling phase,
even if no change events have arrived. This does not indicate that an initial
snapshot has completed.
-If the embedded engine stops with an error, for example because the connector
cannot reach the database or
-the offset store cannot be read, it is not restarted: the route stays started
but receives no further events.
-The failure is reported to the consumer exception handler and turns the route
health check `DOWN`, so it can
-be picked up by a readiness probe.
+The consumer starts when the engine has started the connector tasks, which is
before an initial snapshot is done,
+so a long snapshot does not delay the start. If the engine fails while it
starts, for example because the connector
+cannot reach the database, the database is not set up for change data capture,
or the offset store cannot be read,
+the consumer fails to start, and so does the route, with the error of Debezium
as the cause.
+Debezium gives each task `internal.task.management.timeout.ms` (40 seconds by
default, set with
+`additionalProperties.internal.task.management.timeout.ms`) to start, and the
start waits that long for each task and
+once more for the connector; if the engine has not reported back by then, the
route starts anyway, with a `WARN` in the log.
+
+If the embedded engine stops with an error later, it is not restarted: the
route stays started but receives no further
+events. The failure is reported to the consumer exception handler (with
`bridgeErrorHandler=true`, to the error handler
+of the route) and turns the route health check `DOWN`, so it can be picked up
by a readiness probe.
====
Maven users will need to add the following dependency to their `pom.xml` for
this component.
diff --git
a/components/camel-debezium/camel-debezium-sqlserver/src/main/docs/debezium-sqlserver-component.adoc
b/components/camel-debezium/camel-debezium-sqlserver/src/main/docs/debezium-sqlserver-component.adoc
index 9f11c676af6a..e301141b3d5b 100644
---
a/components/camel-debezium/camel-debezium-sqlserver/src/main/docs/debezium-sqlserver-component.adoc
+++
b/components/camel-debezium/camel-debezium-sqlserver/src/main/docs/debezium-sqlserver-component.adoc
@@ -32,10 +32,17 @@ Before the engine starts polling, the consumer health check
reports the configur
(`DOWN` by default). It reports `UP` once the connector tasks have started and
the engine enters its polling phase,
even if no change events have arrived. This does not indicate that an initial
snapshot has completed.
-If the embedded engine stops with an error, for example because the connector
cannot reach the database or
-the offset store cannot be read, it is not restarted: the route stays started
but receives no further events.
-The failure is reported to the consumer exception handler and turns the route
health check `DOWN`, so it can
-be picked up by a readiness probe.
+The consumer starts when the engine has started the connector tasks, which is
before an initial snapshot is done,
+so a long snapshot does not delay the start. If the engine fails while it
starts, for example because the connector
+cannot reach the database, the database is not set up for change data capture,
or the offset store cannot be read,
+the consumer fails to start, and so does the route, with the error of Debezium
as the cause.
+Debezium gives each task `internal.task.management.timeout.ms` (40 seconds by
default, set with
+`additionalProperties.internal.task.management.timeout.ms`) to start, and the
start waits that long for each task and
+once more for the connector; if the engine has not reported back by then, the
route starts anyway, with a `WARN` in the log.
+
+If the embedded engine stops with an error later, it is not restarted: the
route stays started but receives no further
+events. The failure is reported to the consumer exception handler (with
`bridgeErrorHandler=true`, to the error handler
+of the route) and turns the route health check `DOWN`, so it can be picked up
by a readiness probe.
====
Maven users will need to add the following dependency to their `pom.xml`
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 24daf3ab7fef..1144eda36feb 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
@@ -3925,6 +3925,20 @@ The `Struct` to `Map` type converter now gives a
`LinkedHashMap` in the order of
of the columns of the table), nested `Struct` values included, so the JSON of
the `Map` has the columns in that order.
Before, it was a `HashMap` with no defined order.
+=== camel-debezium - the route fails to start when the Debezium engine cannot
start
+
+A `debezium-*` consumer now waits, when it starts, until the Debezium engine
has started the connector tasks (which is
+before an initial snapshot is done), and fails to start when the engine fails
meanwhile, with the error of Debezium as
+the cause: for example a database that cannot be reached or refuses the TLS
connection, a MySQL server with
+`binlog_format=STATEMENT`, or a lost schema history. The route, and so the
application, then fails to start (with the
+supervising route controller, the route is started again later). Before, the
route started, was never ready, and the
+only sign of the failure was a WARN in the log. The start waits as long as
Debezium waits for the tasks to start
+(`internal.task.management.timeout.ms`, 40 seconds by default, for each task
and once more for the connector); if the
+engine has not reported back by then, the route starts as before, with a WARN
in the log.
+
+A failure of the engine after it has started is still reported to the consumer
exception handler (to the error handler
+of the route with `bridgeErrorHandler=true`) and turns the health check of the
route `DOWN`.
+
=== camel-debezium-mysql - a signed TINYINT column is a Byte
Debezium has been upgraded to 3.7.0.Final, which maps a signed MySQL `TINYINT`
column to the Kafka Connect `INT8`