2024年大数据最全RabbitMQ学习笔记_handledelivery,阿里大牛整理

img
img

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

    channel.basicQos(1);//每一次只能消费一个消息
    channel.queueDeclare("hello",true,false,false,null);
    channel.basicConsume("hello", false,new DefaultConsumer(channel) {
        @SneakyThrows
        @Override
        public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
            TimeUnit.SECONDS.sleep(1);
            System.out.println(new String(body));
            //参数1:手动确认消息标识 参数2:false 每次确认一个
            channel.basicAck(envelope.getDeliveryTag(),false);
        }
    });
}

}


**消费者2**



public class Consumer_2 {
public static void main(String[] args) throws Exception {
Connection connection = RabbitMQUtils.getConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(“hello”, true, false, false, null);
channel.basicQos(1);
channel.basicConsume(“hello”, false, new DefaultConsumer(channel) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
System.out.println(new String(body));
//参数1:手动确认消息标识 参数2:false 每次确认一个
channel.basicAck(envelope.getDeliveryTag(), false);
}
});
}
}


消费者1输出



hello world-0


消费者2输出



hello world-1
hello world-2
hello world-3
hello world-4
hello world-5
hello world-6
hello world-7
hello world-8
hello world-9


上面的结果因为消费者1,加了延时1秒,且channel.basicQos(1); 每次接收接收一条消息,直到确认返回,所以其他就被消费者2没加延迟消费完了,能者多劳


### 3.4第三种模式-Publish/Subscribe/发布订阅(交换机-fanout类型)


![在这里插入图片描述](https://img-blog.csdnimg.cn/6617072835c54c4bb1dafea687b61970.png)



> 
> 在广播模式下,消息发送流程是这样的:  
>  可以有多个消费者  
>  每个消费者有自己的queue(队列)  
>  每个队列都要绑定到Exchange(交换机)  
>  生产者发送的消息,只能发送到交换机,  
>  交换机来决定要发给哪个队列,生产者无法决定。  
>  交换机把消息发送给绑定过的所有队列  
>  队列的消费者都能拿到消息。实现一条消息被多个消费者消费
> 
> 
> 


**生产者**



public class Producer {
public static void main(String[] args) throws Exception {
Connection connection = RabbitMQUtils.getConnection();
Channel channel = connection.createChannel();

    //将通道声明指定交换机
    //参数1: 交换机名称 参数2: 交换机类型 fanout 广播类型
    channel.exchangeDeclare("logs", BuiltinExchangeType.FANOUT);

    //发消息
    channel.basicPublish("logs","",null,"fanout type message".getBytes());

    RabbitMQUtils.closeConnectionAndChanel(channel,connection);
}

}


**消费者1**



public class Consumer_1 {
public static void main(String[] args) throws Exception {
Connection connection = RabbitMQUtils.getConnection();
Channel channel = connection.createChannel();
//通道绑定交换机
channel.exchangeDeclare(“logs”, “fanout”);
//获取临时队列名
String queueName = channel.queueDeclare().getQueue();
System.out.println(“queueName:” + queueName);
//绑定交换机和队列
channel.queueBind(queueName, “logs”, “”);
//自动确认关掉
channel.basicConsume(queueName, true, new DefaultConsumer(channel) {
@SneakyThrows
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
System.out.println(“消费者1” + new String(body));
}
});
}
}


**消费者2**



public class Consumer_2 {
public static void main(String[] args) throws Exception {
Connection connection = RabbitMQUtils.getConnection();
Channel channel = connection.createChannel();
//通道绑定交换机
channel.exchangeDeclare(“logs”, “fanout”);
//获取临时队列名
String queueName = channel.queueDeclare().getQueue();
System.out.println(“queueName:” + queueName);
//绑定交换机和队列
channel.queueBind(queueName, “logs”, “”);
//自动确认关掉
channel.basicConsume(queueName, true, new DefaultConsumer(channel) {
@SneakyThrows
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
System.out.println(“消费者2” + new String(body));
}
});
}
}


