spingboot使用rabbitmq
2021/5/21 10:58:21
本文主要是介绍spingboot使用rabbitmq,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1.引入依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-amqp</artifactId> </dependency>
2.yml配置
spring: rabbitmq: host: 47.115.14.7 port: 9903 username: guest password: guest
3.生产者
@Component public class ProduceSchedule { @Autowired private AmqpTemplate amqpTemplate; @Scheduled(fixedRate = 1000) public void send() { String msg = "MY_QUEUE send ..." + System.currentTimeMillis(); amqpTemplate.convertAndSend(QueueNames.MY_QUEUE, msg); } }
4.消费者
@Component @Slf4j public class Receiver { @RabbitListener(queuesToDeclare = @Queue(QueueNames.MY_QUEUE)) public void receive(String msg) { log.info("MY_QUEUE receive:{}", msg); } }
这篇关于spingboot使用rabbitmq的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-10RabbitMQ教程:初学者指南
- 2024-09-10RabbitMQ教程:初学者指南
- 2024-09-01Kafka事务实现原理
- 2024-08-09KubeSphere 部署 Kafka 集群实战指南
- 2024-07-24百行代码实现 Kafka 运行在 S3 之上
- 2024-07-18如何使用观测云监测 AutoMQ 集群状态
- 2024-07-18活动回顾 | AutoMQ 联合 GreptimeDB 共同探讨新能源汽车数据基础设施
- 2024-07-15AutoMQ vs Kafka: 来自小红书的独立深度评测与对比
- 2024-07-15AutoMQ 生态集成 Kafdrop-ui
- 2024-07-15AutoMQ 与蚂蚁数科达成战略合作