diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/AbstractRoutingConnectionFactory.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/AbstractRoutingConnectionFactory.java index 97b24b63..aee29b09 100644 --- a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/AbstractRoutingConnectionFactory.java +++ b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/AbstractRoutingConnectionFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2015 the original author or authors. * * Licensed 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 @@ -28,9 +28,10 @@ import org.springframework.util.Assert; * * @author Artem Bilan * @author Josh Chappelle + * @author Gary Russell * @since 1.3 */ -public abstract class AbstractRoutingConnectionFactory implements ConnectionFactory { +public abstract class AbstractRoutingConnectionFactory implements ConnectionFactory, RoutingConnectionFactory { private final Map targetConnectionFactories = new ConcurrentHashMap(); @@ -177,11 +178,7 @@ public abstract class AbstractRoutingConnectionFactory implements ConnectionFact return this.determineTargetConnectionFactory().getVirtualHost(); } - /** - * Returns the {@link ConnectionFactory} bound to given lookup key, null if one does not exist - * @param key The lookup key of which the {@link ConnectionFactory} is bound - * @return the {@link ConnectionFactory} bound to given lookup key, null if one does not exist - */ + @Override public ConnectionFactory getTargetConnectionFactory(Object key) { return targetConnectionFactories.get(key); } diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/RoutingConnectionFactory.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/RoutingConnectionFactory.java new file mode 100644 index 00000000..baf5c4c9 --- /dev/null +++ b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/RoutingConnectionFactory.java @@ -0,0 +1,34 @@ +/* + * Copyright 2015 the original author or authors. + * + * Licensed 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.springframework.amqp.rabbit.connection; + +/** + * Implementations select a connection factory based on a supplied key. + * + * @author Gary Russell + * @since 1.4.5 + * + */ +public interface RoutingConnectionFactory { + + /** + * Returns the {@link ConnectionFactory} bound to given lookup key, or null if one does not exist + * @param key The lookup key to which the {@link ConnectionFactory} is bound + * @return the {@link ConnectionFactory} bound to the given lookup key, or null if one does not exist + */ + ConnectionFactory getTargetConnectionFactory(Object key); + +} diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/AbstractMessageListenerContainer.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/AbstractMessageListenerContainer.java index 1ee0bf02..9e60b592 100644 --- a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/AbstractMessageListenerContainer.java +++ b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/AbstractMessageListenerContainer.java @@ -31,13 +31,13 @@ import org.springframework.amqp.core.MessageListener; import org.springframework.amqp.core.MessagePostProcessor; import org.springframework.amqp.core.MessageProperties; import org.springframework.amqp.core.Queue; -import org.springframework.amqp.rabbit.connection.AbstractRoutingConnectionFactory; import org.springframework.amqp.rabbit.connection.Connection; import org.springframework.amqp.rabbit.connection.ConnectionFactory; import org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils; import org.springframework.amqp.rabbit.connection.RabbitAccessor; import org.springframework.amqp.rabbit.connection.RabbitResourceHolder; import org.springframework.amqp.rabbit.connection.RabbitUtils; +import org.springframework.amqp.rabbit.connection.RoutingConnectionFactory; import org.springframework.amqp.rabbit.core.ChannelAwareMessageListener; import org.springframework.amqp.rabbit.listener.exception.FatalListenerExecutionException; import org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException; @@ -390,8 +390,8 @@ public abstract class AbstractMessageListenerContainer extends RabbitAccessor @Override public ConnectionFactory getConnectionFactory() { ConnectionFactory connectionFactory = super.getConnectionFactory(); - if (connectionFactory instanceof AbstractRoutingConnectionFactory) { - ConnectionFactory targetConnectionFactory = ((AbstractRoutingConnectionFactory) connectionFactory) + if (connectionFactory instanceof RoutingConnectionFactory) { + ConnectionFactory targetConnectionFactory = ((RoutingConnectionFactory) connectionFactory) .getTargetConnectionFactory(this.queueNames.toString().replaceAll(" ", "")); if (targetConnectionFactory != null) { return targetConnectionFactory;