企业网站建设方案书前言seo入门教程
使用异步消息服务-AMQP(RabbitMQ)
更多干货
- spring-boot系列一 之restfull api与多环境配置
- springboot系列二之 日志
- SpringBoot系列三之 MVC 模版引擎
- SpringBoot 2.0.0.M7 系列四 异常处理
- springboot 2.0.0.M7之 注解 与 配置
- springboot 2.0.0.M7 配置mvc
- springboot 2.0.0.M7 之 Servlet Listener Filter
- springboot 2.0.0.M7 之 跨域
- springboot 2.0.0.M7 之使用mysql
- spring boot 2.0.0.M7 之 数据库-事务处理
- springboot 2.0.0.M7 之 h2 嵌入式数据库的使用
- springboot 2.0.0.M7 之 数据库-redis
- Spring Boot 2.0.0.M7 中使用Swagger2构建RESTful API文档
- Spring Boot 2.0.0.M7 springBoot-mongodb使用
- Spring Boot 2.0.0.M7 使用 Caching-EhCache
- Spring Boot spring boot 使用 Caching-Redis
- Spring Boot 2.0.0.M7 使用异步消息服务-AMQP(RabbitMQ)
- Spring Boot 2.0.0.M7 调用REST服务-如何使用代理
- Spring Boot 2.0.0.M7 发送邮件-使用模板邮件并实现多账号轮询发送
- Spring Boot 2.0.0.M7 使用Spring Session实现集群-redis
- Spring Boot 2.0.0.M7 如何进行远程调试
- Spring Boot 生产准备-基于HTTP的监控
- Spring Boot 集成 Druid
- springboot思维导图
- RabbitMQ下载地址:http://www.rabbitmq.com/download.html
- erlang 下载地址:http://www.erlang.org/downloads
添加依赖
<!-- amqp -->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
配置文件
# RABBIT (RabbitProperties)
#spring.rabbitmq.host=localhost
#spring.rabbitmq.port=5672
#spring.rabbitmq.password=
#spring.rabbitmq.username=
代码实现
- 1.启用注解: @EnableRabbit
- 2.配置
/**
* amqp队列配置
*
*/
@Configuration
publicclass AmqpConfiguration {@Beanpublic Queue queue() {returnnew Queue("ctoedu.queue");}
}
@Component
publicclass AmqpComponent {@Autowiredprivate AmqpTemplate amqpTemplate;publicvoid send(String msg) {this.amqpTemplate.convertAndSend("ctoedu.queue", msg);}@RabbitListener(queues = "ctoedu.queue")publicvoid receiveQueue(String text) {System.out.println("接受到:" + text);}
}
四、测试
@Autowiredprivate AmqpComponent amqpComponent;@Testpublicvoid send() {amqpComponent.send("hello world2");}