![在这里插入图片描述](https://img-blog.csdnimg.cn/0b7be531fdab449f815960d16437e9cd.png)


生产者启动,发布消息  
 两个消费者收到消息



消费者1fanout type message



消费者2fanout type message


### 3.5第四种模式-Routing/路由(交换机-Direct类型)


![在这里插入图片描述](https://img-blog.csdnimg.cn/233b6c6070fc478ebdff09b47ba7ac6d.png)  
 P:生产者,向Exchange发送消息,发送消息时,  
 会指定一个routing key。  
 X:Exchange(交换机),接收生产者的消息,  
 然后把消息递交给 与routing key完全匹配的队列  
 C1:消费者,其所在队列指定了需要routing key 为 error 的消息  
 C2:消费者,其所在队列指定了需要routing key 为 info、  
 error、warning 的消息



> 
> 在Fanout模式中,一条消息,会被所有订阅的队列都消费。  
>  但是,在某些场景下,我们希望不同的消息被不同的队列消费。  
>  这时就要用到Direct类型的Exchange。
> 
> 
> 



> 
> 在Direct模型下:队列与交换机的绑定,不能是任意绑定了,  
>  而是要指定一个RoutingKey(路由key)  
>  消息的发送方在 向 Exchange发送消息时,  
>  也必须指定消息的 RoutingKey。  
>  Exchange不再把消息交给每一个绑定的队列,  
>  而是根据消息的Routing Key进行判断,  
>  只有队列的Routingkey与消息的 Routing key完全一致,  
>  才会接收到消息
> 
> 
> 


**生产者**



public class Producer {
public static void main(String[] args) throws Exception {
Connection connection = RabbitMQUtils.getConnection();
Channel channel = connection.createChannel();

    String exchangeName = "logs\_direct";
    //将通道声明指定交换机
    //参数1: 交换机名称 参数2: 交换机类型 fanout 广播类型
    channel.exchangeDeclare(exchangeName, BuiltinExchangeType.DIRECT);

    String routingKey = "info";

// String routingKey = “error”;
//发消息
channel.basicPublish(exchangeName, routingKey, null, (“这是direct模型发布的基于route key: [” + routingKey + “] 发送的消息”).getBytes());

    RabbitMQUtils.closeConnectionAndChanel(channel, connection);
}

}


**消费者1**



public class Consumer_1 {
public static void main(String[] args) throws Exception {
Connection connection = RabbitMQUtils.getConnection();
Channel channel = connection.createChannel();
String exchangeName = “logs_direct”;
//通道绑定交换机
channel.exchangeDeclare(exchangeName, BuiltinExchangeType.DIRECT);
//获取临时队列名
String queueName = channel.queueDeclare().getQueue();

    String routingKey = "error";

    //绑定交换机和队列
    channel.queueBind(queueName, exchangeName, routingKey);
    //自动确认关掉
    channel.basicConsume(queueName, true, new DefaultConsumer(channel) {
        @SneakyThrows
        @Override
        public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
            System.out.println("消费者1" + new String(body));
        }
    });
}

}


**消费者2**



public class Consumer_2 {
public static void main(String[] args) throws Exception {
Connection connection = RabbitMQUtils.getConnection();
Channel channel = connection.createChannel();
String exchangeName = “logs_direct”;
//通道绑定交换机
channel.exchangeDeclare(exchangeName, BuiltinExchangeType.DIRECT);
//获取临时队列名
String queueName = channel.queueDeclare().getQueue();

    //绑定交换机和队列
    //临时队列和交换机绑定
    channel.queueBind(queueName, exchangeName, "info");
    channel.queueBind(queueName, exchangeName, "error");
    channel.queueBind(queueName, exchangeName, "warning");
    //自动确认关掉
    channel.basicConsume(queueName, true, new DefaultConsumer(channel) {
        @SneakyThrows
        @Override
        public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
            System.out.println("消费者2" + new String(body));
        }
    });
}

}


消费者1接收routingKey为error的消息,消费者2接收info,error,warning三种routingKey


首先启动生产者,routingKey为info,此时消费者2能收到消息



消费者2这是direct模型发布的基于route key: [info] 发送的消息


生产者,routingKey为error,消费者1和2都能收到消息



消费者1这是direct模型发布的基于route key: [error] 发送的消息



消费者2这是direct模型发布的基于route key: [error] 发送的消息


### 3.6第五种模式-Topic/主题(交换机-topic类型)


![在这里插入图片描述](https://img-blog.csdnimg.cn/92c65ef4521f4acea733d2e69f20f0cd.png)



> 
> Topic类型的Exchange与Direct相比,都是可以根据RoutingKey  
>  把消息路由到不同的队列。只不过Topic类型Exchange可以让  
>  队列在绑定Routing key的时候使用通配符!这种模型Routingkey  
>  一般都是由一个或多个单词组成,多个单词之间以”.”分割,  
>  例如: item.insert
> 
> 
> 



> 
> 在Direct模型下:队列与交换机的绑定,不能是任意绑定了,  
>  而是要指定一个RoutingKey(路由key)  
>  消息的发送方在 向 Exchange发送消息时,  
>  也必须指定消息的 RoutingKey。  
>  Exchange不再把消息交给每一个绑定的队列,  
>  而是根据消息的Routing Key进行判断,  
>  只有队列的Routingkey与消息的 Routing key完全一致,  
>  才会接收到消息
> 
> 
> 


P:生产者,向Exchange发送消息,发送消息时,  
 会指定一个routing key。  
 X:Exchange(交换机),接收生产者的消息,  
 然后把消息递交给 与routing key完全匹配的队列  
 C1:消费者,其所在队列指定了需要routing key 为 error 的消息  
 C2:消费者,其所在队列指定了需要routing key 为 info、  
 error、warning 的消息


**生产者**



public class Producer {
public static void main(String[] args) throws Exception {
Connection connection = RabbitMQUtils.getConnection();
Channel channel = connection.createChannel();

    String exchangeName = "topics";
    //将通道声明指定交换机
    //参数1: 交换机名称 参数2: 交换机类型 TOPIC 主题类型
    channel.exchangeDeclare(exchangeName, BuiltinExchangeType.TOPIC);

    String routingKey = "user.save";
    //发消息
    channel.basicPublish(exchangeName, routingKey, null, ("这是topic模型发布的基于route key: [" + routingKey + "] 发送的消息").getBytes());
    channel.basicPublish(exchangeName, "a.pp", null, ("这是topic模型发布的基于route key: [" + "a.pp" + "] 发送的消息").getBytes());

    RabbitMQUtils.closeConnectionAndChanel(channel, connection);
}

}


**消费者1**



public class Consumer_1 {
public static void main(String[] args) throws Exception {
Connection connection = RabbitMQUtils.getConnection();
Channel channel = connection.createChannel();
String exchangeName = “topics”;
//通道绑定交换机
channel.exchangeDeclare(exchangeName, BuiltinExchangeType.TOPIC);
//获取临时队列名
String queueName = channel.queueDeclare().getQueue();

    String routingKey = "user.\*";

    //绑定交换机和队列
    channel.queueBind(queueName, exchangeName, routingKey);
    //自动确认关掉
    channel.basicConsume(queueName, true, new DefaultConsumer(channel) {
        @SneakyThrows
        @Override
        public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
            System.out.println("消费者1" + new String(body));
        }
    });
}

}


**消费者2**



public class Consumer_2 {
public static void main(String[] args) throws Exception {
Connection connection = RabbitMQUtils.getConnection();
Channel channel = connection.createChannel();
String exchangeName = “topics”;
//通道绑定交换机
channel.exchangeDeclare(exchangeName, BuiltinExchangeType.TOPIC);
//获取临时队列名
String queueName = channel.queueDeclare().getQueue();

    String routingKey = "a.\*";

    //绑定交换机和队列
    channel.queueBind(queueName, exchangeName, routingKey);
    //自动确认关掉
    channel.basicConsume(queueName, true, new DefaultConsumer(channel) {
        @SneakyThrows
        @Override
        public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
            System.out.println("消费者2" + new String(body));
        }
    });
}

}


