Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,7 +41,8 @@ public AbstractMessageListenerContainer createListenerContainer(SpringRabbitMQEn
}

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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ public Exchange receive() {
@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);
Expand All @@ -71,6 +72,11 @@ protected void doInit() throws Exception {
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
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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");
}
}