参考是黑马视频的乐游商城,
消息的队列
pom文件
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
配置文件
spring:
rabbitmq:
host: 192.168.56.101
username: leyou
password: leyou
virtual-host: /leyou
虚拟机和添加的user绑定,是多对一的关系;
生产者:void convertAndSend(String exchange, String routingKey, Object message) throws AmqpException;
消费者:
@RabbitListener(bindings = @QueueBinding(
value = @Queue(value = "spring.test.queue", durable = "true"), 队列持久化;
exchange = @Exchange(
value = "spring.test.exchange",
ignoreDeclarationExceptions = "true",
type = ExchangeTypes.TOPIC
), 交换机类型及其持久化
key = {"#.#"})) 路由键