生产者发布了routingKey为user.save和a.pp的消息  
 消费者1使用routingKey 通配符 user.\*接收,所以收到了以下消息



消费者1这是topic模型发布的基于route key: [user.save] 发送的消息


消费者2使用routingKey 通配符 a.\*接收,所以收到了以下消息



消费者2这是topic模型发布的基于route key: [a.pp] 发送的消息


## 4.SpringBoot中使用RabbitMQ


### 4.1 环境搭建


**pom**



<?xml version="1.0" encoding="UTF-8"?>


4.0.0
com.example
springboot-rabbitmq
0.0.1-SNAPSHOT
springboot-rabbitmq
springboot-rabbitmq

<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-boot.version>2.4.2</spring-boot.version>



org.springframework.boot
spring-boot-starter-web


org.springframework.boot
spring-boot-starter-test
test


org.springframework.boot
spring-boot-starter-amqp





org.springframework.boot
spring-boot-dependencies
${spring-boot.version}
pom
import



**yml**



spring:
application:
name: springboot_rabbitmq
rabbitmq:
host: 127.0.0.1
port: 5673
username: root
password: 123
virtual-host: /


### 4.1第一种-Hello World!/基础队列(生产者-队列-消费者)


**生产者**



@SpringBootTest
public class Producer {

@Autowired
private RabbitTemplate rabbitTemplate;

/\*\*

* 生产端没有指定交换机只有routingKey和Object。
* 消费方产生hello队列,放在默认的交换机(AMQP default)上。
* 而默认的交换机有一个特点,只要你的routerKey的名字与这个
* 交换机的队列有相同的名字,他就会自动路由上。
* 生产端routingKey 叫hello ,消费端生产hello队列。
* 他们就路由上了
*/
@Test
void producer() {
rabbitTemplate.convertAndSend(“hello”, “hello world”);
}

}


**消费者**  
 [Spring Boot中@RabbitHandler注解的介绍、原理和使用]( )



/**
* 生产端没有指定交换机只有routingKey和Object。
* 消费方产生hello队列,放在默认的交换机(AMQP default)上。
* 而默认的交换机有一个特点,只要你的routerKey的名字与这个
* 交换机的队列有相同的名字,他就会自动路由上。
* 生产端routingKey 叫hello ,消费端生产hello队列。
* 他们就路由上了
*/
@Component
@RabbitListener(queuesToDeclare = @Queue(value = “hello”))
public class ConsumerHelloWord {

@RabbitHandler
public void receive(String message) {
    System.out.println("message = " + message);
}

}


先运行消费者,在运行生产者


### 4.2第二种-Work Queues/工作队列/任务队列


**生产者**



/**
* 生产端没有指定交换机只有routingKey和Object。
* 消费方产生work队列,放在默认的交换机(AMQP default)上。
* 而默认的交换机有一个特点,只要你的routerKey的名字与这个
* 交换机的队列有相同的名字,他就会自动路由上。
* 生产端routingKey 叫work ,消费端生产work队列。
* 他们就路由上了
*/
@Component
public class ConsumerWorkQueues {

@RabbitListener(queuesToDeclare = @Queue("work"))
public void receive1(String message) {
    System.out.println("work message1 = " + message);
}


@RabbitListener(queuesToDeclare = @Queue("work"))
public void receive2(String message) {
    System.out.println("work message2 = " + message);
}

}


**消费者**



/**
* 生产端没有指定交换机只有routingKey和Object。
* 消费方产生work队列,放在默认的交换机(AMQP default)上。
* 而默认的交换机有一个特点,只要你的routerKey的名字与这个
* 交换机的队列有相同的名字,他就会自动路由上。
* 生产端routingKey 叫work ,消费端生产work队列。
* 他们就路由上了
*/
@Component
public class ConsumerWorkQueues {

@RabbitListener(queuesToDeclare = @Queue("work"))
public void receive1(String message) {
    System.out.println("work message1 = " + message);
}


@RabbitListener(queuesToDeclare = @Queue("work"))
public void receive2(String message) {
    System.out.println("work message2 = " + message);
}

}


### 4.3第三种模式-Publish/Subscribe/发布订阅(交换机-fanout类型)


**生产者**



@SpringBootTest
public class Producer {

@Autowired
private RabbitTemplate rabbitTemplate;

@Test
void producer() {
    for (int i = 0; i < 10; i++) {
        //参数1为交换机
        //参数2为路由key,“”表示为任意路由
        //参数3为消息内容
        rabbitTemplate.convertAndSend("logs","","这是日志广播");
    }
}

}


**消费者**



@Component
public class ConsumerWorkQueuesFanout {

//使用@RabbitListener注解中的bindings声明并绑定交换机和队列
@RabbitListener(bindings = @QueueBinding(value = @Queue, // 创建临时队列
        exchange = @Exchange(name = "logs", type = ExchangeTypes.FANOUT)
))
public void receive1(String message) {
    System.out.println("message1 = " + message);
}

@RabbitListener(bindings = @QueueBinding(value = @Queue, // 创建临时队列
        exchange = @Exchange(name = "logs", type = ExchangeTypes.FANOUT)
))
public void receive2(String message) {
    System.out.println("message2 = " + message);
}

}


### 4.4第四种模式-Routing/路由(交换机-Direct类型)


**生产者**



@SpringBootTest
public class Producer {

@Autowired
private RabbitTemplate rabbitTemplate;

@Test
void producer() {
    for (int i = 0; i < 10; i++) {
        //参数1为交换机
        //参数2为路由key,“”表示为任意路由
        //参数3为消息内容
        rabbitTemplate.convertAndSend("directs","error","error 的日志信息");
    }
}

}


