Springboot+RabbitMQ消息队列
2019-01-31 16:19
435 查看
第一步:安装对应的RabbitMQ安装和配置
RabbitMQ是基于Erlang语言开发的。所以安装RabbitMQ之前需要先下载安装配置Erlang,下载地址:http://www.erlang.org/downloads
并将安装后的......\erl9.0\bin的bin目录配置到path环境变量中。然后下载安装RabbitMQ。下载地址:http://www.rabbitmq.com/download.html
安装完成之后在开始菜单中找到RabbitMQ Command Promt,打开控制台,输入命令:
rabbitmq-plugins enable rabbitmq_management
第二步:springboot对应的配置:
pom.xml中添加
[code]<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-amqp</artifactId> </dependency>
application.properties文件添加配置
[code]#队列 spring.rabbitmq.host=localhost //队列地址 spring.rabbitmq.port=5672 //端口号 spring.rabbitmq.username=guest spring.rabbitmq.password=guest
第三步:配置队列
[code]@Configuration public class RabbitMQconfig { public static final String QUEUE = "direct_queue"; @Bean public Queue directQueue(){ return new Queue(QUEUE,true); } }
第四步:发送端
[code]@SpringBootApplication @MapperScan("com.csv.dao") public class CsvApplication implements CommandLineRunner { @Autowired private AmqpTemplate amqpTemplate; public static void main(String[] args) { SpringApplication.run( CsvApplication.class, args ); } @Override public void run(String... args) { String massage="哈喽,帅哥"; amqpTemplate.convertSendAndReceive( RabbitMQconfig.QUEUE,massage); System.out.println("ok"); } }
第五步:接收端
[code]public class Receiver { @RabbitListener(queues = RabbitMQconfig.QUEUE) public void ReceiveMesaage(String message){ System.out.println("接受到"+message); } }
接收到的效果
这个是自己学习的一个简单的练习,如有不对,请指教。
相关文章推荐
- Spring Boot + RabbitMQ 实现消息队列场景
- 集群与负载均衡系列(6)——消息队列之rabbitMQ+spring-boot+spring amqp发送可靠的消息
- spring boot Rabbitmq集成,延时消息队列实现
- spring boot Rabbitmq集成,延时消息队列实现
- 第四十六章:SpringBoot & RabbitMQ完成消息延迟消费
- Spring Boot RabbitMQ 延迟消息实现完整版
- Springboot+rabbitmq实现延时队列的两种方式
- SpringBoot+ActiveMQ多消息队列监听
- Spring Boot--整合阿里云消息队列MQ
- SpringBoot对消息队列(MQ)的支持
- springboot + rabbitmq 消费者消息确认 (Ack)
- spring boot rabbitmq 多MQ配置 自动 创建 队列 RPC
- 详细介绍Spring Boot + RabbitMQ实现延迟队列
- Spring Boot RabbitMQ 延迟消息实现完整版示例
- SpringBoot对消息队列(MQ)的支持
- Spring Boot教程(一)在springboot中用redis实现消息队列
- SpringBoot+rabbitMq的配置和使用Demo
- springboot+rabbitMq整合开发实战一
- 基于dubbo的分布式项目框架搭建 开发工具idea (springboot+dubbo+zookeeper+redis+rabbitmq+基于Swagger2的restful api) --(三)
- springboot+rabbitmq整合