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 e6bb6e5d242d CAMEL-27119: camel-jms, camel-sjms - the consumer uses
exceptionHandler, and the request timeout and missing connection factory errors
say why
e6bb6e5d242d is described below
commit e6bb6e5d242de58b8d5dcb83b8accc361314cb0b
Author: croway <[email protected]>
AuthorDate: Tue Nov 17 15:43:04 2026 +0100
CAMEL-27119: camel-jms, camel-sjms - the consumer uses exceptionHandler,
and the request timeout and missing connection factory errors say why
- The request timeout says the exchange was InOut, and how to wait longer
or send InOnly (camel-jms and camel-sjms).
- "connectionFactory must be specified" names the component, the endpoint
and why none was autowired.
- A consumer gives the JMS exceptions of its listener container to its
exceptionHandler, after the exceptionListener.
---
.../apache/camel/catalog/docs/jms-component.adoc | 60 ++++-
.../camel-jms/src/main/docs/jms-component.adoc | 60 ++++-
.../apache/camel/component/jms/JmsComponent.java | 38 ++-
.../camel/component/jms/JmsConfiguration.java | 40 +++-
.../apache/camel/component/jms/JmsEndpoint.java | 32 ++-
.../component/jms/reply/ReplyManagerSupport.java | 10 +-
.../jms/JmsConsumerExceptionHandlerTest.java | 260 +++++++++++++++++++++
.../component/jms/JmsInOutTimeoutMessageTest.java | 109 +++++++++
.../jms/JmsMissingConnectionFactoryTest.java | 194 +++++++++++++++
.../component/sjms/reply/ReplyManagerSupport.java | 10 +-
.../sjms/producer/InOutTimeoutMessageTest.java | 80 +++++++
.../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc | 7 +
.../modules/ROOT/pages/exchange-pattern.adoc | 3 +
13 files changed, 889 insertions(+), 14 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jms-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jms-component.adoc
index 6103a391b1ea..d3bcd0332eba 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jms-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jms-component.adoc
@@ -124,6 +124,10 @@ When the registry has exactly one `ConnectionFactory`, the
component uses it wit
(`allowAutoWiredConnectionFactory`, which is on by default). The example has
two, the one of the client and the pool,
so it sets the pool on the component.
+When no connection factory is set, the endpoints fail with `connectionFactory
must be specified`. The message names the
+endpoint and says why the component did not autowire one: the registry has no
`ConnectionFactory`, or several, which it
+names.
+
`camel run` downloads the client libraries of these classes. In a Maven
project, add
`org.apache.artemis:artemis-jakarta-client` and `org.messaginghub:pooled-jms`.
@@ -1137,6 +1141,20 @@
http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html
jee schema] in the Spring reference documentation for more details about
JNDI lookup.
+=== Connection errors of the consumer
+
+A consumer that cannot connect to the broker, or loses its connection, does
not stop its route: it tries again every
+`recoveryInterval` (5 seconds by default), and logs each failure. With
`testConnectionOnStartup=true`, the route fails
+to start when the consumer cannot connect.
+
+To act on these errors, set an option on the consumer:
+
+* `exceptionListener`: a `jakarta.jms.ExceptionListener`, which gets each
`JMSException`.
+* `exceptionHandler`: an `org.apache.camel.spi.ExceptionHandler`, which gets
the same exceptions, after the
+`exceptionListener` if both are set.
+
+The `bridgeErrorHandler` option is not supported: a message that fails already
goes to the error handler of the route.
+
=== Concurrent Consuming
A common requirement with JMS is to consume messages concurrently in
@@ -1704,10 +1722,44 @@ template.send("activemq:queue:dummy", exchange -> {
=== Using a request timeout
-In the sample below we send a Request Reply
-style message Exchange (we use the `requestBody`
-method = `InOut`) to the slow queue for further processing in Camel, and
-we wait for a return reply:
+A producer that sends an `InOut` exchange waits for the reply up to
`requestTimeout` (20 seconds by default), and
+then fails the exchange with an `ExchangeTimedOutException`. The
`CamelJmsRequestTimeout` header sets the timeout of one
+message.
+
+An exchange is `InOut` when the consumer of the route answers its caller, such
as an HTTP, REST or platform-http
+consumer, or a JMS consumer that receives a message with a `JMSReplyTo`, or
when it comes from a `request` method of a
+`ProducerTemplate`. Then a `to("jms:queue:orders")` sends the message as a
request and waits for a reply, also when no
+consumer of `orders` sends one. When no reply is expected, send the message
`InOnly`, with the `exchangePattern` option:
+
+[tabs]
+====
+Java::
++
+[source,java]
+----
+from("platform-http:/orders")
+ .to("jms:queue:orders?exchangePattern=InOnly")
+ .setBody(constant("Accepted"));
+----
+
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: platform-http:/orders
+ steps:
+ - to:
+ uri: jms:queue:orders
+ parameters:
+ exchangePattern: InOnly
+ - setBody:
+ constant: Accepted
+----
+====
+
+The option `disableReplyTo=true` also sends the message without waiting for a
reply.
=== Sending an InOnly message and keeping the JMSReplyTo header
diff --git a/components/camel-jms/src/main/docs/jms-component.adoc
b/components/camel-jms/src/main/docs/jms-component.adoc
index 6103a391b1ea..d3bcd0332eba 100644
--- a/components/camel-jms/src/main/docs/jms-component.adoc
+++ b/components/camel-jms/src/main/docs/jms-component.adoc
@@ -124,6 +124,10 @@ When the registry has exactly one `ConnectionFactory`, the
component uses it wit
(`allowAutoWiredConnectionFactory`, which is on by default). The example has
two, the one of the client and the pool,
so it sets the pool on the component.
+When no connection factory is set, the endpoints fail with `connectionFactory
must be specified`. The message names the
+endpoint and says why the component did not autowire one: the registry has no
`ConnectionFactory`, or several, which it
+names.
+
`camel run` downloads the client libraries of these classes. In a Maven
project, add
`org.apache.artemis:artemis-jakarta-client` and `org.messaginghub:pooled-jms`.
@@ -1137,6 +1141,20 @@
http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html
jee schema] in the Spring reference documentation for more details about
JNDI lookup.
+=== Connection errors of the consumer
+
+A consumer that cannot connect to the broker, or loses its connection, does
not stop its route: it tries again every
+`recoveryInterval` (5 seconds by default), and logs each failure. With
`testConnectionOnStartup=true`, the route fails
+to start when the consumer cannot connect.
+
+To act on these errors, set an option on the consumer:
+
+* `exceptionListener`: a `jakarta.jms.ExceptionListener`, which gets each
`JMSException`.
+* `exceptionHandler`: an `org.apache.camel.spi.ExceptionHandler`, which gets
the same exceptions, after the
+`exceptionListener` if both are set.
+
+The `bridgeErrorHandler` option is not supported: a message that fails already
goes to the error handler of the route.
+
=== Concurrent Consuming
A common requirement with JMS is to consume messages concurrently in
@@ -1704,10 +1722,44 @@ template.send("activemq:queue:dummy", exchange -> {
=== Using a request timeout
-In the sample below we send a Request Reply
-style message Exchange (we use the `requestBody`
-method = `InOut`) to the slow queue for further processing in Camel, and
-we wait for a return reply:
+A producer that sends an `InOut` exchange waits for the reply up to
`requestTimeout` (20 seconds by default), and
+then fails the exchange with an `ExchangeTimedOutException`. The
`CamelJmsRequestTimeout` header sets the timeout of one
+message.
+
+An exchange is `InOut` when the consumer of the route answers its caller, such
as an HTTP, REST or platform-http
+consumer, or a JMS consumer that receives a message with a `JMSReplyTo`, or
when it comes from a `request` method of a
+`ProducerTemplate`. Then a `to("jms:queue:orders")` sends the message as a
request and waits for a reply, also when no
+consumer of `orders` sends one. When no reply is expected, send the message
`InOnly`, with the `exchangePattern` option:
+
+[tabs]
+====
+Java::
++
+[source,java]
+----
+from("platform-http:/orders")
+ .to("jms:queue:orders?exchangePattern=InOnly")
+ .setBody(constant("Accepted"));
+----
+
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: platform-http:/orders
+ steps:
+ - to:
+ uri: jms:queue:orders
+ parameters:
+ exchangePattern: InOnly
+ - setBody:
+ constant: Accepted
+----
+====
+
+The option `disableReplyTo=true` also sends the message without waiting for a
reply.
=== Sending an InOnly message and keeping the JMSReplyTo header
diff --git
a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
index aa75a2a77b39..91d2f810e8d4 100644
---
a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
+++
b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
@@ -16,7 +16,9 @@
*/
package org.apache.camel.component.jms;
+import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ExecutorService;
@@ -32,6 +34,7 @@ import org.apache.camel.spi.annotations.Component;
import org.apache.camel.support.HeaderFilterStrategyComponent;
import org.apache.camel.support.LRUCacheFactory;
import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.URISupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.task.TaskExecutor;
@@ -1140,8 +1143,27 @@ public class JmsComponent extends
HeaderFilterStrategyComponent {
ConnectionFactory cf = beans.iterator().next();
configuration.setConnectionFactory(cf);
} else if (beans.size() > 1) {
- LOG.debug("Cannot autowire ConnectionFactory as {} instances
found in registry.", beans.size());
+ List<String> names = connectionFactoryBeanNames();
+ LOG.debug("Cannot autowire ConnectionFactory as {} instances
found in registry: {}", beans.size(), names);
+ String example = names.isEmpty() ? "<bean name>" :
names.get(0);
+ configuration.setConnectionFactoryNotAutowiredReason(
+ "The component did not autowire one, because the
registry has " + beans.size()
+ + "
jakarta.jms.ConnectionFactory beans: "
+ +
String.join(", ", names)
+ + ". Set
the connectionFactory option to one of them,"
+ + " such
as connectionFactory=#" + example);
+ } else {
+ configuration.setConnectionFactoryNotAutowiredReason(
+ "The registry has no jakarta.jms.ConnectionFactory
bean to autowire. Create the ConnectionFactory"
+ + " of
the client library of the broker as a bean,"
+ + " or
set the connectionFactory option");
}
+ } else if (configuration.getConnectionFactory() == null) {
+ configuration.setConnectionFactoryNotAutowiredReason("The
component does not autowire one, because "
+ +
(configuration.getTransactionManager() != null
+ ? "a
transactionManager is set"
+ :
"allowAutoWiredConnectionFactory is false")
+ + ". Set the
connectionFactory option");
}
if (configuration.getDestinationResolver() == null &&
isAllowAutoWiredDestinationResolver()) {
@@ -1171,6 +1193,19 @@ public class JmsComponent extends
HeaderFilterStrategyComponent {
super.doInit();
}
+ /**
+ * The names of the connection factory beans in the registry, for the
error when none of them is autowired.
+ */
+ private List<String> connectionFactoryBeanNames() {
+ try {
+ return
getCamelContext().getRegistry().findByTypeWithName(ConnectionFactory.class).keySet().stream()
+ .filter(Objects::nonNull).sorted().toList();
+ } catch (Exception e) {
+ LOG.debug("Cannot get the names of the ConnectionFactory beans in
the registry. This exception is ignored.", e);
+ return List.of();
+ }
+ }
+
@Override
protected void doShutdown() throws Exception {
if (asyncStartStopExecutorService != null) {
@@ -1225,6 +1260,7 @@ public class JmsComponent extends
HeaderFilterStrategyComponent {
// lets make sure we copy the configuration as each endpoint can
// customize its own version
JmsConfiguration newConfiguration = getConfiguration().copy();
+ newConfiguration.setEndpointUriForErrors(URISupport.stripQuery(uri));
JmsEndpoint endpoint;
if (pubSubDomain) {
if (tempDestination) {
diff --git
a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
index 85110e1d8cfa..b106c11d348a 100644
---
a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
+++
b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
@@ -31,7 +31,7 @@ import org.apache.camel.LoggingLevel;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriParams;
-import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.StringHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.task.TaskExecutor;
@@ -68,6 +68,9 @@ public class JmsConfiguration implements Cloneable {
private JmsOperations jmsOperations;
private ConnectionFactory templateConnectionFactory;
private ConnectionFactory listenerConnectionFactory;
+ // not options: they are only used in the message of the error when no
connection factory is set
+ private String endpointUriForErrors;
+ private String connectionFactoryNotAutowiredReason;
@UriParam(description = "The connection factory to be use. A connection
factory must be configured either on the component or endpoint.")
private ConnectionFactory connectionFactory;
@@ -1956,10 +1959,43 @@ public class JmsConfiguration implements Cloneable {
* Factory method which allows derived classes to customize the lazy
creation
*/
protected ConnectionFactory createConnectionFactory() {
- ObjectHelper.notNull(connectionFactory, "connectionFactory");
+ if (connectionFactory == null) {
+ throw new
IllegalArgumentException(missingConnectionFactoryMessage());
+ }
return null;
}
+ /**
+ * The message of the error when no connection factory is set: it names
the endpoint, and says why the component did
+ * not autowire a connection factory, when they are known.
+ */
+ private String missingConnectionFactoryMessage() {
+ StringBuilder sb = new StringBuilder("connectionFactory must be
specified");
+ if (endpointUriForErrors != null) {
+ String scheme = StringHelper.before(endpointUriForErrors, ":",
endpointUriForErrors);
+ sb.append(" on the ").append(scheme).append(" component or on the
endpoint ").append(endpointUriForErrors);
+ }
+ if (connectionFactoryNotAutowiredReason != null) {
+ sb.append(". ").append(connectionFactoryNotAutowiredReason);
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Sets the uri of the endpoint that uses this configuration, which the
error of a missing connection factory names.
+ */
+ void setEndpointUriForErrors(String endpointUriForErrors) {
+ this.endpointUriForErrors = endpointUriForErrors;
+ }
+
+ /**
+ * Sets why the component did not autowire a connection factory, and what
to do, which the error of a missing
+ * connection factory gives.
+ */
+ void setConnectionFactoryNotAutowiredReason(String
connectionFactoryNotAutowiredReason) {
+ this.connectionFactoryNotAutowiredReason =
connectionFactoryNotAutowiredReason;
+ }
+
/**
* Factory method which allows derived classes to customize the lazy
creation
*/
diff --git
a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
index 1d77420af22d..ab708abed037 100644
---
a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
+++
b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
@@ -322,6 +322,33 @@ public class JmsEndpoint extends DefaultEndpoint
listenerContainer.setSubscriptionName(configuration.getSubscriptionName());
}
listenerContainer.setSubscriptionShared(configuration.isSubscriptionShared());
+
+ if (getExceptionHandler() != null) {
+ forwardContainerExceptionsToExceptionHandler(listenerContainer,
consumer);
+ }
+ }
+
+ /**
+ * Gives the JMS exceptions of the listener container (such as a
connection that cannot be established, or a failed
+ * setup of a listener) to the exceptionHandler of the consumer as well,
after the exceptionListener, if any.
+ */
+ private void forwardContainerExceptionsToExceptionHandler(
+ AbstractMessageListenerContainer listenerContainer, JmsConsumer
consumer) {
+ final ExceptionListener exceptionListener =
listenerContainer.getExceptionListener();
+ final String destination = destinationName != null ? destinationName :
getEndpointUri();
+ final String message = "JMS exception in the listener container of the
consumer on destination: " + destination;
+ listenerContainer.setExceptionListener(exception -> {
+ if (exceptionListener != null) {
+ exceptionListener.onException(exception);
+ }
+ try {
+ consumer.getExceptionHandler().handleException(message,
exception);
+ } catch (Exception e) {
+ // the listener container calls this while it recovers, which
must go on
+ LOG.warn("The exceptionHandler of the consumer on destination:
{} failed. This exception is ignored.",
+ destination, e);
+ }
+ });
}
private void setContainerTaskExecutor(AbstractMessageListenerContainer
listenerContainer, Executor executor) {
@@ -361,7 +388,10 @@ public class JmsEndpoint extends DefaultEndpoint
configureConsumer(consumer);
if (isBridgeErrorHandler()) {
- throw new IllegalArgumentException("BridgeErrorHandler is not
support on JMS endpoint");
+ throw new IllegalArgumentException(
+ "BridgeErrorHandler is not supported on JMS endpoint: a
message that fails already goes to the error"
+ + " handler of the route. To
handle the connection errors of the consumer,"
+ + " use the exceptionHandler or
exceptionListener option");
}
String replyTo = consumer.getEndpoint().getReplyTo();
diff --git
a/components/camel-jms/src/main/java/org/apache/camel/component/jms/reply/ReplyManagerSupport.java
b/components/camel-jms/src/main/java/org/apache/camel/component/jms/reply/ReplyManagerSupport.java
index 197dcaa55b0d..9dd887a9aba5 100644
---
a/components/camel-jms/src/main/java/org/apache/camel/component/jms/reply/ReplyManagerSupport.java
+++
b/components/camel-jms/src/main/java/org/apache/camel/component/jms/reply/ReplyManagerSupport.java
@@ -56,6 +56,14 @@ import
org.springframework.jms.listener.DefaultMessageListenerContainer;
*/
public abstract class ReplyManagerSupport extends ServiceSupport implements
ReplyManager {
+ // why the producer waited for a reply, and what to do, added to the
message of the timeout
+ private static final String TIMEOUT_HINT
+ = "The message was sent as a request and the producer waited for a
reply, because the exchange pattern is"
+ + " InOut (such as an exchange from an HTTP or REST consumer,
from a JMS message with a JMSReplyTo, or from a"
+ + " request method of ProducerTemplate)."
+ + " If a reply is expected, check that a consumer of the request
destination sends it, or increase"
+ + " requestTimeout. If no reply is expected, send the message
with exchangePattern=InOnly or disableReplyTo=true";
+
protected final Logger log = LoggerFactory.getLogger(getClass());
protected final CamelContext camelContext;
protected ScheduledExecutorService scheduledExecutorService;
@@ -211,7 +219,7 @@ public abstract class ReplyManagerSupport extends
ServiceSupport implements Repl
ExchangeHelper.logIds(exchange));
}
String msg = "reply message with correlationID: " +
holder.getCorrelationId()
- + " not received on destination: " + replyTo;
+ + " not received on destination: " + replyTo + ". " +
TIMEOUT_HINT;
exchange.setException(new ExchangeTimedOutException(exchange,
holder.getRequestTimeout(), msg));
}
diff --git
a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsConsumerExceptionHandlerTest.java
b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsConsumerExceptionHandlerTest.java
new file mode 100644
index 000000000000..a7fc4ff7f04e
--- /dev/null
+++
b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsConsumerExceptionHandlerTest.java
@@ -0,0 +1,260 @@
+/*
+ * 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.jms;
+
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import jakarta.jms.Connection;
+import jakarta.jms.ConnectionFactory;
+import jakarta.jms.ExceptionListener;
+import jakarta.jms.JMSContext;
+import jakarta.jms.JMSException;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.spi.ExceptionHandler;
+import org.junit.jupiter.api.Test;
+
+import static org.awaitility.Awaitility.await;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The exceptionHandler of a consumer gets the JMS exceptions of its listener
container, such as a connection to the
+ * broker that cannot be established.
+ */
+public class JmsConsumerExceptionHandlerTest {
+
+ @Test
+ public void testExceptionHandlerGetsTheConnectionErrors() throws Exception
{
+ FailingConnectionFactory cf = new FailingConnectionFactory();
+ RecordingExceptionHandler handler = new RecordingExceptionHandler();
+ try (CamelContext context = new DefaultCamelContext()) {
+ context.getRegistry().bind("handler", handler);
+ context.addComponent("jms", JmsComponent.jmsComponent(cf));
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+
from("jms:queue:JmsConsumerExceptionHandlerTest.a?exceptionHandler=#handler&recoveryInterval=100")
+ .to("mock:a");
+ }
+ });
+ context.start();
+
+ await().atMost(10, TimeUnit.SECONDS).until(() ->
handler.exceptions.size() >= 3);
+
+ assertEquals("JMS exception in the listener container of the
consumer on destination:"
+ + " JmsConsumerExceptionHandlerTest.a",
+ handler.messages.get(0));
+ JMSException exception = assertInstanceOf(JMSException.class,
handler.exceptions.get(0));
+ assertEquals("Broker is down", exception.getMessage());
+ }
+ }
+
+ @Test
+ public void
testExceptionHandlerAndExceptionListenerGetTheConnectionErrors() throws
Exception {
+ FailingConnectionFactory cf = new FailingConnectionFactory();
+ RecordingExceptionHandler handler = new RecordingExceptionHandler();
+ RecordingExceptionListener listener = new RecordingExceptionListener();
+ try (CamelContext context = new DefaultCamelContext()) {
+ context.getRegistry().bind("handler", handler);
+ context.getRegistry().bind("listener", listener);
+ context.addComponent("jms", JmsComponent.jmsComponent(cf));
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("jms:queue:JmsConsumerExceptionHandlerTest.b"
+ +
"?exceptionHandler=#handler&exceptionListener=#listener&recoveryInterval=100")
+ .to("mock:b");
+ }
+ });
+ context.start();
+
+ await().atMost(10, TimeUnit.SECONDS)
+ .until(() -> handler.exceptions.size() >= 3 &&
listener.exceptions.size() >= 3);
+
+ assertEquals("Broker is down",
listener.exceptions.get(0).getMessage());
+ assertEquals("Broker is down",
handler.exceptions.get(0).getMessage());
+ }
+ }
+
+ @Test
+ public void testExceptionListenerAloneGetsTheConnectionErrors() throws
Exception {
+ FailingConnectionFactory cf = new FailingConnectionFactory();
+ RecordingExceptionListener listener = new RecordingExceptionListener();
+ try (CamelContext context = new DefaultCamelContext()) {
+ context.getRegistry().bind("listener", listener);
+ context.addComponent("jms", JmsComponent.jmsComponent(cf));
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+
from("jms:queue:JmsConsumerExceptionHandlerTest.c?exceptionListener=#listener&recoveryInterval=100")
+ .routeId("c").to("mock:c");
+ }
+ });
+ context.start();
+
+ await().atMost(10, TimeUnit.SECONDS).until(() ->
listener.exceptions.size() >= 3);
+
+ assertEquals("Broker is down",
listener.exceptions.get(0).getMessage());
+ JmsConsumer consumer = (JmsConsumer)
context.getRoute("c").getConsumer();
+ assertEquals(listener,
consumer.getListenerContainer().getExceptionListener());
+ }
+ }
+
+ @Test
+ public void testNoExceptionListenerWithoutTheOptions() throws Exception {
+ try (CamelContext context = new DefaultCamelContext()) {
+ context.addComponent("jms", JmsComponent.jmsComponent(new
FailingConnectionFactory()));
+ context.start();
+
+ JmsEndpoint endpoint =
context.getEndpoint("jms:queue:JmsConsumerExceptionHandlerTest.d",
JmsEndpoint.class);
+ JmsConsumer consumer = endpoint.createConsumer(exchange -> {
+ });
+ assertNull(consumer.getListenerContainer().getExceptionListener());
+ }
+ }
+
+ @Test
+ public void testFailingExceptionHandlerDoesNotStopTheRecovery() throws
Exception {
+ FailingConnectionFactory cf = new FailingConnectionFactory();
+ RecordingExceptionHandler handler = new
RecordingExceptionHandler(true);
+ try (CamelContext context = new DefaultCamelContext()) {
+ context.getRegistry().bind("handler", handler);
+ context.addComponent("jms", JmsComponent.jmsComponent(cf));
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+
from("jms:queue:JmsConsumerExceptionHandlerTest.e?exceptionHandler=#handler&recoveryInterval=100")
+ .to("mock:e");
+ }
+ });
+ context.start();
+
+ // the container goes on trying to connect after the handler failed
+ await().atMost(10, TimeUnit.SECONDS).until(() ->
handler.exceptions.size() >= 3 && cf.attempts.get() >= 4);
+ }
+ }
+
+ @Test
+ public void testBridgeErrorHandlerIsRejected() throws Exception {
+ try (CamelContext context = new DefaultCamelContext()) {
+ context.addComponent("jms", JmsComponent.jmsComponent(new
FailingConnectionFactory()));
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+
from("jms:queue:JmsConsumerExceptionHandlerTest.f?bridgeErrorHandler=true").to("mock:f");
+ }
+ });
+
+ Exception e = assertThrows(Exception.class, context::start);
+ Throwable root = e;
+ while (root.getCause() != null) {
+ root = root.getCause();
+ }
+ assertInstanceOf(IllegalArgumentException.class, root);
+ assertTrue(root.getMessage().startsWith("BridgeErrorHandler is not
supported on JMS endpoint"),
+ root.getMessage());
+ assertTrue(root.getMessage().contains("use the exceptionHandler or
exceptionListener option"), root.getMessage());
+ }
+ }
+
+ private static final class FailingConnectionFactory implements
ConnectionFactory {
+ private final AtomicInteger attempts = new AtomicInteger();
+
+ @Override
+ public Connection createConnection() throws JMSException {
+ attempts.incrementAndGet();
+ throw new JMSException("Broker is down");
+ }
+
+ @Override
+ public Connection createConnection(String userName, String password)
throws JMSException {
+ return createConnection();
+ }
+
+ @Override
+ public JMSContext createContext() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public JMSContext createContext(String userName, String password) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public JMSContext createContext(String userName, String password, int
sessionMode) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public JMSContext createContext(int sessionMode) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ private static final class RecordingExceptionHandler implements
ExceptionHandler {
+ private final List<String> messages = new CopyOnWriteArrayList<>();
+ private final List<Throwable> exceptions = new
CopyOnWriteArrayList<>();
+ private final boolean fail;
+
+ RecordingExceptionHandler() {
+ this(false);
+ }
+
+ RecordingExceptionHandler(boolean fail) {
+ this.fail = fail;
+ }
+
+ @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) {
+ messages.add(String.valueOf(message));
+ exceptions.add(exception);
+ if (fail) {
+ throw new IllegalStateException("Handler failed");
+ }
+ }
+ }
+
+ private static final class RecordingExceptionListener implements
ExceptionListener {
+ private final List<JMSException> exceptions = new
CopyOnWriteArrayList<>();
+
+ @Override
+ public void onException(JMSException exception) {
+ exceptions.add(exception);
+ }
+ }
+}
diff --git
a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsInOutTimeoutMessageTest.java
b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsInOutTimeoutMessageTest.java
new file mode 100644
index 000000000000..681d3653c8c9
--- /dev/null
+++
b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsInOutTimeoutMessageTest.java
@@ -0,0 +1,109 @@
+/*
+ * 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.jms;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.ConsumerTemplate;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.ExchangeTimedOutException;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.infra.core.CamelContextExtension;
+import org.apache.camel.test.infra.core.TransientCamelContextExtension;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The error of a request that gets no reply says why the producer waited for
a reply, and how to send without waiting.
+ */
+public class JmsInOutTimeoutMessageTest extends AbstractJMSTest {
+
+ @Order(2)
+ @RegisterExtension
+ public static CamelContextExtension camelContextExtension = new
TransientCamelContextExtension();
+ protected ProducerTemplate template;
+ protected ConsumerTemplate consumer;
+
+ @Test
+ public void testTimeoutMessageSaysWhyTheProducerWaitedForAReply() {
+ CamelExecutionException e = assertThrows(CamelExecutionException.class,
+ () -> template.requestBody("direct:noReply", "Hello"));
+
+ ExchangeTimedOutException timeout =
assertInstanceOf(ExchangeTimedOutException.class, e.getCause());
+ assertEquals(500, timeout.getTimeout());
+ String msg = timeout.getMessage();
+ assertTrue(msg.startsWith("The OUT message was not received within:
500 millis due reply message with correlationID: "),
+ msg);
+ assertTrue(msg.contains(" not received on destination: "), msg);
+ assertTrue(msg.contains("the exchange pattern is InOut"), msg);
+ assertTrue(msg.contains("increase requestTimeout"), msg);
+ assertTrue(msg.contains("exchangePattern=InOnly or
disableReplyTo=true. Exchange["), msg);
+ }
+
+ @Test
+ public void testInOnlyExchangeDoesNotWaitForAReply() {
+ template.sendBody("direct:inOnly", "Hello");
+
+ assertEquals("Hello",
consumer.receiveBody("activemq:queue:JmsInOutTimeoutMessageTest.inOnly", 5000,
String.class));
+ }
+
+ @Test
+ public void testInOnlyPatternOnTheEndpointDoesNotWaitForAReply() {
+ // an InOut exchange, as from an HTTP consumer, sent with the InOnly
pattern
+ Object reply = template.requestBody("direct:inOnlyPattern", "Hello");
+
+ assertEquals("Hello", reply);
+ assertEquals("Hello",
+
consumer.receiveBody("activemq:queue:JmsInOutTimeoutMessageTest.inOnlyPattern",
5000, String.class));
+ }
+
+ @Override
+ protected String getComponentName() {
+ return "activemq";
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+
from("direct:noReply").to("activemq:queue:JmsInOutTimeoutMessageTest.noReply?requestTimeout=500");
+
from("direct:inOnly").to("activemq:queue:JmsInOutTimeoutMessageTest.inOnly?requestTimeout=500");
+ from("direct:inOnlyPattern").to(ExchangePattern.InOnly,
+
"activemq:queue:JmsInOutTimeoutMessageTest.inOnlyPattern?requestTimeout=500");
+ }
+ };
+ }
+
+ @Override
+ public CamelContextExtension getCamelContextExtension() {
+ return camelContextExtension;
+ }
+
+ @BeforeEach
+ void setUpRequirements() {
+ template = camelContextExtension.getProducerTemplate();
+ consumer = camelContextExtension.getConsumerTemplate();
+ }
+}
diff --git
a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsMissingConnectionFactoryTest.java
b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsMissingConnectionFactoryTest.java
new file mode 100644
index 000000000000..85cf6e36a13b
--- /dev/null
+++
b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsMissingConnectionFactoryTest.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.jms;
+
+import jakarta.jms.ConnectionFactory;
+
+import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.test.infra.artemis.common.ConnectionFactoryHelper;
+import org.apache.camel.test.infra.artemis.services.ArtemisService;
+import org.apache.camel.test.infra.artemis.services.ArtemisServiceFactory;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+/**
+ * The error when no connection factory is set names the endpoint, and says
why the component did not autowire one.
+ */
+public class JmsMissingConnectionFactoryTest {
+
+ @RegisterExtension
+ public static ArtemisService service =
ArtemisServiceFactory.createSingletonVMService();
+
+ @Test
+ public void testConsumerWithTwoConnectionFactoryBeans() throws Exception {
+ try (CamelContext context = new DefaultCamelContext()) {
+ // connection factories that are never connected
+ context.getRegistry().bind("cf2", new
ActiveMQConnectionFactory("vm://JmsMissingConnectionFactoryTest-2"));
+ context.getRegistry().bind("cf1", new
ActiveMQConnectionFactory("vm://JmsMissingConnectionFactoryTest-1"));
+ context.addComponent("jms", new JmsComponent());
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+
from("jms:queue:JmsMissingConnectionFactoryTest.a").to("mock:a");
+ }
+ });
+
+ Exception e = assertThrows(Exception.class, context::start);
+ assertEquals("connectionFactory must be specified on the jms
component or on the endpoint"
+ + " jms://queue:JmsMissingConnectionFactoryTest.a.
The component did not autowire one, because the"
+ + " registry has 2 jakarta.jms.ConnectionFactory
beans: cf1, cf2. Set the connectionFactory option"
+ + " to one of them, such as connectionFactory=#cf1",
+ illegalArgument(e).getMessage());
+ }
+ }
+
+ @Test
+ public void testConsumerWithNoConnectionFactoryBean() throws Exception {
+ try (CamelContext context = new DefaultCamelContext()) {
+ context.addComponent("jms", new JmsComponent());
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+
from("jms:queue:JmsMissingConnectionFactoryTest.b").to("mock:b");
+ }
+ });
+
+ Exception e = assertThrows(Exception.class, context::start);
+ assertEquals("connectionFactory must be specified on the jms
component or on the endpoint"
+ + " jms://queue:JmsMissingConnectionFactoryTest.b.
The registry has no jakarta.jms.ConnectionFactory"
+ + " bean to autowire. Create the ConnectionFactory of
the client library of the broker as a bean,"
+ + " or set the connectionFactory option",
+ illegalArgument(e).getMessage());
+ }
+ }
+
+ @Test
+ public void testProducerWithTwoConnectionFactoryBeans() throws Exception {
+ try (CamelContext context = new DefaultCamelContext()) {
+ context.getRegistry().bind("cf1", new
ActiveMQConnectionFactory("vm://JmsMissingConnectionFactoryTest-1"));
+ context.getRegistry().bind("cf2", new
ActiveMQConnectionFactory("vm://JmsMissingConnectionFactoryTest-2"));
+ context.addComponent("broker", new JmsComponent());
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+
from("direct:start").to("broker:queue:JmsMissingConnectionFactoryTest.c?timeToLive=1000");
+ }
+ });
+ context.start();
+
+ ProducerTemplate template = context.createProducerTemplate();
+ CamelExecutionException e =
assertThrows(CamelExecutionException.class,
+ () -> template.sendBody("direct:start", "Hello"));
+ IllegalArgumentException cause =
assertInstanceOf(IllegalArgumentException.class, e.getCause());
+ assertEquals("connectionFactory must be specified on the broker
component or on the endpoint"
+ + " broker://queue:JmsMissingConnectionFactoryTest.c.
The component did not autowire one, because"
+ + " the registry has 2 jakarta.jms.ConnectionFactory
beans: cf1, cf2. Set the connectionFactory"
+ + " option to one of them, such as
connectionFactory=#cf1",
+ cause.getMessage());
+ }
+ }
+
+ @Test
+ public void testAutowireDisabled() throws Exception {
+ try (CamelContext context = new DefaultCamelContext()) {
+ context.getRegistry().bind("cf1", new
ActiveMQConnectionFactory("vm://JmsMissingConnectionFactoryTest-1"));
+ JmsComponent component = new JmsComponent();
+ component.setAllowAutoWiredConnectionFactory(false);
+ context.addComponent("jms", component);
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+
from("jms:queue:JmsMissingConnectionFactoryTest.d").to("mock:d");
+ }
+ });
+
+ Exception e = assertThrows(Exception.class, context::start);
+ assertEquals("connectionFactory must be specified on the jms
component or on the endpoint"
+ + " jms://queue:JmsMissingConnectionFactoryTest.d.
The component does not autowire one, because"
+ + " allowAutoWiredConnectionFactory is false. Set the
connectionFactory option",
+ illegalArgument(e).getMessage());
+ }
+ }
+
+ @Test
+ public void testSingleConnectionFactoryBeanIsAutowired() throws Exception {
+ try (CamelContext context = new DefaultCamelContext()) {
+ ConnectionFactory cf =
ConnectionFactoryHelper.createConnectionFactory(service);
+ context.getRegistry().bind("cf1", cf);
+ context.addComponent("jms", new JmsComponent());
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+
from("direct:start").to("jms:queue:JmsMissingConnectionFactoryTest.e");
+
from("jms:queue:JmsMissingConnectionFactoryTest.e").to("mock:e");
+ }
+ });
+ context.start();
+
+ assertSame(cf, context.getComponent("jms",
JmsComponent.class).getConfiguration().getConnectionFactory());
+ MockEndpoint mock = context.getEndpoint("mock:e",
MockEndpoint.class);
+ mock.expectedBodiesReceived("Hello");
+ context.createProducerTemplate().sendBody("direct:start", "Hello");
+ MockEndpoint.assertIsSatisfied(context);
+ }
+ }
+
+ @Test
+ public void testConnectionFactoryOnTheEndpoint() throws Exception {
+ try (CamelContext context = new DefaultCamelContext()) {
+ context.getRegistry().bind("cf1",
ConnectionFactoryHelper.createConnectionFactory(service));
+ context.getRegistry().bind("cf2", new
ActiveMQConnectionFactory("vm://JmsMissingConnectionFactoryTest-2"));
+ context.addComponent("jms", new JmsComponent());
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+
from("direct:start").to("jms:queue:JmsMissingConnectionFactoryTest.f?connectionFactory=#cf1");
+
from("jms:queue:JmsMissingConnectionFactoryTest.f?connectionFactory=#cf1").to("mock:f");
+ }
+ });
+ context.start();
+
+ MockEndpoint mock = context.getEndpoint("mock:f",
MockEndpoint.class);
+ mock.expectedBodiesReceived("Hello");
+ context.createProducerTemplate().sendBody("direct:start", "Hello");
+ MockEndpoint.assertIsSatisfied(context);
+ }
+ }
+
+ private static IllegalArgumentException illegalArgument(Throwable t) {
+ IllegalArgumentException found = null;
+ for (Throwable c = t; c != null; c = c.getCause()) {
+ if (c instanceof IllegalArgumentException iae) {
+ found = iae;
+ }
+ }
+ assertNotNull(found, "no IllegalArgumentException in " + t);
+ return found;
+ }
+}
diff --git
a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/reply/ReplyManagerSupport.java
b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/reply/ReplyManagerSupport.java
index aef32e3ddf5a..81a88d5fd67b 100644
---
a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/reply/ReplyManagerSupport.java
+++
b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/reply/ReplyManagerSupport.java
@@ -53,6 +53,14 @@ import static
org.apache.camel.component.sjms.jms.JmsMessageHelper.getJMSCorrela
*/
public abstract class ReplyManagerSupport extends ServiceSupport implements
ReplyManager {
+ // why the producer waited for a reply, and what to do, added to the
message of the timeout
+ private static final String TIMEOUT_HINT
+ = "The message was sent as a request and the producer waited for a
reply, because the exchange pattern is"
+ + " InOut (such as an exchange from an HTTP or REST consumer,
from a JMS message with a JMSReplyTo, or from a"
+ + " request method of ProducerTemplate)."
+ + " If a reply is expected, check that a consumer of the request
destination sends it, or increase"
+ + " requestTimeout. If no reply is expected, send the message
with exchangePattern=InOnly or disableReplyTo=true";
+
protected final Logger log = LoggerFactory.getLogger(getClass());
protected final CamelContext camelContext;
protected ScheduledExecutorService scheduledExecutorService;
@@ -185,7 +193,7 @@ public abstract class ReplyManagerSupport extends
ServiceSupport implements Repl
ExchangeHelper.logIds(exchange));
}
String msg = "reply message with correlationID: " +
holder.getCorrelationId()
- + " not received on destination: " + replyTo;
+ + " not received on destination: " + replyTo + ". " +
TIMEOUT_HINT;
exchange.setException(new ExchangeTimedOutException(exchange,
holder.getRequestTimeout(), msg));
}
diff --git
a/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/producer/InOutTimeoutMessageTest.java
b/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/producer/InOutTimeoutMessageTest.java
new file mode 100644
index 000000000000..2838c21d40a1
--- /dev/null
+++
b/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/producer/InOutTimeoutMessageTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.sjms.producer;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.ExchangeTimedOutException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.sjms.support.JmsTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The error of a request that gets no reply says why the producer waited for
a reply, and how to send without waiting.
+ */
+public class InOutTimeoutMessageTest extends JmsTestSupport {
+
+ @Test
+ public void testTimeoutMessageSaysWhyTheProducerWaitedForAReply() {
+ CamelExecutionException e = assertThrows(CamelExecutionException.class,
+ () -> template.requestBody("direct:noReply", "Hello"));
+
+ ExchangeTimedOutException timeout =
assertInstanceOf(ExchangeTimedOutException.class, e.getCause());
+ assertEquals(500, timeout.getTimeout());
+ String msg = timeout.getMessage();
+ assertTrue(msg.startsWith("The OUT message was not received within:
500 millis due reply message with correlationID: "),
+ msg);
+ assertTrue(msg.contains(" not received on destination: "), msg);
+ assertTrue(msg.contains("the exchange pattern is InOut"), msg);
+ assertTrue(msg.contains("increase requestTimeout"), msg);
+ assertTrue(msg.contains("exchangePattern=InOnly or
disableReplyTo=true. Exchange["), msg);
+ }
+
+ @Test
+ public void testInOnlyExchangeDoesNotWaitForAReply() {
+ template.sendBody("direct:inOnly", "Hello");
+
+ assertEquals("Hello",
consumer.receiveBody("sjms:queue:InOutTimeoutMessageTest.inOnly", 5000,
String.class));
+ }
+
+ @Test
+ public void testInOnlyPatternOnTheEndpointDoesNotWaitForAReply() {
+ // an InOut exchange, as from an HTTP consumer, sent with the InOnly
pattern
+ Object reply = template.requestBody("direct:inOnlyPattern", "Hello");
+
+ assertEquals("Hello", reply);
+ assertEquals("Hello",
consumer.receiveBody("sjms:queue:InOutTimeoutMessageTest.inOnlyPattern", 5000,
String.class));
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+
from("direct:noReply").to("sjms:queue:InOutTimeoutMessageTest.noReply?requestTimeout=500");
+
from("direct:inOnly").to("sjms:queue:InOutTimeoutMessageTest.inOnly?requestTimeout=500");
+ from("direct:inOnlyPattern").to(ExchangePattern.InOnly,
+
"sjms:queue:InOutTimeoutMessageTest.inOnlyPattern?requestTimeout=500");
+ }
+ };
+ }
+}
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 8cab29e3f158..b70e68a1297f 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
@@ -672,6 +672,13 @@ message is processed once per consumer; this is unchanged.
This also applies whe
and the route consumes from a topic, and to camel-activemq, camel-activemq6
and camel-amqp. To process each message
once, set `subscriptionShared=true` with a `subscriptionName`, or use a single
consumer on the topic.
+=== camel-jms - the exceptionHandler of a consumer gets the JMS exceptions of
its listener container
+
+A consumer with the `exceptionHandler` option now gives that handler the JMS
exceptions of its listener container,
+such as a connection to the broker that cannot be established or is lost (the
consumer tries again every
+`recoveryInterval`). Before, the option was not used. When `exceptionListener`
is set too, it still gets each
+exception, before the handler. This also applies to camel-activemq,
camel-activemq6 and camel-amqp.
+
=== camel-sjms, camel-sjms2 - pollEnrich and ConsumerTemplate read the message
before they close the session
`pollEnrich` and a `ConsumerTemplate` on an `sjms` or `sjms2` endpoint now
read the body and the headers of the message
diff --git a/docs/user-manual/modules/ROOT/pages/exchange-pattern.adoc
b/docs/user-manual/modules/ROOT/pages/exchange-pattern.adoc
index 2a650e82771e..ebe60c11e9b5 100644
--- a/docs/user-manual/modules/ROOT/pages/exchange-pattern.adoc
+++ b/docs/user-manual/modules/ROOT/pages/exchange-pattern.adoc
@@ -38,6 +38,9 @@ xref:components::seda-component.adoc[SEDA], and
xref:components::amqp-component.
These components use the pattern to decide between fire-and-forget and
request/reply messaging.
For example, with JMS `InOnly` sends a message to a queue without waiting for
a reply,
while `InOut` sets up a temporary reply queue (via `JMSReplyTo`) and waits for
a response.
+An exchange created by a consumer that answers its caller, such as HTTP, REST
or platform-http, or by a
+`request` method of a `ProducerTemplate`, is `InOut`. So a
`to("jms:queue:foo")` in its route waits for a reply, up to
+the `requestTimeout` of the endpoint. Use
`jms:queue:foo?exchangePattern=InOnly` when no reply is expected.
For example to override the default pattern on a
xref:components::jms-component.adoc[JMS]
endpoint you could use the `exchangePattern` parameter in the Endpoint
xref:uris.adoc[URI]