**消费者**



@Component
public class ConsumerRouting {

//使用@RabbitListener注解中的bindings声明并绑定交换机和队列
@RabbitListener(bindings = @QueueBinding(value = @Queue("directsQueue"),//指定队列名
        key = {"info", "error"},
        exchange = @Exchange(name = "directs", type = ExchangeTypes.DIRECT)
))
public void receive1(String message) {
    System.out.println("message1 = " + message);
}

@RabbitListener(bindings = @QueueBinding(value = @Queue("directsQueue"),
        key = {"error"},
        exchange = @Exchange(name = "directs", type = ExchangeTypes.DIRECT)
))
public void receive2(String message) {
    System.out.println("message2 = " + message);
}

}


### 4.5第五种模式-Topic/主题(交换机-topic类型)


**生产者**



@SpringBootTest
public class Producer {

@Autowired
private RabbitTemplate rabbitTemplate;

@Test
void producer() {
    for (int i = 0; i < 10; i++) {
        //参数1为交换机
        //参数2为路由key,“”表示为任意路由
        //参数3为消息内容
        rabbitTemplate.convertAndSend("topics","user.save.findAll","user.save.findAll 的消息");
    }
}

}


**消费者**



@Component
public class ConsumerTopics {

@RabbitListener(bindings = {
        @QueueBinding(
                value = @Queue,
                key = {"user.\*"},
                exchange = @Exchange(type = ExchangeTypes.TOPIC, name = "topics")
        )
})
public void receive1(String message) {
    System.out.println("message1 = " + message);
}

@RabbitListener(bindings = {
        @QueueBinding(
                value = @Queue,
                key = {"user.#"},
                exchange = @Exchange(type = ExchangeTypes.TOPIC, name = "topics")
        )
})
public void receive2(String message) {
    System.out.println("message2 = " + message);
}

}


## 5.死信队列,延迟队列


### 5.1 死信概念



> 
> 先从概念解释上搞清楚这个定义,死信,顾名思义就是无法被消费的消息,字面意思可以这样理解,一般来说,producer 将消息投递到  
>  broker 或者直接到queue 里了,consumer 从 queue 取出消息进行消费,但某些时候由于特定的原因导致 queue  
>  中的某些消息无法被消费,这样的消息如果没有 后续的处理,就变成了死信,有死信自然就有了死信队列。
> 
> 
> 



> 
> 应用场景:为了保证订单业务的消息数据不丢失,需要使用到  
>  RabbitMQ的死信队列机制,当消息消费发生异常时,将消息投入死信队列中.还有比如说:用户在商城下单成功并点击去支付后在指定时间未支付时自动失效
> 
> 
> 


### 5.2死信的来源


1. 消息 TTL 过期
2. 队列达到最大长度(队列满了,无法再添加数据到 mq 中)
3. 消息被拒绝(basic.reject 或 basic.nack)并且 requeue=false.


### 5.3入门实战


#### 5.3.1 架构图


![在这里插入图片描述](https://img-blog.csdnimg.cn/a55915c4bc21465981fd5ee490154c8f.png)


#### 5.3.2 代码


**生产者**



public class Producer {
private static final String NORMAL_EXCHANGE = “normal_exchange”;

public static void main(String[] argv) throws Exception {
    try (Channel channel = RabbitMQUtils.getConnection().createChannel()) {
        channel.exchangeDeclare(NORMAL\_EXCHANGE,
                BuiltinExchangeType.DIRECT);
        //设置消息的 TTL 时间
        AMQP.BasicProperties properties = new AMQP.BasicProperties().builder().expiration("10000").build();
        //该信息是用作演示队列个数限制
        for (int i = 1; i < 11; i++) {
            String message = "info" + i;
            channel.basicPublish(NORMAL\_EXCHANGE, "zhangsan", properties, message.getBytes());
            System.out.println("生产者发送消息:" + message);
        }
    }
}

}


**消费者1**



public class Consumer01 {
//普通交换机名称
private static final String NORMAL_EXCHANGE = “normal_exchange”;
//死信交换机名称
private static final String DEAD_EXCHANGE = “dead_exchange”;

public static void main(String[] argv) throws Exception {
    Channel channel = RabbitMQUtils.getConnection().createChannel();
    //声明死信和普通交换机 类型为 direct
    channel.exchangeDeclare(NORMAL\_EXCHANGE, BuiltinExchangeType.DIRECT);
    channel.exchangeDeclare(DEAD\_EXCHANGE, BuiltinExchangeType.DIRECT);

    //声明死信队列
    String deadQueue = "dead-queue";
    channel.queueDeclare(deadQueue, false, false, false, null);
    //死信队列绑定死信交换机与 routingKey
    channel.queueBind(deadQueue, DEAD\_EXCHANGE, "lisi");

    Map<String, Object> params = new HashMap<>();
    //正常队列设置死信交换机 参数 key 是固定值
    params.put("x-dead-letter-exchange", DEAD\_EXCHANGE);
    //正常队列设置死信 routing-key 参数 key 是固定值
    params.put("x-dead-letter-routing-key", "lisi");
    String normalQueue = "normal-queue";
    //正常队列绑定死信队列信息
    channel.queueDeclare(normalQueue, false, false, false, params);
    channel.queueBind(normalQueue, NORMAL\_EXCHANGE, "zhangsan");

    System.out.println("等待接收消息........... ");

    DeliverCallback deliverCallback = (consumerTag, delivery) ->
    {
        String message = new String(delivery.getBody(), StandardCharsets.UTF\_8);
        System.out.println("Consumer01 接收到消息" + message);
    };
    channel.basicConsume(normalQueue, true, deliverCallback, consumerTag -> {
    });
}

}


**消费者2**



public class Consumer02 {
//死信交换机名称
private static final String DEAD_EXCHANGE = “dead_exchange”;

public static void main(String[] argv) throws Exception {
    Channel channel = RabbitMQUtils.getConnection().createChannel();
    channel.exchangeDeclare(DEAD\_EXCHANGE, BuiltinExchangeType.DIRECT);

    //声明死信队列
    String deadQueue = "dead-queue";
    channel.queueDeclare(deadQueue, false, false, false, null);
    //死信队列绑定死信交换机与 routingKey
    channel.queueBind(deadQueue, DEAD\_EXCHANGE, "lisi");

    System.out.println("等待接收消息........... ");

    DeliverCallback deliverCallback = (consumerTag, delivery) ->
    {
        String message = new String(delivery.getBody(), StandardCharsets.UTF\_8);
        System.out.println("Consumer01 接收到消息" + message);
    };
    channel.basicConsume(deadQueue, true, deliverCallback, consumerTag -> {
    });
}

}


**流程**  
 启动消费者1,生产交换机和队列  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/8eeb0c7df3864e4384aa13b5d5f13264.png)


