001/*002 * Copyright 2012-2016 the original author or authors.003 *004 * Licensed under the Apache License, Version 2.0 (the "License");005 * you may not use this file except in compliance with the License.006 * You may obtain a copy of the License at007 *008 * http://www.apache.org/licenses/LICENSE-2.0009 *010 * Unless required by applicable law or agreed to in writing, software011 * distributed under the License is distributed on an "AS IS" BASIS,012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.013 * See the License for the specific language governing permissions and014 * limitations under the License.015 */016017package org.springframework.boot.autoconfigure.amqp;018019import com.rabbitmq.client.Channel;020021import org.springframework.amqp.core.AmqpAdmin;022import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;023import org.springframework.amqp.rabbit.connection.ConnectionFactory;024import org.springframework.amqp.rabbit.connection.RabbitConnectionFactoryBean;025import org.springframework.amqp.rabbit.core.RabbitAdmin;026import org.springframework.amqp.rabbit.core.RabbitMessagingTemplate;027import org.springframework.amqp.rabbit.core.RabbitTemplate;028import org.springframework.amqp.support.converter.MessageConverter;029import org.springframework.beans.factory.ObjectProvider;030import org.springframework.boot.autoconfigure.EnableAutoConfiguration;031import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;032import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;033import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;034import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;035import org.springframework.boot.context.properties.EnableConfigurationProperties;036import org.springframework.context.annotation.Bean;037import org.springframework.context.annotation.Configuration;038import org.springframework.context.annotation.Import;039import org.springframework.retry.backoff.ExponentialBackOffPolicy;040import org.springframework.retry.policy.SimpleRetryPolicy;041import org.springframework.retry.support.RetryTemplate;042043/**044 * {@link EnableAutoConfiguration Auto-configuration} for {@link RabbitTemplate}.045 * <p>046 * This configuration class is active only when the RabbitMQ and Spring AMQP client047 * libraries are on the classpath.048 * <P>049 * Registers the following beans:050 * <ul>051 * <li>{@link org.springframework.amqp.rabbit.core.RabbitTemplate RabbitTemplate} if there052 * is no other bean of the same type in the context.</li>053 * <li>{@link org.springframework.amqp.rabbit.connection.CachingConnectionFactory054 * CachingConnectionFactory} instance if there is no other bean of the same type in the055 * context.</li>056 * <li>{@link org.springframework.amqp.core.AmqpAdmin } instance as long as057 * {@literal spring.rabbitmq.dynamic=true}.</li>058 * </ul>059 * <p>060 * The {@link org.springframework.amqp.rabbit.connection.CachingConnectionFactory} honors061 * the following properties:062 * <ul>063 * <li>{@literal spring.rabbitmq.port} is used to specify the port to which the client064 * should connect, and defaults to 5672.</li>065 * <li>{@literal spring.rabbitmq.username} is used to specify the (optional) username.066 * </li>067 * <li>{@liter