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 df3660624bca CAMEL-24071: camel-spring-rabbitmq - Trim queue names and
reject multi-queue polling
df3660624bca is described below
commit df3660624bcaa4ec5fbb86508b5f817aae86a681
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Jul 15 20:13:16 2026 +0200
CAMEL-24071: camel-spring-rabbitmq - Trim queue names and reject
multi-queue polling
Trim each queue name after splitting on comma in
DefaultListenerContainerFactory, so
"q1, q2" no longer creates a listener for " q2" (with leading space) while
declaring
"q2" — fixing a mismatch at runtime. Also reject multiple comma-separated
queues in
SpringRabbitPollingConsumer.doInit() since RabbitTemplate.receive() only
accepts a
single queue name.
Closes #24741
Co-Authored-By: Claude Opus 4.6 <[email protected]>
---
.../DefaultListenerContainerFactory.java | 5 ++-
.../springrabbit/SpringRabbitPollingConsumer.java | 10 ++++-
.../DefaultListenerContainerFactoryTest.java | 40 ++++++++++++++++++++
.../SpringRabbitPollingConsumerTest.java | 43 ++++++++++++++++++++++
4 files changed, 95 insertions(+), 3 deletions(-)
diff --git
a/components/camel-spring-parent/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/DefaultListenerContainerFactory.java
b/components/camel-spring-parent/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/DefaultListenerContainerFactory.java
index f265117b727a..5bc0a4bdd7b4 100644
---
a/components/camel-spring-parent/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/DefaultListenerContainerFactory.java
+++
b/components/camel-spring-parent/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/DefaultListenerContainerFactory.java
@@ -16,6 +16,8 @@
*/
package org.apache.camel.component.springrabbit;
+import java.util.Arrays;
+
import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.rabbit.config.RetryInterceptorBuilder;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
@@ -39,7 +41,8 @@ public class DefaultListenerContainerFactory implements
ListenerContainerFactory
}
if (endpoint.getQueues() != null) {
- listener.setQueueNames(endpoint.getQueues().split(","));
+ listener.setQueueNames(
+
Arrays.stream(endpoint.getQueues().split(",")).map(String::trim).toArray(String[]::new));
}
listener.setAcknowledgeMode(endpoint.getAcknowledgeMode());
listener.setExclusive(endpoint.isExclusive());
diff --git
a/components/camel-spring-parent/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/SpringRabbitPollingConsumer.java
b/components/camel-spring-parent/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/SpringRabbitPollingConsumer.java
index 200477c49d1a..d65f4f7cc0fa 100644
---
a/components/camel-spring-parent/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/SpringRabbitPollingConsumer.java
+++
b/components/camel-spring-parent/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/SpringRabbitPollingConsumer.java
@@ -51,11 +51,12 @@ public class SpringRabbitPollingConsumer extends
PollingConsumerSupport {
@Override
public Exchange receive(long timeout) {
try {
+ String queue = jmsEndpoint.getQueues().trim();
Message message;
if (timeout == 0) {
- message = template.receive(jmsEndpoint.getQueues());
+ message = template.receive(queue);
} else {
- message = template.receive(jmsEndpoint.getQueues(), timeout);
+ message = template.receive(queue, timeout);
}
if (message != null) {
return getEndpoint().createExchange(message);
@@ -71,6 +72,11 @@ public class SpringRabbitPollingConsumer extends
PollingConsumerSupport {
if (getEndpoint().getQueues() == null) {
throw new IllegalArgumentException("Queues must be configured when
using PollingConsumer");
}
+ if (getEndpoint().getQueues().contains(",")) {
+ throw new IllegalArgumentException(
+ "PollingConsumer does not support multiple queues.
Configure a single queue name instead of: "
+ + getEndpoint().getQueues());
+ }
}
@Override
diff --git
a/components/camel-spring-parent/camel-spring-rabbitmq/src/test/java/org/apache/camel/component/springrabbit/DefaultListenerContainerFactoryTest.java
b/components/camel-spring-parent/camel-spring-rabbitmq/src/test/java/org/apache/camel/component/springrabbit/DefaultListenerContainerFactoryTest.java
new file mode 100644
index 000000000000..f2550d0d21ef
--- /dev/null
+++
b/components/camel-spring-parent/camel-spring-rabbitmq/src/test/java/org/apache/camel/component/springrabbit/DefaultListenerContainerFactoryTest.java
@@ -0,0 +1,40 @@
+/*
+ * 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.springrabbit;
+
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
+import
org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+
+public class DefaultListenerContainerFactoryTest extends CamelTestSupport {
+
+ @Test
+ void queueNamesShouldBeTrimmedAfterSplit() throws Exception {
+ SpringRabbitMQEndpoint endpoint
+ = context.getEndpoint("spring-rabbitmq:default?queues=myqueue,
myotherqueue", SpringRabbitMQEndpoint.class);
+ endpoint.setConnectionFactory(new
CachingConnectionFactory("localhost"));
+
+ DefaultListenerContainerFactory factory = new
DefaultListenerContainerFactory();
+ AbstractMessageListenerContainer listener =
factory.createListenerContainer(endpoint);
+
+ assertArrayEquals(new String[] { "myqueue", "myotherqueue" },
listener.getQueueNames(),
+ "queue names must be trimmed after splitting on comma");
+ }
+}
diff --git
a/components/camel-spring-parent/camel-spring-rabbitmq/src/test/java/org/apache/camel/component/springrabbit/SpringRabbitPollingConsumerTest.java
b/components/camel-spring-parent/camel-spring-rabbitmq/src/test/java/org/apache/camel/component/springrabbit/SpringRabbitPollingConsumerTest.java
new file mode 100644
index 000000000000..ccf0abf04938
--- /dev/null
+++
b/components/camel-spring-parent/camel-spring-rabbitmq/src/test/java/org/apache/camel/component/springrabbit/SpringRabbitPollingConsumerTest.java
@@ -0,0 +1,43 @@
+/*
+ * 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.springrabbit;
+
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class SpringRabbitPollingConsumerTest extends CamelTestSupport {
+
+ @Test
+ void multipleQueuesShouldBeRejected() throws Exception {
+ SpringRabbitMQEndpoint endpoint
+ = context.getEndpoint("spring-rabbitmq:default?queues=q1,q2",
SpringRabbitMQEndpoint.class);
+ CachingConnectionFactory cf = new
CachingConnectionFactory("localhost");
+ endpoint.setConnectionFactory(cf);
+ RabbitTemplate template = new RabbitTemplate(cf);
+
+ SpringRabbitPollingConsumer consumer = new
SpringRabbitPollingConsumer(endpoint, template);
+
+ IllegalArgumentException ex =
assertThrows(IllegalArgumentException.class, consumer::doInit);
+ assertTrue(ex.getMessage().contains("does not support multiple
queues"),
+ "error message should explain that polling consumer does not
support multiple queues");
+ }
+}