![在这里插入图片描述](https://img-blog.csdnimg.cn/e52c94c525c94a8fb8a7fc2e2874c9ce.png)  
 启动消费者,发现10条消息没被消费  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/63e388fac55445bea6bd3caf4b5a6712.png)  
 等待10S后,发现没被消费就转移到死信队列  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/ba66efbe3d9f4b14ae861028e67800a0.png)  
 启动消费者2,消费者2去消费死信队列的消息  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/bccd142cd0394a78b95392613330d5a3.png)


### 5.4 SpringBoot实现延迟队列


#### 5.4.1 延迟队列概念


延时队列,队列内部是有序的,最重要的特性就体现在它的延时属性上,延时队列中的元素是希望在指定时间到了以后或之前取出和处理,简单来说,延时队列就是用来存放需要在指定时间被处理的元素的队列。


#### 5.4.2 延迟队列使用场景


1.订单在十分钟之内未支付则自动取消  
 2.新创建的店铺,如果在十天内都没有上传过商品,则自动发送消息提醒。  
 3.用户注册成功后,如果三天内没有登陆则进行短信提醒。  
 4.用户发起退款,如果三天内没有得到处理则通知相关运营人员。  
 5.预定会议后,需要在预定的时间点前十分钟通知各个与会人员参加会议


这些场景都有一个特点,需要在某个事件发生之后或者之前的指定时间点完成某一项任务


#### 5.4.3 RabbitMQ 中的 TTL


TTL 是什么呢?TTL 是 RabbitMQ 中一个消息或者队列的属性,表明一条消息或者该队列中的所有消息的最大存活时间,单位是毫秒。


换句话说,如果一条消息设置了 TTL 属性或者进入了设置TTL 属性的队列,那么这条消息如果在TTL 设置的时间内没有被消费,则会成为"死信"。如果同时配置了队列的TTL 和消息的TTL,那么较小的那个值将会被使用,有两种方式设置 TTL。


如果设置了队列的 TTL 属性,那么一旦消息过期,就会被队列丢弃(如果配置了死信队列被丢到死信队 列中),而第二种方式,消息即使过期,也不一定会被马上丢弃,因为消息是否过期是在即将投递到消费者 之前判定的,如果当前队列有严重的消息积压情况,则已过期的消息也许还能存活较长时间;另外,还需 要注意的一点是,如果不设置 TTL,表示消息永远不会过期,如果将 TTL 设置为 0,则表示除非此时可以 直接投递该消息到消费者,否则该消息将会被丢弃。


前一小节我们介绍了死信队列,刚刚又介绍了 TTL,至此利用 RabbitMQ 实现延时队列的两大要素已 经集齐,接下来只需要将它们进行融合,再加入一点点调味料,延时队列就可以新鲜出炉了。想想看,延 时队列,不就是想要消息延迟多久被处理吗,TTL 则刚好能让消息在延迟多久之后成为死信,另一方面, 成为死信的消息都会被投递到死信队列里,这样只需要消费者一直消费死信队列里的消息就完事了,因为 里面的消息都是希望被立即处理的消息。


#### 5.4.3 架构图


创建两个队列 QA 和 QB,两者队列 TTL 分别设置为 10S 和 20S,然后在创建一个交换机 X 和死信交换机 Y,它们的类型都是direct,创建一个死信队列 QD,它们的绑定关系如下:  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/6c71281260e94859ad00e69b7d35f063.png)


#### 5.4.4 实现代码


用上面的springboot项目继续搞这个延迟队列  
 **配置类** 用于生命交换机、队列以及之间的绑定关系



@Configuration
public class DeadQueueConfig {
public static final String EXCHANGE_X = “X”;
public static final String ROUTING_KEY_XA = “XA”;
public static final String ROUTING_KEY_XB = “XB”;
public static final String QUEUE_A = “QA”;
public static final String QUEUE_B = “QB”;
public static final String EXCHANGE_Y = “Y”;
public static final String QUEUE_D = “QD”;
public static final String ROUTING_KEY_YD = “YD”;
public static final int X_MESSAGE_TTL_QA = 10;
public static final int X_MESSAGE_TTL_QB = 20;

// 声明 交换机X
@Bean
public DirectExchange exchangeX() {
    return new DirectExchange(EXCHANGE\_X);
}

//声明队列 A ttl 为 10s 并绑定到对应的死信交换机
@Bean
public Queue queueA() {
    return QueueBuilder.durable(QUEUE\_A)
            //声明当前队列绑定的死信交换机
            .deadLetterExchange(EXCHANGE\_Y)
            //声明当前队列的死信路由 key
            .deadLetterRoutingKey(ROUTING\_KEY\_YD)
            //声明队列的 TTL
            .ttl(X\_MESSAGE\_TTL\_QA \* 1000)
            .build();
}

// 声明队列 A 绑定 X 交换机
@Bean
public Binding queueABindExchangeX(Queue queueA, DirectExchange exchangeX) {
    return BindingBuilder.bind(queueA).to(exchangeX).with(ROUTING\_KEY\_XA);
}

//声明队列 B ttl 为 20s 并绑定到对应的死信交换机
@Bean
public Queue queueB() {
    return QueueBuilder.durable(QUEUE\_B)
            .deadLetterExchange(EXCHANGE\_Y)
            .deadLetterRoutingKey(ROUTING\_KEY\_YD)
            .ttl(X\_MESSAGE\_TTL\_QB \* 1000)
            .build();
}

//声明队列 B 绑定 X 交换机
@Bean
public Binding queueBBindExchangeX(Queue queueB, DirectExchange exchangeX) {
    return BindingBuilder.bind(queueB).to(exchangeX).with(ROUTING\_KEY\_XB);
}

// 声明 交换机Y
@Bean
public DirectExchange exchangeY() {
    return new DirectExchange(EXCHANGE\_Y);
}

//声明死信队列 QD
@Bean
public Queue queueD() {
    return new Queue(QUEUE\_D);
}

//声明死信队列 QD 绑定关系
@Bean
public Binding queueDBindExchangeX(Queue queueD, DirectExchange exchangeY) {
    return BindingBuilder.bind(queueD).to(exchangeY).with(ROUTING\_KEY\_YD);
}

}


