Spring Data AMQP启动器
- 依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
- application.yml
spring:
rabbitmq:
host:
username:
password:
# 指定虚拟机
virtual-host:
# 开启生产者确认机制
publisher-confirms: true
- 生产信息
@Autowired
RabbitTemplate rabbitTemplate;
rabbitTemplate.convertAndSend("交换机名","routingKey","mes")
- 消费信息
@Component
public class Listener{
@RabbitListener(queues="队列名")
public void listen(String mes){}
}