2.2_springboot2.x消息RabbitMQ整合&amqpAdmin管理组件的使用

本文介绍了如何在SpringBoot应用中整合RabbitMQ,使用RabbitTemplate进行消息发送和接收,以及AmqpAdmin组件来管理队列、交换器和绑定。通过@RabbitListener和@EnableRabbit注解实现消息监听,详细讲解了测试用例和配置过程。
摘要由CSDN通过智能技术生成
5.1.1、基本测试

1.引 spring-boot-starter-amqp**

 <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-amqp</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.amqp</groupId>
            <artifactId>spring-rabbit-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

自动配置原理说明 RabbitAutoConfiguration

1、有自动配置了连接工厂CachingConnectionFactory;获取与rabbitmq连接信息

@Configuration
@ConditionalOnClass({
    RabbitTemplate.class, Channel.class })
@EnableConfigurationProperties(RabbitProperties.class)
@Import(RabbitAnnotationDrivenConfiguration.class)
public class RabbitAutoConfiguration {
   

	@Configuration
	@ConditionalOnMissingBean(ConnectionFactory.class)
	protected static class RabbitConnectionFactoryCreator {
   

		@Bean
		public CachingConnectionFactory rabbitConnectionFactory(RabbitProperties properties,
				ObjectProvider<ConnectionNameStrategy> connectionNameStrategy) throws Exception {
   
            
           ... 
        }
        ...

2、RabbitProperties封装了 RabbitMQ的配置

@ConfigurationProperties(prefix = "spring.rabbitmq")
public class RabbitProperties {
   

	/**
	 * RabbitMQ host.
	 */
	private String host = "localhost";

	/**
	 * RabbitMQ port.
	 */
	private int port = 5672;
    ....
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值