**消费者**



@Slf4j
@Component
public class DeadLetterQueueConsumer {

@RabbitListener(queues = DeadQueueConfig.QUEUE\_D)
public void receiveD(Message message, Channel channel){
    String msg = StrUtil.str(message.getBody(), StandardCharsets.UTF\_8);
    log.info("当前时间:{},收到死信队列信息{}", DateUtil.now(), msg);
}

}


**生产者**



@Slf4j
@RequestMapping(“ttl”)
@RestController
public class SendMsgController {
@Autowired
private RabbitTemplate rabbitTemplate;

@GetMapping("sendMsg/{message}")
public void sendMsg(@PathVariable String message) {
    log.info("当前时间:{},发送一条信息给两个 TTL 队列:{}", DateUtil.now(), message);
    //第三个参数:要发送的消息
    rabbitTemplate.convertAndSend(DeadQueueConfig.EXCHANGE\_X, DeadQueueConfig.ROUTING\_KEY\_XA, "消息来自 ttl 为 " + DeadQueueConfig.X\_MESSAGE\_TTL\_QA + "S 的队列: " + message);
    rabbitTemplate.convertAndSend(DeadQueueConfig.EXCHANGE\_X, DeadQueueConfig.ROUTING\_KEY\_XB, "消息来自 ttl 为 " + DeadQueueConfig.X\_MESSAGE\_TTL\_QB + "S 的队列: " + message);
}

}


发送请求 [http://127.0.0.1:8080/ttl/sendMsg/姬霓太美]( )  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/2183d49046c044a2a79d6ee9224aa932.png)  
 第一条消息在 10S 后变成了死信消息,然后被消费者消费掉,第二条消息在 40S 之后变成了死信消息, 然后被消费掉,这样一个延时队列就打造完成了。


不过,如果这样使用的话,岂不是每增加一个新的时间需求,就要新增一个队列,这里只有 10S 和 40S 两个时间选项,如果需要一个小时后处理,那么就需要增加TTL 为一个小时的队列,如果是预定会议室然 后提前通知这样的场景,岂不是要增加无数个队列才能满足需求?  
 0


#### 5.4.5 优化,由生产者定义消息存活时间


##### 5.4.5.1 代码架构图


在这里新增了一个队列 QC,绑定关系如下,该队列不设置TTL 时间,有生产者设定消息ttl  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/362436716b7a46dabdc5989d526eb851.png)


##### 5.4.5.2 代码


**配置类新增**



//声明队列C,ttl为生产者设置,并绑定到对应的死信交换机
@Bean
public Queue queueC() {
    return QueueBuilder.durable(QUEUE\_C)
            //声明当前队列绑定的死信交换机
            .deadLetterExchange(EXCHANGE\_Y)
            //声明当前队列的死信路由 key
            .deadLetterRoutingKey(ROUTING\_KEY\_YD)
            .build();
}

//声明队列 QC 绑定关系
@Bean
public Binding queueCBindExchangeX(Queue queueC, DirectExchange exchangeX) {
    return BindingBuilder.bind(queueC).to(exchangeX).with(ROUTING\_KEY\_XC);
}

**消费者新增**



@GetMapping("sendExpirationMsg/{message}/{ttlTimeMillisecond}")
public void sendMsg(@PathVariable String message, @PathVariable String ttlTimeMillisecond) {
    rabbitTemplate.convertAndSend(DeadQueueConfig.EXCHANGE\_X, DeadQueueConfig.ROUTING\_KEY\_XC, message, correlationData -> {
        correlationData.getMessageProperties().setExpiration(ttlTimeMillisecond);
        return correlationData;
    });
    log.info("当前时间:{},发送一条时长{}秒 TTL 信息给队列 C:{}", DateUtil.now(), TimeUnit.MILLISECONDS.toSeconds(Long.parseLong(ttlTimeMillisecond)), message);
}

