sprig-amqp-rabbitmq使用

参考是黑马视频的乐游商城,

消息的队列

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 = {"#.#"})) 路由键

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值