1. 导包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
2.在 application.yml 文件里编写配置信息
spring:
rabbitmq:
host: 192.168.88.130
port: 5672
virtual-host: /hmall
username: hmall
password: 123
2. Autowired
@Autowired
private RabbitTemplate rabbitTemplate;
3. 编写代码
@GetMapping("/mq01")
public void mq01(){
String queueName = "simple.queue";
String msg = "hello,amqp";
rabbitTemplate.convertAndSend(queueName, msg);
}