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 3e34578f441e CAMEL-27014: camel-jms - pollEnrich and ConsumerTemplate
read the message before the JMS session is closed (#30164)
3e34578f441e is described below
commit 3e34578f441ec770954d901d615e450c6df067b3
Author: Federico Mariani <[email protected]>
AuthorDate: Mon Nov 16 14:13:19 2026 +0100
CAMEL-27014: camel-jms - pollEnrich and ConsumerTemplate read the message
before the JMS session is closed (#30164)
* CAMEL-27014: camel-jms - pollEnrich and ConsumerTemplate read the message
before the JMS session is closed
* CAMEL-27014: camel-jms - roll back or recover the session when the polled
message cannot be read, and document when the body is not read at receive time
---
.../apache/camel/catalog/docs/jms-component.adoc | 9 +
.../camel-jms/src/main/docs/jms-component.adoc | 9 +
.../camel/component/jms/JmsConfiguration.java | 88 ++++++++
.../camel/component/jms/JmsPollingConsumer.java | 22 +-
.../component/jms/JmsObjectMessageEnabledTest.java | 8 +-
.../jms/JmsPollingConsumerLargeMessageTest.java | 244 +++++++++++++++++++++
.../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc | 8 +
7 files changed, 380 insertions(+), 8 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 166c7ea0304c..53e8fe260290 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
@@ -883,6 +883,15 @@ As all the above information is standard JMS, you can
check the
http://java.sun.com/javaee/5/docs/api/javax/jms/Message.html[JMS
documentation] for further details.
+When `pollEnrich` or a `ConsumerTemplate` receives a message from a JMS
endpoint, Camel reads the body and the
+headers of the message before it closes the JMS consumer and session, as a JMS
client may not read the message after
+that (the ActiveMQ Artemis client streams the body of a large message through
the consumer). The whole body is read at
+once (with `artemisStreamingEnabled`, into a stream cache). If the body cannot
be read, the receive fails, and the
+message is rolled back with `transacted=true`, or recovered with
`CLIENT_ACKNOWLEDGE`, so that it is delivered again.
+The body is not read at receive time with `mapJmsMessage=false` (the body is
the `jakarta.jms.Message` itself), for a
+`StreamMessage` (the body is an `InputStream` that reads the message when it
is used), and with a custom
+`jmsOperations` that is not a `CamelJmsTemplate` (the message is read after
the session is closed, as before).
+
=== About using Camel to send and receive messages and JMSReplyTo
The JMS component is complex, and you have to pay close attention to how
diff --git a/components/camel-jms/src/main/docs/jms-component.adoc
b/components/camel-jms/src/main/docs/jms-component.adoc
index 166c7ea0304c..53e8fe260290 100644
--- a/components/camel-jms/src/main/docs/jms-component.adoc
+++ b/components/camel-jms/src/main/docs/jms-component.adoc
@@ -883,6 +883,15 @@ As all the above information is standard JMS, you can
check the
http://java.sun.com/javaee/5/docs/api/javax/jms/Message.html[JMS
documentation] for further details.
+When `pollEnrich` or a `ConsumerTemplate` receives a message from a JMS
endpoint, Camel reads the body and the
+headers of the message before it closes the JMS consumer and session, as a JMS
client may not read the message after
+that (the ActiveMQ Artemis client streams the body of a large message through
the consumer). The whole body is read at
+once (with `artemisStreamingEnabled`, into a stream cache). If the body cannot
be read, the receive fails, and the
+message is rolled back with `transacted=true`, or recovered with
`CLIENT_ACKNOWLEDGE`, so that it is delivered again.
+The body is not read at receive time with `mapJmsMessage=false` (the body is
the `jakarta.jms.Message` itself), for a
+`StreamMessage` (the body is an `InputStream` that reads the message when it
is used), and with a custom
+`jmsOperations` that is not a `CamelJmsTemplate` (the message is read after
the session is closed, as before).
+
=== About using Camel to send and receive messages and JMSReplyTo
The JMS component is complex, and you have to pay close attention to how
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 5867de2f3220..1e78da6f9023 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
@@ -16,11 +16,14 @@
*/
package org.apache.camel.component.jms;
+import java.util.function.Function;
+
import jakarta.jms.ConnectionFactory;
import jakarta.jms.Destination;
import jakarta.jms.ExceptionListener;
import jakarta.jms.JMSException;
import jakarta.jms.Message;
+import jakarta.jms.MessageConsumer;
import jakarta.jms.MessageProducer;
import jakarta.jms.Session;
@@ -33,6 +36,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.task.TaskExecutor;
import org.springframework.jms.JmsException;
+import org.springframework.jms.connection.JmsResourceHolder;
import org.springframework.jms.connection.JmsTransactionManager;
import org.springframework.jms.core.JmsOperations;
import org.springframework.jms.core.JmsTemplate;
@@ -44,6 +48,7 @@ import org.springframework.jms.support.JmsUtils;
import org.springframework.jms.support.converter.MessageConverter;
import org.springframework.jms.support.destination.DestinationResolver;
import org.springframework.transaction.PlatformTransactionManager;
+import
org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.util.Assert;
import org.springframework.util.ErrorHandler;
@@ -679,6 +684,89 @@ public class JmsConfiguration implements Cloneable {
}
}
+ /**
+ * Receives a message from the default destination, and applies the
function to it before the message is
+ * acknowledged (or the session committed) and before the consumer and
the session are closed.
+ * <p/>
+ * {@link #receiveSelected(String)} returns the message after the
consumer and the session are closed, when a
+ * JMS client may no longer read it: the Apache Artemis client streams
the body of a large message through the
+ * consumer. If the function fails, the message is not acknowledged: a
locally transacted session is rolled
+ * back, and a client acknowledge session is recovered, so the message
is delivered again.
+ *
+ * @param messageSelector the message selector, or <tt>null</tt> for
none
+ * @param function the function to apply to the received
message
+ * @return the result of the function, or
<tt>null</tt> if no message was received within the
+ * receive timeout
+ */
+ public <T> T receiveSelectedAndApply(final String messageSelector,
final Function<Message, T> function)
+ throws JmsException {
+ return execute(session -> {
+ Destination destination = getDefaultDestination();
+ if (destination == null) {
+ String destinationName = getDefaultDestinationName();
+ if (destinationName == null) {
+ throw new IllegalStateException(
+ "No 'defaultDestination' or
'defaultDestinationName' specified. Check configuration of JmsTemplate.");
+ }
+ destination = resolveDestinationName(session,
destinationName);
+ }
+ return doReceiveAndApply(session, createConsumer(session,
destination, messageSelector), function);
+ }, true);
+ }
+
+ private <T> T doReceiveAndApply(Session session, MessageConsumer
consumer, Function<Message, T> function)
+ throws JMSException {
+ try {
+ // use the transaction timeout (if available), as JmsTemplate
does
+ long timeout = getReceiveTimeout();
+ ConnectionFactory connectionFactory = getConnectionFactory();
+ JmsResourceHolder resourceHolder = null;
+ if (connectionFactory != null) {
+ resourceHolder = (JmsResourceHolder)
TransactionSynchronizationManager.getResource(connectionFactory);
+ }
+ if (resourceHolder != null && resourceHolder.hasTimeout()) {
+ timeout = Math.min(timeout,
resourceHolder.getTimeToLiveInMillis());
+ }
+ Message message = receiveFromConsumer(consumer, timeout);
+ T answer;
+ try {
+ answer = message != null ? function.apply(message) : null;
+ } catch (RuntimeException | Error e) {
+ rollbackOnException(session, e);
+ throw e;
+ }
+ if (session.getTransacted()) {
+ commitIfNecessary(session);
+ } else if (message != null && isClientAcknowledge(session)) {
+ message.acknowledge();
+ }
+ return answer;
+ } finally {
+ JmsUtils.closeMessageConsumer(consumer);
+ }
+ }
+
+ /**
+ * Rolls back a locally transacted session, or recovers a client
acknowledge session, when the function failed,
+ * as Spring's message listener container does. A pooled or cached
session is not closed after the receive, so
+ * the message would otherwise stay unacknowledged on it, and the next
acknowledge on that session would
+ * acknowledge it too. A failure of the rollback is added to the cause
as a suppressed exception.
+ */
+ private void rollbackOnException(Session session, Throwable cause) {
+ try {
+ if (session.getTransacted()) {
+ // a session bound to a transaction manager is rolled back
by the transaction manager
+ if (isSessionLocallyTransacted(session)) {
+ JmsUtils.rollbackIfNecessary(session);
+ }
+ } else if (isClientAcknowledge(session)) {
+ session.recover();
+ }
+ } catch (JMSException | RuntimeException e) {
+ cause.addSuppressed(e);
+ }
+ }
+
/**
* Override so we can support preserving the Qos settings that have
been set on the message.
*/
diff --git
a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsPollingConsumer.java
b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsPollingConsumer.java
index 2e6eac1ee0ae..5b9b15540cf5 100644
---
a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsPollingConsumer.java
+++
b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsPollingConsumer.java
@@ -19,6 +19,7 @@ package org.apache.camel.component.jms;
import jakarta.jms.Message;
import org.apache.camel.Exchange;
+import org.apache.camel.component.jms.JmsConfiguration.CamelJmsTemplate;
import org.apache.camel.support.PollingConsumerSupport;
import org.apache.camel.util.ObjectHelper;
import org.springframework.jms.core.JmsOperations;
@@ -55,13 +56,18 @@ public class JmsPollingConsumer extends
PollingConsumerSupport {
@Override
public Exchange receive(long timeout) {
+ String selector = ObjectHelper.isNotEmpty(jmsEndpoint.getSelector()) ?
jmsEndpoint.getSelector() : null;
Message message;
// synchronize to make set-timeout + receive atomic, as the polling
consumer
// may be shared across concurrent pollEnrich / ConsumerTemplate
callers
synchronized (template) {
setReceiveTimeout(timeout);
- if (ObjectHelper.isNotEmpty(jmsEndpoint.getSelector())) {
- message = template.receiveSelected(jmsEndpoint.getSelector());
+ if (template instanceof CamelJmsTemplate camelJmsTemplate) {
+ // read the message before the JMS consumer and session are
closed
+ return camelJmsTemplate.receiveSelectedAndApply(selector,
this::createExchange);
+ }
+ if (selector != null) {
+ message = template.receiveSelected(selector);
} else {
message = template.receive();
}
@@ -72,6 +78,18 @@ public class JmsPollingConsumer extends
PollingConsumerSupport {
return null;
}
+ /**
+ * Creates the exchange for the received message, and reads the body and
the headers of the message. It is called
+ * before the JMS consumer and session are closed, as a JMS client may not
read the message after that: the Apache
+ * Artemis client streams the body of a large message through the consumer.
+ */
+ protected Exchange createExchange(Message message) {
+ Exchange exchange = getEndpoint().createExchange(message, null);
+ exchange.getIn().getBody();
+ exchange.getIn().getHeaders();
+ return exchange;
+ }
+
@Override
protected void doStart() throws Exception {
// noop
diff --git
a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsObjectMessageEnabledTest.java
b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsObjectMessageEnabledTest.java
index 315d295430f1..e0d1e5000041 100644
---
a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsObjectMessageEnabledTest.java
+++
b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsObjectMessageEnabledTest.java
@@ -24,7 +24,6 @@ import jakarta.jms.ObjectMessage;
import org.apache.camel.CamelContext;
import org.apache.camel.CamelExecutionException;
import org.apache.camel.ConsumerTemplate;
-import org.apache.camel.Exchange;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.infra.core.CamelContextExtension;
@@ -35,7 +34,6 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.springframework.jms.core.JmsTemplate;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -100,11 +98,9 @@ public class JmsObjectMessageEnabledTest extends
AbstractJMSTest {
return msg;
});
- // Reading the body via Camel should fail because
objectMessageEnabled=false
- Exchange exchange =
consumer.receive("activemq:JmsObjectMessageEnabledTest.consumer", 5000);
- assertNotNull(exchange, "Should have received the exchange wrapper");
+ // Receiving via Camel should fail because objectMessageEnabled=false
(the receive reads the body)
IllegalStateException ex = assertThrows(IllegalStateException.class,
- () -> exchange.getIn().getBody());
+ () ->
consumer.receive("activemq:JmsObjectMessageEnabledTest.consumer", 5000));
assertTrue(ex.getMessage().contains("objectMessageEnabled=true"),
"Expected guidance to enable objectMessageEnabled=true, got: "
+ ex.getMessage());
}
diff --git
a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsPollingConsumerLargeMessageTest.java
b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsPollingConsumerLargeMessageTest.java
new file mode 100644
index 000000000000..548c46feaeba
--- /dev/null
+++
b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsPollingConsumerLargeMessageTest.java
@@ -0,0 +1,244 @@
+/*
+ * 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.Arrays;
+
+import jakarta.jms.ConnectionFactory;
+import jakarta.jms.Message;
+import jakarta.jms.ObjectMessage;
+
+import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
+import org.apache.camel.CamelContext;
+import org.apache.camel.ConsumerTemplate;
+import org.apache.camel.Exchange;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.infra.artemis.services.ArtemisService;
+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 org.messaginghub.pooled.jms.JmsPoolConnectionFactory;
+import org.springframework.jms.core.JmsTemplate;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+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.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The polling consumer (pollEnrich and ConsumerTemplate) reads the message
before the JMS consumer and session are
+ * closed. The Artemis client streams the body of a large message through the
consumer, so the body cannot be read after
+ * the consumer is closed.
+ */
+public class JmsPollingConsumerLargeMessageTest extends AbstractJMSTest {
+
+ private static final String QUEUE = "JmsPollingConsumerLargeMessageTest";
+ private static final byte[] LARGE = payload(200_000);
+ private static final byte[] SMALL = payload(512);
+
+ @Order(2)
+ @RegisterExtension
+ public static CamelContextExtension camelContextExtension = new
TransientCamelContextExtension();
+
+ protected CamelContext context;
+ protected ProducerTemplate template;
+ protected ConsumerTemplate consumer;
+ protected ConnectionFactory connectionFactory;
+ protected JmsTemplate jmsTemplate;
+
+ @Override
+ protected String getComponentName() {
+ return "jms";
+ }
+
+ @Override
+ protected JmsComponent setupComponent(CamelContext camelContext,
ArtemisService service, String componentName) {
+ // every message above 1 KB is an Artemis large message
+ connectionFactory = new
ActiveMQConnectionFactory(service.serviceAddress() +
"?minLargeMessageSize=1024");
+ jmsTemplate = new JmsTemplate(connectionFactory);
+ jmsTemplate.setReceiveTimeout(5000);
+ return setupComponent(camelContext, connectionFactory, componentName);
+ }
+
+ @Test
+ void consumerTemplateReceivesLargeBytesMessage() {
+ template.sendBody("jms:queue:" + QUEUE + ".receive", LARGE);
+
+ Exchange exchange = consumer.receive("jms:queue:" + QUEUE +
".receive", 5000);
+
+ assertNotNull(exchange);
+ // the message is an Artemis large message
+ assertEquals(200_000L, exchange.getIn().getHeader("_AMQ_LARGE_SIZE",
Long.class));
+ assertArrayEquals(LARGE, exchange.getIn().getBody(byte[].class));
+ }
+
+ @Test
+ void consumerTemplateReceivesLargeBytesMessageWithArtemisStreaming() {
+ String uri = "jms:queue:" + QUEUE +
".streaming?artemisStreamingEnabled=true";
+ template.sendBody(uri, LARGE);
+
+ Exchange exchange = consumer.receive(uri, 5000);
+
+ assertNotNull(exchange);
+ assertArrayEquals(LARGE, exchange.getIn().getBody(byte[].class));
+ }
+
+ @Test
+ void consumerTemplateReceivesLargeBytesMessageWithSelector() {
+ String uri = "jms:queue:" + QUEUE + ".selector";
+ template.sendBodyAndHeader(uri, "other", "kind", "other");
+ template.sendBodyAndHeader(uri, LARGE, "kind", "large");
+
+ assertArrayEquals(LARGE, consumer.receiveBody(uri +
"?selector=kind='large'", 5000, byte[].class));
+ assertEquals("other", consumer.receiveBody(uri +
"?selector=kind='other'", 5000, String.class));
+ }
+
+ @Test
+ void pollEnrichReceivesLargeBytesMessage() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:" + QUEUE + ".result");
+ mock.expectedMessageCount(1);
+ template.sendBody("jms:queue:" + QUEUE + ".pollEnrich", LARGE);
+
+ template.sendBody("direct:" + QUEUE + ".pollEnrich", "trigger");
+
+ MockEndpoint.assertIsSatisfied(context);
+ assertArrayEquals(LARGE,
mock.getReceivedExchanges().get(0).getIn().getBody(byte[].class));
+ }
+
+ @Test
+ void transactedConsumerTemplateCommitsTheReceive() {
+ String uri = "jms:queue:" + QUEUE + ".transacted?transacted=true";
+ template.sendBody(uri, LARGE);
+
+ assertArrayEquals(LARGE, consumer.receiveBody(uri, 5000,
byte[].class));
+ // the message is not delivered again
+ assertNull(consumer.receive(uri, 1000));
+ }
+
+ @Test
+ void clientAcknowledgeConsumerTemplateAcknowledgesTheMessage() {
+ String uri = "jms:queue:" + QUEUE +
".clientAck?acknowledgementModeName=CLIENT_ACKNOWLEDGE";
+ template.sendBody(uri, LARGE);
+
+ assertArrayEquals(LARGE, consumer.receiveBody(uri, 5000,
byte[].class));
+ // the message is not delivered again
+ assertNull(consumer.receive(uri, 1000));
+ }
+
+ @Test
+ void transactedConsumerTemplateRollsBackMessageWhoseBodyCannotBeRead()
throws Exception {
+ String queue = QUEUE + ".unreadable";
+ jmsTemplate.send(queue, session -> session.createObjectMessage("not
allowed"));
+
+ // objectMessageEnabled is false, so the body cannot be read: the
receive fails and is rolled back
+ IllegalStateException e = assertThrows(IllegalStateException.class,
+ () -> consumer.receive("jms:queue:" + queue +
"?transacted=true", 5000));
+ assertTrue(e.getMessage().contains("objectMessageEnabled=true"),
e.getMessage());
+
+ Message message = jmsTemplate.receive(queue);
+ assertEquals("not allowed", assertInstanceOf(ObjectMessage.class,
message).getObject());
+ }
+
+ @Test
+ void
clientAcknowledgeConsumerTemplateRecoversMessageWhoseBodyCannotBeRead() throws
Exception {
+ String queue = QUEUE + ".unreadableClientAck";
+ String options = "?acknowledgementModeName=CLIENT_ACKNOWLEDGE";
+ // a pooled session (as with camel-activemq) is not closed after the
receive, but goes back to the pool
+ JmsPoolConnectionFactory pooledConnectionFactory = new
JmsPoolConnectionFactory();
+ pooledConnectionFactory.setConnectionFactory(connectionFactory);
+ try {
+ context.addComponent("pooledjms",
JmsComponent.jmsComponentAutoAcknowledge(pooledConnectionFactory));
+ jmsTemplate.send(queue, session ->
session.createObjectMessage("not allowed"));
+
+ // objectMessageEnabled is false, so the body cannot be read: the
receive fails and the session is recovered
+ IllegalStateException e = assertThrows(IllegalStateException.class,
+ () -> consumer.receive("pooledjms:queue:" + queue +
options, 5000));
+ assertTrue(e.getMessage().contains("objectMessageEnabled=true"),
e.getMessage());
+
+ // the next receive on the pooled session acknowledges its own
message only
+ template.sendBody("jms:queue:" + queue + ".next", "next");
+ assertEquals("next", consumer.receiveBody("pooledjms:queue:" +
queue + ".next" + options, 5000, String.class));
+
+ Message message = jmsTemplate.receive(queue);
+ assertEquals("not allowed", assertInstanceOf(ObjectMessage.class,
message).getObject());
+ assertTrue(message.getJMSRedelivered());
+ } finally {
+ pooledConnectionFactory.stop();
+ }
+ }
+
+ @Test
+ void consumerTemplateReceivesSmallBytesMessage() {
+ template.sendBody("jms:queue:" + QUEUE + ".small", SMALL);
+
+ assertArrayEquals(SMALL, consumer.receiveBody("jms:queue:" + QUEUE +
".small", 5000, byte[].class));
+ }
+
+ @Test
+ void routeReceivesLargeBytesMessage() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:" + QUEUE + ".route");
+ mock.expectedMessageCount(1);
+
+ template.sendBody("jms:queue:" + QUEUE + ".route", LARGE);
+
+ MockEndpoint.assertIsSatisfied(context);
+ assertArrayEquals(LARGE,
mock.getReceivedExchanges().get(0).getIn().getBody(byte[].class));
+ }
+
+ private static byte[] payload(int size) {
+ byte[] answer = new byte[size];
+ Arrays.fill(answer, (byte) 'a');
+ for (int i = 0; i < size; i += 1000) {
+ answer[i] = (byte) ('0' + (i / 1000) % 10);
+ }
+ return answer;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("jms:queue:" + QUEUE + ".route").to("mock:" + QUEUE +
".route");
+
+ from("direct:" + QUEUE + ".pollEnrich")
+ .pollEnrich("jms:queue:" + QUEUE + ".pollEnrich", 5000)
+ .to("mock:" + QUEUE + ".result");
+ }
+ };
+ }
+
+ @Override
+ public CamelContextExtension getCamelContextExtension() {
+ return camelContextExtension;
+ }
+
+ @BeforeEach
+ void setUpRequirements() {
+ context = camelContextExtension.getContext();
+ template = camelContextExtension.getProducerTemplate();
+ consumer = camelContextExtension.getConsumerTemplate();
+ }
+}
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 a4bd0d7a1650..f846f815c0cf 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
@@ -462,6 +462,14 @@ the error handler (such as the dead letter channel or
`onException`) without red
body. Before, when the error handler had redeliveries, the first step of the
route was redelivered with that body and,
when it succeeded, the message went on through the route and never reached the
error handler.
+=== camel-jms - pollEnrich and ConsumerTemplate read the message before they
close the session
+
+`pollEnrich` and a `ConsumerTemplate` on a `jms` endpoint now read the body
and the headers of the message before they
+close the JMS consumer and session. Before, the body was read when the
exchange first used it, after the session was
+closed, so the body of an ActiveMQ Artemis large message failed with
`AMQ219023`. A message whose body cannot be read
+(such as an `ObjectMessage` while `objectMessageEnabled` is `false`) now fails
the receive itself, and the message is
+rolled back with `transacted=true`, or recovered with `CLIENT_ACKNOWLEDGE`,
instead of committed or acknowledged.
+
=== camel-keycloak - Keycloak 26.8.2 requires the kc-admin-api client scope
This is a change in Keycloak, not in Camel: from Keycloak 26.8.2 the Admin
REST API accepts only access tokens that