This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 76479634bf35 CAMEL-23676: camel-nats - Only send reply when exchange
pattern is InOut (#23739)
76479634bf35 is described below
commit 76479634bf35639e8afc780df2307612aaa25293
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Jun 4 16:24:55 2026 +0200
CAMEL-23676: camel-nats - Only send reply when exchange pattern is InOut
(#23739)
* CAMEL-23676: camel-nats - Only send reply when exchange pattern is InOut
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
* CAMEL-23676: camel-nats - Remove auto-set InOut, require explicit
exchangePattern for reply
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
* CAMEL-23676: camel-nats - Add upgrade guide entry for reply-to behavior
change
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
---------
Signed-off-by: Claus Ibsen <[email protected]>
Co-authored-by: Claude Opus 4.6 <[email protected]>
---
.../org/apache/camel/component/nats/NatsConsumer.java | 5 +++--
.../nats/integration/NatsConsumerReplyToIT.java | 2 +-
...ReplyToIT.java => NatsConsumerReplyToInOnlyIT.java} | 18 ++++++++----------
.../ROOT/pages/camel-4x-upgrade-guide-4_21.adoc | 17 +++++++++++++++++
4 files changed, 29 insertions(+), 13 deletions(-)
diff --git
a/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsConsumer.java
b/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsConsumer.java
index 2a1ce6df6113..1630fa1b8e32 100644
---
a/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsConsumer.java
+++
b/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsConsumer.java
@@ -384,9 +384,10 @@ public class NatsConsumer extends DefaultConsumer {
NatsConsumer.this.processor.process(exchange);
- // is there a reply?
+ // is there a reply? only send reply if exchange pattern
supports output (InOut)
if
(!NatsConsumingTask.this.configuration.isReplyToDisabled()
- && msg.getReplyTo() != null && msg.getConnection()
!= null) {
+ && msg.getReplyTo() != null && msg.getConnection()
!= null
+ && exchange.getPattern().isOutCapable()) {
final Connection con = msg.getConnection();
final byte[] data =
exchange.getMessage().getBody(byte[].class);
if (data != null) {
diff --git
a/components/camel-nats/src/test/java/org/apache/camel/component/nats/integration/NatsConsumerReplyToIT.java
b/components/camel-nats/src/test/java/org/apache/camel/component/nats/integration/NatsConsumerReplyToIT.java
index 2c7bc8656387..7a640ba5a3b5 100644
---
a/components/camel-nats/src/test/java/org/apache/camel/component/nats/integration/NatsConsumerReplyToIT.java
+++
b/components/camel-nats/src/test/java/org/apache/camel/component/nats/integration/NatsConsumerReplyToIT.java
@@ -53,7 +53,7 @@ public class NatsConsumerReplyToIT extends NatsITSupport {
from("direct:send")
.to("nats:test?replySubject=myReplyQueue&flushConnection=true");
- from("nats:test?flushConnection=true")
+ from("nats:test?flushConnection=true&exchangePattern=InOut")
.to(mockResultEndpoint)
.convertBodyTo(String.class)
.setBody().simple("Bye ${body}");
diff --git
a/components/camel-nats/src/test/java/org/apache/camel/component/nats/integration/NatsConsumerReplyToIT.java
b/components/camel-nats/src/test/java/org/apache/camel/component/nats/integration/NatsConsumerReplyToInOnlyIT.java
similarity index 74%
copy from
components/camel-nats/src/test/java/org/apache/camel/component/nats/integration/NatsConsumerReplyToIT.java
copy to
components/camel-nats/src/test/java/org/apache/camel/component/nats/integration/NatsConsumerReplyToInOnlyIT.java
index 2c7bc8656387..f259f66546be 100644
---
a/components/camel-nats/src/test/java/org/apache/camel/component/nats/integration/NatsConsumerReplyToIT.java
+++
b/components/camel-nats/src/test/java/org/apache/camel/component/nats/integration/NatsConsumerReplyToInOnlyIT.java
@@ -19,10 +19,9 @@ package org.apache.camel.component.nats.integration;
import org.apache.camel.EndpointInject;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.component.nats.NatsConstants;
import org.junit.jupiter.api.Test;
-public class NatsConsumerReplyToIT extends NatsITSupport {
+public class NatsConsumerReplyToInOnlyIT extends NatsITSupport {
@EndpointInject("mock:result")
protected MockEndpoint mockResultEndpoint;
@@ -31,17 +30,16 @@ public class NatsConsumerReplyToIT extends NatsITSupport {
protected MockEndpoint mockReplyEndpoint;
@Test
- public void testReplyTo() throws Exception {
+ public void testInOnlyNoReply() throws Exception {
mockResultEndpoint.expectedBodiesReceived("World");
- mockResultEndpoint.expectedHeaderReceived(NatsConstants.NATS_SUBJECT,
"test");
- mockReplyEndpoint.expectedBodiesReceived("Bye World");
- mockReplyEndpoint.expectedHeaderReceived(NatsConstants.NATS_SUBJECT,
"myReplyQueue");
+ // reply endpoint should NOT receive any message when exchange pattern
is InOnly
+ mockReplyEndpoint.expectedMessageCount(0);
template.sendBody("direct:send", "World");
mockResultEndpoint.setAssertPeriod(5000);
mockResultEndpoint.assertIsSatisfied();
- mockReplyEndpoint.setAssertPeriod(5000);
+ mockReplyEndpoint.setAssertPeriod(2000);
mockReplyEndpoint.assertIsSatisfied();
}
@@ -51,14 +49,14 @@ public class NatsConsumerReplyToIT extends NatsITSupport {
@Override
public void configure() {
from("direct:send")
-
.to("nats:test?replySubject=myReplyQueue&flushConnection=true");
+
.to("nats:testInOnly?replySubject=myReplyInOnly&flushConnection=true");
- from("nats:test?flushConnection=true")
+
from("nats:testInOnly?flushConnection=true&exchangePattern=InOnly")
.to(mockResultEndpoint)
.convertBodyTo(String.class)
.setBody().simple("Bye ${body}");
- from("nats:myReplyQueue")
+ from("nats:myReplyInOnly")
.to("mock:reply");
}
};
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_21.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_21.adoc
index 702d78ff39a8..50d714498733 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_21.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_21.adoc
@@ -344,6 +344,23 @@ Or, on a single endpoint:
jms:queue:foo?objectMessageEnabled=true
----
+=== camel-nats
+
+The NATS consumer no longer sends a reply to the `replyTo` subject by default.
Previously, the consumer
+would unconditionally publish the exchange body back to the NATS `replyTo`
subject after route processing,
+regardless of the exchange pattern. This could cause `TypeConversionException`
or payload-size-exceeded
+errors when the route body was not suitable for reply.
+
+The reply is now only sent when the exchange pattern is `InOut`. To restore
request/reply behavior, set
+`exchangePattern=InOut` on the consumer endpoint:
+
+[source,text]
+----
+nats:myTopic?exchangePattern=InOut
+----
+
+Routes that do not use NATS request/reply are unaffected.
+
=== camel-sjms / camel-sjms2
The same default applies to `camel-sjms` (and `camel-sjms2`, which inherits
from it): JMS `ObjectMessage`