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

Croway 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 63e3046cea9e CAMEL-27117: camel-direct, camel-kamelet - the no 
consumer error says why there is no consumer and how long the producer waited 
(#30284)
63e3046cea9e is described below

commit 63e3046cea9e17163e875a792163515bc06b1c48
Author: Federico Mariani <[email protected]>
AuthorDate: Tue Nov 17 17:02:37 2026 +0100

    CAMEL-27117: camel-direct, camel-kamelet - the no consumer error says why 
there is no consumer and how long the producer waited (#30284)
    
    * CAMEL-27117: camel-direct, camel-kamelet - the no consumer error says 
which route consumes from the endpoint and its status, or that none does with a 
close name, and how long the producer waited
    
    * CAMEL-27117: camel-direct - the direct page says a similar endpoint name 
and REST service
---
 .../camel/catalog/docs/direct-component.adoc       |  47 ++++-
 .../src/main/docs/direct-component.adoc            |  47 ++++-
 .../camel/component/direct/DirectEndpoint.java     |   7 +
 .../camel/component/direct/DirectProducer.java     |  72 +++++++-
 .../camel/component/kamelet/KameletProducer.java   |  33 +++-
 .../kamelet/KameletProducerNoConsumerTest.java     | 107 ++++++++++++
 .../direct/DirectNoConsumerMessageTest.java        | 194 +++++++++++++++++++++
 7 files changed, 500 insertions(+), 7 deletions(-)

diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/direct-component.adoc
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/direct-component.adoc
index b130a1778b95..0bfbc2628c9d 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/direct-component.adoc
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/direct-component.adoc
@@ -41,6 +41,51 @@ include::partial$component-endpoint-options.adoc[]
 include::partial$component-endpoint-headers.adoc[]
 // component options: END
 
+== Usage
+
+The route that consumes from a direct endpoint runs in the thread of the 
producer, and the producer continues with the
+message as that route leaves it.
+A direct endpoint is therefore called like a method: from Java code, call a 
route with `requestBody` of a
+xref:manual::producertemplate.adoc[ProducerTemplate] to get its reply:
+
+[source,java]
+----
+String reply = template.requestBody("direct:processOrder", order, 
String.class);
+----
+
+=== One route per endpoint
+
+Only one route can consume from a direct endpoint.
+A second route that consumes from the same endpoint fails to start with
+`Multiple consumers for the same endpoint is not allowed: 
direct://processOrder`.
+To send a message to several routes, use the 
xref:eips:multicast-eip.adoc[Multicast] or
+xref:eips:recipientList-eip.adoc[Recipient List] EIP, or the 
xref:seda-component.adoc[SEDA] component with
+`multipleConsumers=true`.
+
+=== When no route consumes from the endpoint
+
+When no started route consumes from the endpoint, the producer waits up to 
`timeout` milliseconds (30 seconds by
+default) for one to start, for example while Camel starts or reloads routes.
+Then the exchange fails with `DirectConsumerNotAvailableException`.
+Its message starts with `No consumers available on endpoint:`, and says which 
route consumes from the endpoint and its
+status, or that no route does (with a similar endpoint name when there is 
one), and how long the producer waited.
+
+Set `block=false` to fail without waiting, or `failIfNoConsumers=false` to 
drop the message (logged at `DEBUG`) instead
+of failing.
+
+The common causes are:
+
+* The route is not loaded. With Spring Boot, the `RouteBuilder` class must be 
a Spring bean, for example annotated with
+  `@Component`. With Camel Quarkus, a `RouteBuilder` class from another jar is 
only found when that jar has a Jandex
+  index. XML and YAML routes must be in the files Camel loads routes from.
+* The producer and the route use a different name, for example because of a 
typo.
+* The route is stopped or suspended, or it did not start because of 
`autoStartup=false`.
+* The route is in another CamelContext: a direct endpoint only reaches the 
routes of its own CamelContext.
+* With the xref:manual::rest-dsl.adoc[Rest DSL], a direct route that only one 
REST service calls is inlined into that
+  service (the `inlineRoutes` option, enabled by default), so other routes 
cannot call it.
+
+NOTE: A `ProducerTemplate` sends only once the CamelContext has started. 
Sending earlier, for example from a Spring
+`@PostConstruct` method, fails with another exception, before any direct 
endpoint is called.
 
 == Examples
 
@@ -53,7 +98,7 @@ Java::
 [source,java]
 ----
 from("activemq:queue:order.in")
-    .to("bean:orderServer?method=validate")
+    .to("bean:orderService?method=validate")
     .to("direct:processOrder");
 
 from("direct:processOrder")
diff --git a/components/camel-direct/src/main/docs/direct-component.adoc 
b/components/camel-direct/src/main/docs/direct-component.adoc
index b130a1778b95..0bfbc2628c9d 100644
--- a/components/camel-direct/src/main/docs/direct-component.adoc
+++ b/components/camel-direct/src/main/docs/direct-component.adoc
@@ -41,6 +41,51 @@ include::partial$component-endpoint-options.adoc[]
 include::partial$component-endpoint-headers.adoc[]
 // component options: END
 
+== Usage
+
+The route that consumes from a direct endpoint runs in the thread of the 
producer, and the producer continues with the
+message as that route leaves it.
+A direct endpoint is therefore called like a method: from Java code, call a 
route with `requestBody` of a
+xref:manual::producertemplate.adoc[ProducerTemplate] to get its reply:
+
+[source,java]
+----
+String reply = template.requestBody("direct:processOrder", order, 
String.class);
+----
+
+=== One route per endpoint
+
+Only one route can consume from a direct endpoint.
+A second route that consumes from the same endpoint fails to start with
+`Multiple consumers for the same endpoint is not allowed: 
direct://processOrder`.
+To send a message to several routes, use the 
xref:eips:multicast-eip.adoc[Multicast] or
+xref:eips:recipientList-eip.adoc[Recipient List] EIP, or the 
xref:seda-component.adoc[SEDA] component with
+`multipleConsumers=true`.
+
+=== When no route consumes from the endpoint
+
+When no started route consumes from the endpoint, the producer waits up to 
`timeout` milliseconds (30 seconds by
+default) for one to start, for example while Camel starts or reloads routes.
+Then the exchange fails with `DirectConsumerNotAvailableException`.
+Its message starts with `No consumers available on endpoint:`, and says which 
route consumes from the endpoint and its
+status, or that no route does (with a similar endpoint name when there is 
one), and how long the producer waited.
+
+Set `block=false` to fail without waiting, or `failIfNoConsumers=false` to 
drop the message (logged at `DEBUG`) instead
+of failing.
+
+The common causes are:
+
+* The route is not loaded. With Spring Boot, the `RouteBuilder` class must be 
a Spring bean, for example annotated with
+  `@Component`. With Camel Quarkus, a `RouteBuilder` class from another jar is 
only found when that jar has a Jandex
+  index. XML and YAML routes must be in the files Camel loads routes from.
+* The producer and the route use a different name, for example because of a 
typo.
+* The route is stopped or suspended, or it did not start because of 
`autoStartup=false`.
+* The route is in another CamelContext: a direct endpoint only reaches the 
routes of its own CamelContext.
+* With the xref:manual::rest-dsl.adoc[Rest DSL], a direct route that only one 
REST service calls is inlined into that
+  service (the `inlineRoutes` option, enabled by default), so other routes 
cannot call it.
+
+NOTE: A `ProducerTemplate` sends only once the CamelContext has started. 
Sending earlier, for example from a Spring
+`@PostConstruct` method, fails with another exception, before any direct 
endpoint is called.
 
 == Examples
 
@@ -53,7 +98,7 @@ Java::
 [source,java]
 ----
 from("activemq:queue:order.in")
-    .to("bean:orderServer?method=validate")
+    .to("bean:orderService?method=validate")
     .to("direct:processOrder");
 
 from("direct:processOrder")
diff --git 
a/components/camel-direct/src/main/java/org/apache/camel/component/direct/DirectEndpoint.java
 
b/components/camel-direct/src/main/java/org/apache/camel/component/direct/DirectEndpoint.java
index d40853506ee5..1058150a6a47 100644
--- 
a/components/camel-direct/src/main/java/org/apache/camel/component/direct/DirectEndpoint.java
+++ 
b/components/camel-direct/src/main/java/org/apache/camel/component/direct/DirectEndpoint.java
@@ -82,6 +82,13 @@ public class DirectEndpoint extends DefaultEndpoint {
         return answer;
     }
 
+    /**
+     * The key of the consumer in the component: the endpoint uri without its 
options.
+     */
+    String getKey() {
+        return key;
+    }
+
     @Deprecated
     public DirectConsumer getConsumer() throws InterruptedException {
         return component.getConsumer(key, block, timeout);
diff --git 
a/components/camel-direct/src/main/java/org/apache/camel/component/direct/DirectProducer.java
 
b/components/camel-direct/src/main/java/org/apache/camel/component/direct/DirectProducer.java
index 12be998da2f0..6e5a34c5df90 100644
--- 
a/components/camel-direct/src/main/java/org/apache/camel/component/direct/DirectProducer.java
+++ 
b/components/camel-direct/src/main/java/org/apache/camel/component/direct/DirectProducer.java
@@ -16,11 +16,19 @@
  */
 package org.apache.camel.component.direct;
 
+import java.util.LinkedHashMap;
+import java.util.Map;
+
 import org.apache.camel.AsyncCallback;
+import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePropertyKey;
+import org.apache.camel.Route;
 import org.apache.camel.RouteStoppingException;
+import org.apache.camel.ServiceStatus;
 import org.apache.camel.support.DefaultAsyncProducer;
+import org.apache.camel.util.ArtifactUtils;
+import org.apache.camel.util.StringHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -55,7 +63,7 @@ public class DirectProducer extends DefaultAsyncProducer {
         DirectConsumer consumer = getConsumer();
         if (consumer == null) {
             if (endpoint.isFailIfNoConsumers()) {
-                throw new DirectConsumerNotAvailableException("No consumers 
available on endpoint: " + endpoint, exchange);
+                throw new 
DirectConsumerNotAvailableException(noConsumerMessage(), exchange);
             } else {
                 LOG.debug("message ignored, no consumers available on 
endpoint: {}", endpoint);
             }
@@ -76,8 +84,7 @@ public class DirectProducer extends DefaultAsyncProducer {
             DirectConsumer consumer = getConsumer();
             if (consumer == null) {
                 if (endpoint.isFailIfNoConsumers()) {
-                    exchange.setException(new 
DirectConsumerNotAvailableException(
-                            "No consumers available on endpoint: " + endpoint, 
exchange));
+                    exchange.setException(new 
DirectConsumerNotAvailableException(noConsumerMessage(), exchange));
                 } else {
                     LOG.debug("message ignored, no consumers available on 
endpoint: {}", endpoint);
                 }
@@ -123,6 +130,65 @@ public class DirectProducer extends DefaultAsyncProducer {
         }
     }
 
+    /**
+     * The message when there is no consumer: the text users and tools search 
for, then why there is none (the route
+     * that consumes from the endpoint and its status, or that no route does, 
with a close name), how long the producer
+     * waited, and the options that change this.
+     */
+    private String noConsumerMessage() {
+        CamelContext context = endpoint.getCamelContext();
+        StringBuilder sb = new StringBuilder(256);
+        sb.append("No consumers available on endpoint: 
").append(endpoint).append(". ");
+
+        String routeId = null;
+        boolean rest = false;
+        // the other direct endpoints routes consume from, by name, for a 
close name
+        Map<String, String> others = new LinkedHashMap<>();
+        for (Route route : context.getRoutes()) {
+            rest |= route.isCreatedByRestDsl();
+            if (route.getEndpoint() instanceof DirectEndpoint direct && 
direct.getComponent() == component) {
+                if (key.equals(direct.getKey())) {
+                    routeId = route.getRouteId();
+                } else {
+                    others.put(name(direct.getKey()), direct.getKey());
+                }
+            }
+        }
+        if (routeId != null) {
+            ServiceStatus status = 
context.getRouteController().getRouteStatus(routeId);
+            sb.append("Route ").append(routeId).append(" in CamelContext 
").append(context.getName())
+                    .append(" consumes from it");
+            if (status != null) {
+                sb.append(" and is ").append(status);
+            }
+            sb.append(". ");
+        } else {
+            sb.append("No route in CamelContext 
").append(context.getName()).append(" consumes from it");
+            String closest = ArtifactUtils.closest(name(key), others.keySet());
+            if (closest != null) {
+                sb.append(", did you mean 
").append(others.get(closest)).append("? ");
+            } else {
+                sb.append(". ");
+            }
+            if (rest && context.getRestConfiguration().isInlineRoutes()) {
+                sb.append("A direct route that only one REST DSL service calls 
is inlined into that service, and no other"
+                          + " route can call it (inlineRoutes in the rest 
configuration). ");
+            }
+        }
+        if (block && timeout > 0) {
+            sb.append("The producer waited ").append(timeout).append(" millis 
for a consumer");
+        } else {
+            sb.append("The producer did not wait for a consumer");
+        }
+        sb.append(" (see the block, timeout and failIfNoConsumers options)");
+        return sb.toString();
+    }
+
+    private static String name(String key) {
+        // direct://foo is foo
+        return StringHelper.after(key, "://", key);
+    }
+
     /**
      * Gets the consumer, which is looked up again when it has been added or 
removed (such as when its route is
      * suspended or stopped) since it was looked up last.
diff --git 
a/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletProducer.java
 
b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletProducer.java
index ee9296a87284..3ea1fb117c92 100644
--- 
a/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletProducer.java
+++ 
b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletProducer.java
@@ -18,8 +18,10 @@ package org.apache.camel.component.kamelet;
 
 import org.apache.camel.AsyncCallback;
 import org.apache.camel.AsyncProcessor;
+import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.Route;
+import org.apache.camel.ServiceStatus;
 import org.apache.camel.spi.ManagementStrategy;
 import org.apache.camel.spi.RouteIdAware;
 import org.apache.camel.support.DefaultAsyncProducer;
@@ -62,8 +64,7 @@ final class KameletProducer extends DefaultAsyncProducer 
implements RouteIdAware
             final KameletConsumer consumer = getConsumer();
             if (consumer == null) {
                 if (endpoint.isFailIfNoConsumers()) {
-                    exchange.setException(new 
KameletConsumerNotAvailableException(
-                            "No consumers available on endpoint: " + endpoint, 
exchange));
+                    exchange.setException(new 
KameletConsumerNotAvailableException(noConsumerMessage(), exchange));
                 } else {
                     LOG.debug("Exchange ignored, no consumers available on 
endpoint: {}", endpoint);
                 }
@@ -148,6 +149,34 @@ final class KameletProducer extends DefaultAsyncProducer 
implements RouteIdAware
         }
     }
 
+    /**
+     * The message when there is no consumer: the text users and tools search 
for, then why there is none (the route of
+     * the Kamelet and its status, or that there is no such route), how long 
the producer waited, and the options that
+     * change this.
+     */
+    private String noConsumerMessage() {
+        CamelContext context = endpoint.getCamelContext();
+        String id = endpoint.getRouteId();
+        StringBuilder sb = new StringBuilder(256);
+        sb.append("No consumers available on endpoint: 
").append(endpoint).append(". ");
+        ServiceStatus status = context.getRoute(id) != null ? 
context.getRouteController().getRouteStatus(id) : null;
+        if (status != null) {
+            sb.append("Route ").append(id).append(" of Kamelet 
").append(endpoint.getTemplateId())
+                    .append(" in CamelContext 
").append(context.getName()).append(" consumes from it and is ")
+                    .append(status).append(". ");
+        } else {
+            sb.append("CamelContext ").append(context.getName()).append(" has 
no route ").append(id)
+                    .append(" of Kamelet 
").append(endpoint.getTemplateId()).append(". ");
+        }
+        if (block && timeout > 0) {
+            sb.append("The producer waited ").append(timeout).append(" millis 
for a consumer");
+        } else {
+            sb.append("The producer did not wait for a consumer");
+        }
+        sb.append(" (see the block, timeout and failIfNoConsumers options)");
+        return sb.toString();
+    }
+
     /**
      * Gets the consumer, which is looked up again when it has been added or 
removed (such as when its route is
      * suspended or stopped) since it was looked up last.
diff --git 
a/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletProducerNoConsumerTest.java
 
b/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletProducerNoConsumerTest.java
new file mode 100644
index 000000000000..bab712b06530
--- /dev/null
+++ 
b/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletProducerNoConsumerTest.java
@@ -0,0 +1,107 @@
+/*
+ * 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.kamelet;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.catchThrowableOfType;
+
+/**
+ * The message of {@link KameletConsumerNotAvailableException} says why there 
is no consumer: the route of the Kamelet
+ * and its status, or that there is no such route, how long the producer 
waited, and the options to change it.
+ */
+@Timeout(20)
+public class KameletProducerNoConsumerTest extends CamelTestSupport {
+
+    @Test
+    public void testKameletRouteStopped() throws Exception {
+        context.getRouteController().stopRoute("echo");
+
+        assertThat(failure("direct:start"))
+                .startsWith("No consumers available on endpoint: 
kamelet:echo/echo?timeout=100. ")
+                .contains("Route echo of Kamelet echo in CamelContext " + 
context.getName()
+                          + " consumes from it and is Stopped")
+                .contains("The producer waited 100 millis for a consumer")
+                .contains("block, timeout and failIfNoConsumers options");
+    }
+
+    @Test
+    public void testKameletRouteRemoved() throws Exception {
+        context.getRouteController().stopRoute("echo");
+        context.removeRoute("echo");
+
+        assertThat(failure("direct:start"))
+                .startsWith("No consumers available on endpoint: 
kamelet:echo/echo?timeout=100. ")
+                .contains("CamelContext " + context.getName() + " has no route 
echo of Kamelet echo")
+                .contains("The producer waited 100 millis for a consumer");
+    }
+
+    @Test
+    public void testProducerDoesNotWait() throws Exception {
+        context.getRouteController().stopRoute("quiet");
+
+        assertThat(failure("direct:no-wait"))
+                .startsWith("No consumers available on endpoint: 
kamelet:echo/quiet?block=false. ")
+                .contains("Route quiet of Kamelet echo in CamelContext " + 
context.getName()
+                          + " consumes from it and is Stopped")
+                .contains("The producer did not wait for a consumer")
+                .doesNotContain("waited");
+    }
+
+    @Test
+    public void testKameletRouteStarted() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:kamelet");
+        mock.expectedBodiesReceived("Hello World");
+
+        template.sendBody("direct:start", "Hello World");
+
+        mock.assertIsSatisfied();
+    }
+
+    private String failure(String uri) {
+        CamelExecutionException e
+                = catchThrowableOfType(CamelExecutionException.class, () -> 
template.sendBody(uri, "Hello World"));
+        assertThat(e).as("The exchange should fail").isNotNull();
+        
assertThat(e.getCause()).isInstanceOf(KameletConsumerNotAvailableException.class);
+        return e.getCause().getMessage();
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                routeTemplate("echo")
+                        .from("kamelet:source")
+                        .to("mock:kamelet");
+
+                from("direct:start")
+                        .to("kamelet:echo/echo?timeout=100");
+
+                from("direct:no-wait")
+                        .to("kamelet:echo/quiet?block=false");
+            }
+        };
+    }
+}
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/direct/DirectNoConsumerMessageTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/direct/DirectNoConsumerMessageTest.java
new file mode 100644
index 000000000000..9117089b9d1e
--- /dev/null
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/direct/DirectNoConsumerMessageTest.java
@@ -0,0 +1,194 @@
+/*
+ * 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.direct;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.rest.DummyRestConsumerFactory;
+import org.apache.camel.spi.Registry;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The message of {@link DirectConsumerNotAvailableException} says why there 
is no consumer: the route that consumes
+ * from the endpoint and its status, or that no route does, how long the 
producer waited, and the options to change it.
+ */
+@Timeout(20)
+public class DirectNoConsumerMessageTest extends ContextTestSupport {
+
+    private static final String PREFIX = "No consumers available on endpoint: 
";
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    @Override
+    protected Registry createCamelRegistry() throws Exception {
+        Registry registry = super.createCamelRegistry();
+        registry.bind("dummy-rest", new DummyRestConsumerFactory());
+        return registry;
+    }
+
+    @Test
+    public void testNoRouteConsumesFromTheEndpoint() throws Exception {
+        addReportRoutes();
+
+        String message = failure("direct:reportReport?timeout=100");
+
+        assertTrue(message.startsWith(PREFIX + 
"direct://reportReport?timeout=100. "), message);
+        assertTrue(message.contains("No route in CamelContext " + 
context.getName() + " consumes from it"), message);
+        assertTrue(message.contains("did you mean direct://reportRoute?"), 
message);
+        assertTrue(message.contains("The producer waited 100 millis for a 
consumer"), message);
+        assertTrue(message.contains("block, timeout and failIfNoConsumers 
options"), message);
+        assertFalse(message.contains("inlineRoutes"), message);
+    }
+
+    @Test
+    public void testNoRouteConsumesFromTheEndpointSynchronous() throws 
Exception {
+        addReportRoutes();
+
+        String message = 
failure("direct:reportReport?timeout=100&synchronous=true");
+
+        assertTrue(message.startsWith(PREFIX + 
"direct://reportReport?synchronous=true&timeout=100. "), message);
+        assertTrue(message.contains("No route in CamelContext " + 
context.getName() + " consumes from it"), message);
+        assertTrue(message.contains("did you mean direct://reportRoute?"), 
message);
+        assertTrue(message.contains("The producer waited 100 millis for a 
consumer"), message);
+    }
+
+    @Test
+    public void testNoCloseName() throws Exception {
+        addReportRoutes();
+
+        String message = failure("direct:invoices?timeout=100");
+
+        assertTrue(message.contains("No route in CamelContext " + 
context.getName() + " consumes from it"), message);
+        assertFalse(message.contains("did you mean"), message);
+    }
+
+    @Test
+    public void testRouteNotStarted() throws Exception {
+        addReportRoutes();
+
+        String message = failure("direct:off?timeout=100");
+
+        assertTrue(message.startsWith(PREFIX + "direct://off?timeout=100. "), 
message);
+        assertTrue(message.contains("Route off in CamelContext " + 
context.getName() + " consumes from it and is Stopped"),
+                message);
+        assertTrue(message.contains("The producer waited 100 millis for a 
consumer"), message);
+        assertFalse(message.contains("No route"), message);
+    }
+
+    @Test
+    public void testRouteSuspended() throws Exception {
+        addReportRoutes();
+        context.getRouteController().suspendRoute("report");
+
+        String message = failure("direct:reportRoute?timeout=100");
+
+        assertTrue(message.contains("Route report in CamelContext " + 
context.getName()
+                                    + " consumes from it and is Suspended"),
+                message);
+    }
+
+    @Test
+    public void testProducerDoesNotWait() throws Exception {
+        addReportRoutes();
+
+        String message = failure("direct:reportReport?block=false");
+
+        assertTrue(message.contains("The producer did not wait for a 
consumer"), message);
+        assertFalse(message.contains("waited"), message);
+    }
+
+    @Test
+    public void testFromRoute() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("direct:start").to("direct:reportReport?timeout=100");
+                from("direct:reportRoute").routeId("report").to("mock:report");
+            }
+        });
+        context.start();
+
+        CamelExecutionException e = assertThrows(CamelExecutionException.class,
+                () -> template.sendBody("direct:start", "Hello World"));
+        String message = 
assertIsInstanceOf(DirectConsumerNotAvailableException.class, 
e.getCause()).getMessage();
+
+        assertTrue(message.startsWith(PREFIX + 
"direct://reportReport?timeout=100. "), message);
+        assertTrue(message.contains("did you mean direct://reportRoute?"), 
message);
+    }
+
+    @Test
+    public void testRouteInlinedIntoRestService() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() {
+                restConfiguration().host("localhost");
+                rest("/orders").get().to("direct:orders");
+
+                
from("direct:orders").routeId("orders").transform().constant("All orders");
+                
from("direct:order").routeId("order").to("direct:orders?timeout=100");
+            }
+        });
+        context.start();
+
+        // the rest service calls the inlined route
+        assertTrue(template.requestBody("seda:get-orders", "", 
String.class).contains("All orders"));
+
+        CamelExecutionException e = assertThrows(CamelExecutionException.class,
+                () -> template.requestBody("direct:order", ""));
+        String message = 
assertIsInstanceOf(DirectConsumerNotAvailableException.class, 
e.getCause()).getMessage();
+
+        assertTrue(message.startsWith(PREFIX + "direct://orders?timeout=100. 
"), message);
+        assertTrue(message.contains("No route in CamelContext " + 
context.getName() + " consumes from it"), message);
+        assertTrue(message.contains("inlineRoutes"), message);
+    }
+
+    @Test
+    public void testRouteConsumesFromTheEndpoint() throws Exception {
+        addReportRoutes();
+        getMockEndpoint("mock:report").expectedBodiesReceived("Hello World");
+
+        template.sendBody("direct:reportRoute?timeout=100", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    private void addReportRoutes() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("direct:reportRoute").routeId("report").to("mock:report");
+                
from("direct:off").routeId("off").autoStartup(false).to("mock:off");
+            }
+        });
+        context.start();
+    }
+
+    private String failure(String uri) {
+        CamelExecutionException e = assertThrows(CamelExecutionException.class,
+                () -> template.sendBody(uri, "Hello World"));
+        return assertIsInstanceOf(DirectConsumerNotAvailableException.class, 
e.getCause()).getMessage();
+    }
+}

Reply via email to