AMQP-494: Extract RoutingConnectionFactory Iface

JIRA: https://jira.spring.io/browse/AMQP-494
This commit is contained in:
Gary Russell
2015-05-01 10:35:25 +01:00
committed by Artem Bilan
parent afeb2b64e7
commit b87f36263a
3 changed files with 41 additions and 10 deletions

View File

@@ -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<Object, ConnectionFactory> targetConnectionFactories =
new ConcurrentHashMap<Object, ConnectionFactory>();
@@ -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);
}

View File

@@ -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);
}

View File

@@ -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;