RabbitMQ 发送消息到队列(交换机不参与的那种)

发布时间 2023-12-01 21:26:11作者: 嘎嘎鸭2

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);
}