启动应用,按顺序请求以下接口  
 [http://127.0.0.1:8080/ttl/sendExpirationMsg/姬霓太美/2000]( )  
 [http://127.0.0.1:8080/ttl/sendExpirationMsg/姬霓太美/20000]( )  
 可以发现,正常消费,2秒后的消费了,20秒后的也消费了  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/a62c6407b6174ce5991956f91fd6c795.png)  
 此时看着正常,但是我们反顺序过来请求,先请求20秒的,在请求2秒的


[http://127.0.0.1:8080/ttl/sendExpirationMsg/姬霓太美/20000]( )  
 [http://127.0.0.1:8080/ttl/sendExpirationMsg/姬霓太美/2000]( )  
 结果如下,发现2秒的并没有先消费,而是消费完20秒的,再消费2秒的,因为mq底层就是FIFO,所以只能这样  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/0dedbed2c15e439aab8c75189d196acc.png)  
 **结论**  
 使用这种由生产者定义消息ttl的方式,如果第一个消息的延时时长很长,而第二个消息的延时时长很短,第二个消息并不会优先得到执行。


#### 5.4.6 Rabbitmq 插件实现延迟队列


上文中提到的问题,确实是一个问题,如果不能实现在消息粒度上的 TTL,并使其在设置的TTL 时间及时死亡,就无法设计成一个通用的延时队列。那如何解决呢,接下来我们就去解决该问题。


##### 5.4.6.1 安装延时队列插件


在官网上下载 <https://www.rabbitmq.com/community-plugins.html>,下载  
 [rabbitmq\_delayed\_message\_exchange]( ) 插件,注意对应当前mq版本,然后到 RabbitMQ 的插件目录。  
 可以使用搜索命令,查找插件目录



find / -name plugins

/usr/lib/rabbitmq/lib/rabbitmq_server-3.7.18/plugins


执行下面命令让该插件生效



rabbitmq-plugins enable rabbitmq_delayed_message_exchange


![在这里插入图片描述](https://img-blog.csdnimg.cn/45601e0dbd7f4b86b9fab4b4a571a219.png)


##### 5.4.6.2 代码架构图


在这里新增了一个队列delayed.queue,一个自定义交换机delayed.exchange,绑定关系如下:  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/8b6432df550542bc83878b7c2fed2aa1.png)


##### 5.4.6.3 代码


在我们自定义的交换机中,这是一种新的交换类型,该类型消息支持延迟投递机制 消息传递后并不会立即投递到目标队列中,而是存储在 mnesia(一个分布式数据系统)表中,当达到投递时间时,才投递到目标队列中。


**配置类**



@Configuration
public class DelayedQueueConfig {
public static final String DELAYED_QUEUE_NAME = “delayed.queue”;
public static final String DELAYED_EXCHANGE_NAME = “delayed.exchange”;
public static final String DELAYED_ROUTING_KEY = “delayed.routingkey”;

@Bean
public Queue delayedQueue() {
    return new Queue(DELAYED\_QUEUE\_NAME);
}

//自定义交换机 我们在这里定义的是一个延迟交换机
@Bean
public CustomExchange delayedExchange() {
    Map<String, Object> args = new HashMap<>();
    //自定义交换机的类型
    args.put("x-delayed-type", ExchangeTypes.DIRECT);
    return new CustomExchange(DELAYED\_EXCHANGE\_NAME, "x-delayed-message", true, false,
            args);
}

@Bean
public Binding bindingDelayedQueue(Queue delayedQueue, CustomExchange delayedExchange) {
    return BindingBuilder.bind(delayedQueue).to(delayedExchange).with(DELAYED\_ROUTING\_KEY).noargs();
}

}


**生产者**



@Slf4j
@RequestMapping(“ttl”)
@RestController
public class DelayedQueueProducerController {

@Autowired
private RabbitTemplate rabbitTemplate;
public static final String DELAYED\_EXCHANGE\_NAME = "delayed.exchange";
public static final String DELAYED\_ROUTING\_KEY = "delayed.routingkey";

@GetMapping("sendDelayMsg/{message}/{delayTime}")
public void sendMsg(@PathVariable String message, @PathVariable Integer delayTime) {
    rabbitTemplate.convertAndSend(DELAYED\_EXCHANGE\_NAME, DELAYED\_ROUTING\_KEY, message,
            correlationData -> {
                correlationData.getMessageProperties().setDelay(delayTime);
                return correlationData;
            });
    log.info(" 当 前 时 间 : {}, 发 送 一 条 延 迟 {} 秒的信息给队列 delayed.queue:{}", DateUtil.now(), TimeUnit.MILLISECONDS.toSeconds(delayTime), message);
}

}


**消费者**



@Slf4j
@Component
public class DelayedQueueConsumer {
public static final String DELAYED_QUEUE_NAME = “delayed.queue”;

@RabbitListener(queues = DELAYED\_QUEUE\_NAME)
public void receiveDelayedQueue(Message message) {
    String msg = StrUtil.str(message.getBody(), StandardCharsets.UTF\_8);
    log.info("当前时间:{},收到延时队列的消息:{}", DateUtil.now(), msg);
}

}


启动应用,分别访问  
 [http://localhost:8080/ttl/sendDelayMsg/come on baby1/20000]( )  
 [http://localhost:8080/ttl/sendDelayMsg/come on baby1/2000]( )  
 结果如下,20秒的先访问,2秒后访问,但是还是2秒快的先消费了  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/0d938b1f53a143a4b85120f08e9e7d49.png)


#### 5.4.7 总结


     延时队列在需要延时处理的场景下非常有用,使用 RabbitMQ 来实现延时队列可以很好的利用 RabbitMQ 的特性,如:消息可靠发送、消息可靠投递、死信队列来保障消息至少被消费一次以及未被正 确处理的消息不会被丢弃。另外,通过 RabbitMQ 集群的特性,可以很好的解决单点故障问题,不会因为 单个节点挂掉导致延时队列不可用或者消息丢失。  
      当然,延时队列还有很多其它选择,比如利用 Java 的 DelayQueue,利用 Redis 的 zset,利用 Quartz 或者利用 kafka 的时间轮,这些方式各有特点,看需要适用的场景


## 6 发布确认高级


![在这里插入图片描述](https://img-blog.csdnimg.cn/e3859e6140924e5588adc1bc137ace3a.png)



> 
> [springboot + rabbitmq 消息确认机制(避坑指南)]( )  
>  发送消息确认:用来确认生产者 producer 将消息发送到 broker ,broker 上的交换机 exchange 再投递给队列  
>  queue的过程中,消息是否成功投递。
> 
> 
> 消息从 producer 到 rabbitmq broker有一个 confirmCallback 确认模式。
> 
> 
> 消息从 exchange 到 queue 投递失败有一个 returnCallback 退回模式。
> 
> 
> 我们可以利用这两个Callback来确保消的100%送达。
> 
> 
> 


在生产环境中由于一些不明原因,导致 rabbitmq 重启,在 RabbitMQ 重启期间生产者消息投递失败,  
 导致消息丢失,需要手动处理和恢复。于是,我们开始思考,如何才能进行 RabbitMQ 的消息可靠投递呢? 特  
 别是在这样比较极端的情况,RabbitMQ 集群不可用的时候,无法投递的消息该如何处理呢:


### 6.1 确认机制方案


![在这里插入图片描述](https://img-blog.csdnimg.cn/8cf84b97d715487b83fa905fd493eacf.png)


### 6.2 代码架构图


简单来说就是,生产者发送消息到交换机这一步,不论成功失败,都会有个回调方法被调用,从回调方法可以知道是否发送成功,从而进行下一步处理,比如重新发送  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/f76f03c432ac4e29be8435ad33a7eef5.png)


### 6.3 开启发布确认配置



spring:
rabbitmq:
publisher-confirm-type: correlated


枚举类ConfirmType定义了三种RabbitMQ发布确认类型:


* **NONE**:表示不使用发布确认。当配置为该类型时,生产者发送消息后将不会等待或接收任何确认通知。
* **SIMPLE**:表示使用简单的发布确认。当配置为该类型时,生产者发送消息后将等待Broker的确认通知,并根据确认通知进行下一步的操作。simple模式下如果消息成功到达Broker后一样会触发
* **CORRELATED**:表示消息成功到达Broker后触发ConfirmCalllBack回调;表示使用关联ID的发布确认。当配置为该类型时,生产者发送消息后将等待Broker的确认通知,并通过关联ID来确定是哪条消息被确认。


### 6.4 代码编写


**队列交换机配置**



@Configuration
public class QueueConfig {
public static final String CONFIRM_EXCHANGE_NAME = “confirm.exchange”;
public static final String CONFIRM_QUEUE_NAME = “confirm.queue”;
public static final String ROUTING_KEY = “key1”;

//声明业务 Exchange
@Bean("confirmExchange")
public DirectExchange confirmExchange() {
    return new DirectExchange(CONFIRM\_EXCHANGE\_NAME);
}

// 声明确认队列
@Bean("confirmQueue")
public Queue confirmQueue() {
    return QueueBuilder.durable(CONFIRM\_QUEUE\_NAME).build();
}

// 声明确认队列绑定关系
@Bean
public Binding queueBinding(@Qualifier("confirmQueue") Queue queue,
                            @Qualifier("confirmExchange") DirectExchange exchange) {

    return BindingBuilder.bind(queue).to(exchange).with(ROUTING\_KEY);
}

}


**消息生产者**  
 发送了三条消息


1. 第一条可达
2. 第二条路由不到
3. 第三条没有指定的交换机



@RestController
@RequestMapping(“/confirm”)
@Slf4j
public class Producer {
public static final String CONFIRM_EXCHANGE_NAME = “confirm.exchange”;
@Autowired
private RabbitTemplate rabbitTemplate;
@Autowired
private MyCallBack myCallBack;

//依赖注入 rabbitTemplate 之后再设置它的回调对象
@PostConstruct
public void init() {
    rabbitTemplate.setConfirmCallback(myCallBack);
}

@GetMapping("confirmCallback/{message}")
public void confirmCallback(@PathVariable String message) throws InterruptedException {
    /\*

*此消息正常发送到队列
*/
//指定消息 id 为 1
CorrelationData correlationData1 = new CorrelationData(“1”);
String routingKey = “key1”;
rabbitTemplate.convertAndSend(CONFIRM_EXCHANGE_NAME, routingKey, message + routingKey, correlationData1);
log.info(“发送消息内容:{}”, message);
TimeUnit.SECONDS.sleep(3);
log.info(“\n”);

    /\*

*此消息发到交换机了,但是路由失败,没发送到队列
*/
CorrelationData correlationData2 = new CorrelationData(“2”);
routingKey = “key2”;
rabbitTemplate.convertAndSend(CONFIRM_EXCHANGE_NAME, routingKey, message + routingKey, correlationData2);
log.info(“发送消息内容:{}”, message + routingKey);

img
img

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

``
@RestController
@RequestMapping(“/confirm”)
@Slf4j
public class Producer {
public static final String CONFIRM_EXCHANGE_NAME = “confirm.exchange”;
@Autowired
private RabbitTemplate rabbitTemplate;
@Autowired
private MyCallBack myCallBack;

//依赖注入 rabbitTemplate 之后再设置它的回调对象
@PostConstruct
public void init() {
    rabbitTemplate.setConfirmCallback(myCallBack);
}

@GetMapping("confirmCallback/{message}")
public void confirmCallback(@PathVariable String message) throws InterruptedException {
    /\*

*此消息正常发送到队列
*/
//指定消息 id 为 1
CorrelationData correlationData1 = new CorrelationData(“1”);
String routingKey = “key1”;
rabbitTemplate.convertAndSend(CONFIRM_EXCHANGE_NAME, routingKey, message + routingKey, correlationData1);
log.info(“发送消息内容:{}”, message);
TimeUnit.SECONDS.sleep(3);
log.info(“\n”);

    /\*

*此消息发到交换机了,但是路由失败,没发送到队列
*/
CorrelationData correlationData2 = new CorrelationData(“2”);
routingKey = “key2”;
rabbitTemplate.convertAndSend(CONFIRM_EXCHANGE_NAME, routingKey, message + routingKey, correlationData2);
log.info(“发送消息内容:{}”, message + routingKey);

[外链图片转存中…(img-stKyj3N4-1715594913563)]
[外链图片转存中…(img-rvg96jwy-1715594913564)]

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 27
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值