SpringBoot集成RabbitMQ
来源:互联网 发布:系统服务 软件更新 编辑:程序博客网 时间:2024/04/30 05:39
1. pom.xml添加依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-amqp</artifactId></dependency>
2. application.properties配置
spring.rabbitmq.host=localhostspring.rabbitmq.port=5672spring.rabbitmq.username=guestspring.rabbitmq.password=guest
3. RabbitConfig队列配置
@Configurationpublic class RabbitConfig { @Bean public Queue helloQueue() { return new Queue("hello"); }}
4. HelloSender发送者
@Componentpublic class HelloSender { private static Logger logger = Logger.getLogger(HelloSender.class); @Autowired private AmqpTemplate rabbitTemplate; public void send(String message) { rabbitTemplate.convertAndSend("hello", message); logger.info(String.format("send message: %s", message)); }}
5. HelloReceiver接收者
@Component@RabbitListener(queues = "hello")public class HelloReceiver { private static Logger logger = Logger.getLogger(HelloReceiver.class); @RabbitHandler public void process(String message) { logger.info(String.format("receive message: %s", message)); }}
6. HelloTest测试
@RunWith(SpringRunner.class)@SpringBootTestpublic class HelloTest { @Autowired private HelloSender helloSender; @Test public void test() { helloSender.send("hello world"); }}
7. 测试结果
send message: hello worldreceive message: hello world
阅读全文
0 0
- SpringBoot集成RabbitMQ
- Springboot集成RabbitMq
- Springboot集成RabbitMQ
- SpringBoot 快速集成RabbitMQ
- Springboot之集成RabbitMQ
- SpringBoot项目集成RabbitMq
- springboot集成RabbitMQ
- Springboot集成RabbitMq
- springboot(集成篇):RabbitMQ集成详解
- 随便谈谈RabbitMQ与springBoot进行集成。
- springboot集成rabbitMQ之对象传输
- springboot中rabbitmq集成——单项目
- springboot中rabbitmq集成——多项目
- 微服务,微架构[十三]springboot集成RabbitMQ
- 第5篇 RabbitMQ集成SpringBoot实现Direct模式
- CentOS7下RabbitMq及与SpringBoot集成注意点
- springboot中rabbitmq集成——单项目
- Springboot+RabbitMq
- maven配置生成可执行的jar:maven-shade-plugin
- 你应该知道的那些Android小经验(神文)
- Java内存管理(三)——卡片表
- nginx fastDFS 搭建安装
- 分辨率 ppi
- SpringBoot集成RabbitMQ
- 【双系统】ubuntu与windows双系统时间不一致
- 2016 CCPC-Final B
- H5桌面小通知
- angularJS的自定义服务-factory、service、value 三种方式实现的异同
- bzoj 1030 [JSOI2007]文本生成器
- nodejs取参四种方法req.body,req.params,req.param,req.body多适用于restful风格url中的参数的解析 req.query与req.params的区别 r
- docker+gitlab的私有服务环境搭建
- Nginx 四种分配方式