RabbitMQ死信队列原理与项目代码示例

news2024/11/19 8:50:18
1、产生死信消息的原因

当在消费消息时,如果队列里的消息出现以下情况,那么该消息将成为一条死信消息:

  • 当一条消息被使用 channel.basicNack方法 或 channel.basicReject方法所nack响应 ,并且此时requeue 属性被设置为false。

  • 消息在队列的存活时间超过设置的生存时间(TTL)时间。

  • 消息队列的消息数量超过了设置的最大队列长度。

死信队列(DLQ)非常简单,就一个普通的队列,只不过它是和死信交换机绑定的而已,在声明队列的时候,通过x-dead-letter-exchange参数和x-dead-letter-routing-key指定死信交换机以及死信路由键即可。

  • 参数dead-letter-exchange:指定死信交换机。

  • 参数dead-letter-routing-key:指定死信路由键,用于绑定死信交换机和死信队列。

2、代码实现

pom.xml

plugins {
	id 'java'
	id 'org.springframework.boot' version '3.1.1'
	id 'io.spring.dependency-management' version '1.1.0'
}

group = 'com.kexuexiong'
version = '0.0.1-SNAPSHOT'

java {
	sourceCompatibility = '17'
}

configurations {
	compileOnly {
		extendsFrom annotationProcessor
	}
}

repositories {
//	mavenCentral()
	maven {
		url 'https://maven.aliyun.com/repository/public'
	}
}

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-jdbc'
	implementation 'org.springframework.boot:spring-boot-starter-validation'
	implementation 'org.springframework.boot:spring-boot-starter-web'
	implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:3.0.2'
	compileOnly 'org.projectlombok:lombok'
	runtimeOnly 'com.mysql:mysql-connector-j'
	annotationProcessor 'org.projectlombok:lombok'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
	testImplementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter-test:3.0.2'
	// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-amqp
	implementation 'org.springframework.boot:spring-boot-starter-amqp'
	implementation 'cn.hutool:hutool-all:5.8.16'
}

tasks.named('test') {
	useJUnitPlatform()
}

yml配置文件:
搭建的是RabbitMQ集群:192.168.49.10:5672,192.168.49.9:5672,192.168.49.11:5672
详细搭建过程可以参考往期中的RabbitMQ集群搭建。

server:
  port: 8014

spring:
  rabbitmq:
    username: admin
    password: 123456
    dynamic: true
#    port: 5672
#    host: 192.168.49.9
    addresses: 192.168.49.10:5672,192.168.49.9:5672,192.168.49.11:5672
    publisher-confirm-type: correlated
    publisher-returns: true
  application:
    name: shushan
  datasource:
      driver-class-name: com.mysql.cj.jdbc.Driver
      url: jdbc:mysql://ip/shushan
      username: root
      password: 
      hikari:
        minimum-idle: 10
        maximum-pool-size: 20
        idle-timeout: 50000
        max-lifetime: 540000
        connection-test-query: select 1
        connection-timeout: 600000

常量文件:

package com.kexuexiong.shushan.common.mq;

import javax.swing.plaf.PanelUI;

public class MqConstant {

    public final static String demoDirectQueue = "demoDirectQueue";

    public final static String demoDirectExchange = "demoDirectExchange";

    public final static String demoDirectRouting = "demoDirectRouting";

    public final static String lonelyDirectExchange = "lonelyDirectExchange";

    public final static String topicExchange = "topicExchange";

    public final static String BIG_CAR_TOPIC = "topic.big_car";

    public final static String SMALL_CAR_TOPIC = "topic.small_car";

    public final static String TOPIC_ALL = "topic.#";

    public final static String FANOUT_A = "fanout.A";

    public final static String FANOUT_B = "fanout_B";

    public final static String FANOUT_C = "fanout_c";

    public final static String FANOUT_EXCHANGE = "fanoutExchange";

    public final static String DEAD_LETTER_EXCHANGE = "dead.letter.exchange";

    public final static String DEAD_LETTER_QUEUE = "dead.letter.queue";

    public final static String DEAD_LETTER_ROUTING_KEY = "dead.letter.routing.key";

    public final static String BUSINESS_QUEUE = "business.queue";

    public final static String BUSINESS_ROUTING_KEY = "business.routing.key";

    public final static String BUSINESS_EXCHANGE = "business.exchange";


}

RabbitMQ配置文件:

package com.kexuexiong.shushan.common.mq;


import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;


@Configuration
public class DirectDLXRabbitConfig {

    @Bean
    public Queue businessDirectQueue() {
        HashMap<String, Object> args = new HashMap<>();
        args.put("x-dead-letter-exchange",MqConstant.DEAD_LETTER_EXCHANGE);//设置死信交换机
        args.put("x-dead-letter-routing-key",MqConstant.DEAD_LETTER_ROUTING_KEY);
        return QueueBuilder.durable(MqConstant.BUSINESS_QUEUE).withArguments(args).build();
    }

    @Bean
    DirectExchange businessDirectExchange() {
        return new DirectExchange(MqConstant.BUSINESS_EXCHANGE, true, false);
    }

    @Bean
    DirectExchange deadLetterDirectExchange() {
        return new DirectExchange(MqConstant.DEAD_LETTER_EXCHANGE, true, false);
    }

    @Bean
    public Queue deadLetterDirectQueue() {
        return new Queue(MqConstant.DEAD_LETTER_QUEUE, true, false, false);
    }

    @Bean
    Binding deadLetterBingingDirect() {
        return BindingBuilder.bind(deadLetterDirectQueue()).to(deadLetterDirectExchange()).with(MqConstant.DEAD_LETTER_ROUTING_KEY);
    }


    @Bean
    Binding businessBingingDirect() {
        return BindingBuilder.bind(businessDirectQueue()).to(businessDirectExchange()).with(MqConstant.BUSINESS_ROUTING_KEY);
    }

}

队列绑定死信交换机:
在这里插入图片描述

生产者:

package com.kexuexiong.shushan.controller.mq;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.kexuexiong.shushan.common.mq.MqConstant;
import com.kexuexiong.shushan.controller.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@Slf4j
@RestController
@RequestMapping("/mq/")
public class MqController extends BaseController {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @GetMapping("/deadLetterSendDirectMessage")
    public String deadLetterSendDirectMessage(){

        String msgId = UUID.randomUUID().toString();
        String msg = "demo msg ,dead letter!!";
        String createTime = DateUtil.format(new Date(),"YYYY-MM-dd HH:mm:ss");

        Map<String,Object> map = new HashMap();
        map.put("msgId",msgId);
        map.put("msg",msg);
        map.put("createTime",createTime);

        rabbitTemplate.convertAndSend(MqConstant.BUSINESS_EXCHANGE,MqConstant.BUSINESS_ROUTING_KEY,map);

        return "ok";
    }

    @GetMapping("/deadLetterTimeOutSendDirectMessage")
    public String deadLetterTimeOutSendDirectMessage(){

        String msgId = UUID.randomUUID().toString();
        String msg = "demo msg ,dead letter!!";
        String createTime = DateUtil.format(new Date(),"YYYY-MM-dd HH:mm:ss");
        log.info("msg time :" +createTime);
        Map<String,Object> map = new HashMap();
        map.put("msgId",msgId);
        map.put("msg",msg);
        map.put("createTime",createTime);
        Integer randomInt = RandomUtil.randomInt(30000);
        map.put("randomTime",randomInt);
        MessagePostProcessor messagePostProcessor = message -> {
            // 设置消息过期时间为5秒
            message.getMessageProperties().setExpiration("30000");
            return message;
        };

        rabbitTemplate.convertAndSend(MqConstant.BUSINESS_EXCHANGE,MqConstant.BUSINESS_ROUTING_KEY,map,messagePostProcessor);

        return "ok";
    }

   
}

消费者:

package com.kexuexiong.shushan.common.mq;

import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MessageListenerConfig {

    @Autowired
    private CachingConnectionFactory connectionFactory;

    @Autowired
    private AckReceiver ackReceiver;

    @Bean
    public SimpleMessageListenerContainer simpleMessageListenerContainer() {
        SimpleMessageListenerContainer simpleMessageListenerContainer = new SimpleMessageListenerContainer(connectionFactory);

        simpleMessageListenerContainer.setConcurrentConsumers(2);
        simpleMessageListenerContainer.setMaxConcurrentConsumers(2);
        simpleMessageListenerContainer.setAcknowledgeMode(AcknowledgeMode.MANUAL);
        //,MqConstant.demoDirectQueue, MqConstant.FANOUT_A, MqConstant.BIG_CAR_TOPIC

        simpleMessageListenerContainer.setQueueNames(MqConstant.DEAD_LETTER_QUEUE);

        simpleMessageListenerContainer.setMessageListener(ackReceiver);

        return simpleMessageListenerContainer;
    }

}

AckReceiver:

package com.kexuexiong.shushan.common.mq;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener;
import org.springframework.stereotype.Component;

import java.io.ByteArrayInputStream;
import java.io.ObjectInputStream;
import java.util.Map;
import java.util.Objects;

@Slf4j
@Component
public class AckReceiver implements ChannelAwareMessageListener {
    @Override
    public void onMessage(Message message, Channel channel) throws Exception {
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        byte[] messageBody = message.getBody();
        try (ObjectInputStream inputStream = new ObjectInputStream(new ByteArrayInputStream(messageBody));) {

            Map<String, String> msg = (Map<String, String>) inputStream.readObject();
            log.info(message.getMessageProperties().getConsumerQueue()+"-ack Receiver :" + msg);
            log.info("header msg :"+message.getMessageProperties().getHeaders());
            if(Objects.equals(message.getMessageProperties().getConsumerQueue(),MqConstant.BUSINESS_QUEUE)){
             //拒绝
                channel.basicNack(deliveryTag,false,false);

            }else if(Objects.equals(message.getMessageProperties().getConsumerQueue(),MqConstant.DEAD_LETTER_QUEUE)){
                channel.basicAck(deliveryTag, true);
            }else {
                channel.basicAck(deliveryTag, true);
            }

        } catch (Exception e) {
            channel.basicReject(deliveryTag, false);
            log.error(e.getMessage());
        }
    }
}

测试:

1、当一条消息被使用 channel.basicNack方法 或 channel.basicReject方法所nack响应 ,并且此时requeue 属性被设置为false

在这里插入图片描述

2023-10-11T16:18:13.124+08:00  INFO 28104 --- [enerContainer-2] c.k.shushan.common.mq.AckReceiver        : business.queue-ack Receiver :{msg=demo msg ,dead letter!!, createTime=2023-10-11 16:18:13, msgId=9b31b4b3-c58f-47bd-8b27-cac4f53ae120}
2023-10-11T16:18:13.125+08:00  INFO 28104 --- [enerContainer-2] c.k.shushan.common.mq.AckReceiver        : header msg :{spring_listener_return_correlation=995de3d2-d5a8-42fe-91e6-992fd485d20d}
2023-10-11T16:18:13.125+08:00  INFO 28104 --- [nectionFactory1] c.k.shushan.common.config.RabbitConfig   : confirmCallback  data: null
2023-10-11T16:18:13.125+08:00  INFO 28104 --- [nectionFactory1] c.k.shushan.common.config.RabbitConfig   : confirmCallback ack :true
2023-10-11T16:18:13.125+08:00  INFO 28104 --- [nectionFactory1] c.k.shushan.common.config.RabbitConfig   : confirmCallback cause :null
2023-10-11T16:18:13.127+08:00  INFO 28104 --- [enerContainer-1] c.k.shushan.common.mq.AckReceiver        : dead.letter.queue-ack Receiver :{msg=demo msg ,dead letter!!, createTime=2023-10-11 16:18:13, msgId=9b31b4b3-c58f-47bd-8b27-cac4f53ae120}
2023-10-11T16:18:13.127+08:00  INFO 28104 --- [enerContainer-1] c.k.shushan.common.mq.AckReceiver        : header msg :{spring_listener_return_correlation=995de3d2-d5a8-42fe-91e6-992fd485d20d, x-first-death-exchange=business.exchange, x-death=[{reason=rejected, count=1, exchange=business.exchange, time=Wed Oct 11 16:18:14 CST 2023, routing-keys=[business.routing.key], queue=business.queue}], x-first-death-reason=rejected, x-first-death-queue=business.queue}

if(Objects.equals(message.getMessageProperties().getConsumerQueue(),MqConstant.BUSINESS_QUEUE)){
             //拒绝
                channel.basicNack(deliveryTag,false,false);

  }

消费者代码中拒绝消费,然后消息被路由到死信队列中。

{spring_listener_return_correlation=995de3d2-d5a8-42fe-91e6-992fd485d20d, x-first-death-exchange=business.exchange, x-death=[{reason=rejected, count=1, exchange=business.exchange, time=Wed Oct 11 16:18:14 CST 2023, routing-keys=[business.routing.key], queue=business.queue}], x-first-death-reason=rejected, x-first-death-queue=business.queue}

reason为rejected,并记录原交换机 exchange=business.exchange

2、消息在队列的存活时间超过设置的生存时间(TTL)时间

将消费者中的MqConstant.BUSINESS_QUEUE去掉,后测试。
设置消息过期时间可以在队列中设置:增加参数x-message-ttl

 @Bean("businessQueue")
    public Queue businessQueue() {
        Map<String, Object> args = new HashMap<>(16);
        // 设置当前队列绑定的死信交换机
        args.put("x-dead-letter-exchange", DEAD_LETTER_EXCHANGE);
        // 设置当前队列的死信路由key
        args.put("x-dead-letter-routing-key", DEAD_LETTER_ROUTING_KEY);
        // 设置消息的过期时间 单位:ms(毫秒)
        args.put("x-message-ttl", 5000);
        return QueueBuilder.durable(BUSINESS_QUEUE).withArguments(args).build();
    }

也可以针对每个消息进行设置过期时间:

  @GetMapping("/deadLetterTimeOutSendDirectMessage")
    public String deadLetterTimeOutSendDirectMessage(){

        String msgId = UUID.randomUUID().toString();
        String msg = "demo msg ,dead letter!!";
        String createTime = DateUtil.format(new Date(),"YYYY-MM-dd HH:mm:ss");
        log.info("msg time :" +createTime);
        Map<String,Object> map = new HashMap();
        map.put("msgId",msgId);
        map.put("msg",msg);
        map.put("createTime",createTime);
        Integer randomInt = RandomUtil.randomInt(30000);
        map.put("randomTime",randomInt);
        MessagePostProcessor messagePostProcessor = message -> {
            // 设置消息过期时间为5秒
            message.getMessageProperties().setExpiration("30000");
            return message;
        };

        rabbitTemplate.convertAndSend(MqConstant.BUSINESS_EXCHANGE,MqConstant.BUSINESS_ROUTING_KEY,map,messagePostProcessor);

        return "ok";
    }

在这里插入图片描述
测试:
在这里插入图片描述

2023-10-11T16:28:49.052+08:00  INFO 25848 --- [nio-8014-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2023-10-11T16:28:49.052+08:00  INFO 25848 --- [nio-8014-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2023-10-11T16:28:49.053+08:00  INFO 25848 --- [nio-8014-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 1 ms
2023-10-11T16:28:49.099+08:00  INFO 25848 --- [nio-8014-exec-1] c.k.shushan.controller.mq.MqController   : msg time :2023-10-11 16:28:49
2023-10-11T16:28:49.120+08:00  INFO 25848 --- [nectionFactory1] c.k.shushan.common.config.RabbitConfig   : confirmCallback  data: null
2023-10-11T16:28:49.121+08:00  INFO 25848 --- [nectionFactory1] c.k.shushan.common.config.RabbitConfig   : confirmCallback ack :true
2023-10-11T16:28:49.121+08:00  INFO 25848 --- [nectionFactory1] c.k.shushan.common.config.RabbitConfig   : confirmCallback cause :null
2023-10-11T16:29:19.123+08:00  INFO 25848 --- [enerContainer-1] c.k.shushan.common.mq.AckReceiver        : dead.letter.queue-ack Receiver :{msg=demo msg ,dead letter!!, randomTime=22235, createTime=2023-10-11 16:28:49, msgId=4793dd5c-70c2-4c2f-a6ae-cdc6663e0b05}
2023-10-11T16:29:19.123+08:00  INFO 25848 --- [enerContainer-1] c.k.shushan.common.mq.AckReceiver        : header msg :{spring_listener_return_correlation=22fdc49f-30da-4524-9fc8-d4f69eb4c2c3, x-first-death-exchange=business.exchange, x-death=[{reason=expired, original-expiration=30000, count=1, exchange=business.exchange, time=Wed Oct 11 16:29:20 CST 2023, routing-keys=[business.routing.key], queue=business.queue}], x-first-death-reason=expired, x-first-death-queue=business.queue}

在这里插入图片描述
30秒过期,进入死信队列,然后被消费。

3、 消息队列的消息数量超过了设置的最大队列长度

修改RabbitMQ配置文件,创建businessDirectQueue时增加x-max-length设置容量的参数。

package com.kexuexiong.shushan.common.mq;


import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;


@Configuration
public class DirectDLXRabbitConfig {

    @Bean
    public Queue businessDirectQueue() {
        HashMap<String, Object> args = new HashMap<>();
        args.put("x-dead-letter-exchange",MqConstant.DEAD_LETTER_EXCHANGE);
        args.put("x-dead-letter-routing-key",MqConstant.DEAD_LETTER_ROUTING_KEY);
        args.put("x-max-length", 3);
        return QueueBuilder.durable(MqConstant.BUSINESS_QUEUE).withArguments(args).build();
    }

    @Bean
    DirectExchange businessDirectExchange() {
        return new DirectExchange(MqConstant.BUSINESS_EXCHANGE, true, false);
    }

    @Bean
    DirectExchange deadLetterDirectExchange() {
        return new DirectExchange(MqConstant.DEAD_LETTER_EXCHANGE, true, false);
    }

    @Bean
    public Queue deadLetterDirectQueue() {
        return new Queue(MqConstant.DEAD_LETTER_QUEUE, true, false, false);
    }

    @Bean
    Binding deadLetterBingingDirect() {
        return BindingBuilder.bind(deadLetterDirectQueue()).to(deadLetterDirectExchange()).with(MqConstant.DEAD_LETTER_ROUTING_KEY);
    }


    @Bean
    Binding businessBingingDirect() {
        return BindingBuilder.bind(businessDirectQueue()).to(businessDirectExchange()).with(MqConstant.BUSINESS_ROUTING_KEY);
    }

}

在这里插入图片描述

测试:
在这里插入图片描述

在这里插入图片描述
第三次请求的结果:
在这里插入图片描述

第四次请求结果:
在这里插入图片描述
控制台输出,死信队列接收到消息。

2023-10-11T16:46:54.783+08:00  INFO 20444 --- [nectionFactory2] c.k.shushan.common.config.RabbitConfig   : confirmCallback  data: null
2023-10-11T16:46:54.783+08:00  INFO 20444 --- [nectionFactory2] c.k.shushan.common.config.RabbitConfig   : confirmCallback ack :true
2023-10-11T16:46:54.783+08:00  INFO 20444 --- [nectionFactory2] c.k.shushan.common.config.RabbitConfig   : confirmCallback cause :null
2023-10-11T16:46:54.787+08:00  INFO 20444 --- [enerContainer-1] c.k.shushan.common.mq.AckReceiver        : dead.letter.queue-ack Receiver :{msg=demo msg ,dead letter!!, createTime=2023-10-11 16:44:35, msgId=db7d2d7f-12a0-4ca4-9e92-81758cda436e}
2023-10-11T16:46:54.787+08:00  INFO 20444 --- [enerContainer-1] c.k.shushan.common.mq.AckReceiver        : header msg :{spring_listener_return_correlation=e2a1871a-7765-43ee-b44c-d80d0ac6323c, x-first-death-exchange=business.exchange, x-death=[{reason=maxlen, count=1, exchange=business.exchange, time=Wed Oct 11 16:46:56 CST 2023, routing-keys=[business.routing.key], queue=business.queue}], x-first-death-reason=maxlen, x-first-death-queue=business.queue}

到这里三种情况都介绍完了,总体来讲RabbitMQ的死信队列还是很简单的。但是它作用还是很强大的,可以用于实现延时消息,订单到时取消等。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1095185.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

使用Elasticsearch来进行简单的DDL搜索数据

说明&#xff1a;Elasticsearch提供了多种多样的搜索方式来满足不同使用场景的需求&#xff0c;我们可以使用Elasticsearch来进行各种复制的查询&#xff0c;进行数据的检索。 1.1 精准查询 用来查询索引中某个类型为keyword的文本字段&#xff0c;类似于SQL的“”查询。 创…

Python学习基础笔记六十七——格式化字符串

Printf-Style String Formatting: Printf风格字符串格式化 salary input(请输入薪资&#xff1a;)# 计算出缴税额&#xff0c;存入变量tax tax int(salary) *25/100 # 转化为字符串&#xff0c;方便下面的字符串拼接 taxStr str(tax) # 计算出税后工资&#xff0c;存入变…

Linux基础—1

1、命令行 1) 重要快捷键 按键作用Tab命令补全Ctrl强行终止当前程序Ctrld键盘输入结束或退出终端Ctrls暂停当前程序&#xff0c;暂停后按下任意键恢复运行Ctrlz将当前程序放到后台运行&#xff0c;恢复到前台为命令fgCtrla将光标移至输入行头&#xff0c;相当于Home键Ctrle将…

计算机操作系统-第六天

目录 1、操作系统的体系结构&#xff08;简要了解&#xff09; 操作系统的内核&#xff1a; 操作系统的体系结构 关于微内核的相关理解&#xff1a; 本节思维导图&#xff1a; 1、操作系统的体系结构&#xff08;简要了解&#xff09; 操作系统的内核&#xff1a; 内核是…

整理总结提高抖音小店商品转化率的五大策略

要提高抖音小店的商品转化率&#xff0c;即将浏览者转化为实际购买者&#xff0c;四川不若与众整理了需要注意的以下几个关键因素。 首先&#xff0c;优化商品页面设计。商品页面是消费者获取产品信息和决策的关键环节。商家应确保商品页面简洁清晰&#xff0c;配备高质量的产品…

Pytest+Allure生成可添加附件的测试报告

#测试套件层级 allure.feature("测试PecExplorer") #重试次数&#xff0c;粒度为用例&#xff0c;建议用例设计可重复性高 pytest.mark.flaky(reruns3) class TestPecExplorer:#功能模块层级allure.story("登录界面")#测试用例层级allure.title("Test…

C语言程序设计 三四节课堂笔记

C语言程序设计 三四节课堂笔记 C语言程序设计 三四节课堂笔记3.0 程序编写顺序&#xff08;了解&#xff09;3.1 C语言的特点3.2 认识C程序1. C程序的基本框架2. C语言程序的结构特点3. C程序的开发过程 C语言程序设计 第四节课4.1 开发环境dev-C的使用1. 如何将英文界面调整为…

Spring-Java

Spring&#xff1a; 图片出处&#xff1a;b站黑马 ssm学习截图 是一个大家族 &#xff0c;是一套完整的开发生态圈。可以利用这个spring全家桶快速构建企业级开发环境。 Spring Freamwork 是其他框架的基础 Springbot 使用了注解开发 SpringCloud 分布式 云服务 Sprin…

Leetcode—88.合并两个有序数组【简单】

2023每日刷题&#xff08;一&#xff09; Leetcode—88.合并两个有序数组 题解 因为这两个数组已经排好序&#xff0c;我们可以把两个指针分别放在两个数组的末尾&#xff0c;即 nums1 的m − 1 位和 nums2 的 n − 1 位。每次将较大的那个数字复制到 nums1 的后边&#xff0…

计算机操作系统面试题自用

什么是操作系统&#xff1a; 操作系统是管理硬件和软件的一种应用程序。操作系统是运行在计算机上最重要的一种软件 操作系统的主要功能 解释一下操作系统的主要目的是什么 操作系统是一种软件&#xff0c;它的主要目的有三种 1 管理计算机资源&#xff0c;这些资源包括 C…

LangChain结合milvus向量数据库以及GPT3.5结合做知识库问答之一 --->milvus的docker compose安装

https://github.com/milvus-io/milvus/releaseshttps://github.com/milvus-io/milvus/releases 以下步骤均在Linux环境中进行&#xff1a; 将milvus-standalone-docker-compose.yml下载到本地。 1、新建一个目录milvus 2、将milvus-standalone-docker-compose.yml放到milvu…

UWB承启定位基站

UWB承启定位基站 随着我们使用UWB做超高精度的定位项目越来越多&#xff0c;我们发现之前的定位基站完全站在二维或三维的角度去设计还是存在对应的缺陷&#xff0c;这个时候需要在很短的距离内安装多一个基站&#xff0c;对于用户来说&#xff0c;会觉得设备变多了&#xff0…

05在IDEA中配置Maven的基本信息

配置Maven信息 配置Maven家目录 每次创建Project工程后都需要设置Maven家目录位置&#xff0c;否则IDEA将使用内置的Maven核心程序和使用默认的本地仓库位置 一般我们配置了Maven家目录后IDEA就会自动识别到conf/settings.xml配置文件和配置文件指定的本地仓库位置创建新的P…

Java中的栈(Stack)为什么要采用先进后出

Java虚拟机栈 Java虚拟机栈是描述Java方法运行过程的内存模型。 当一个方法即将被运行时&#xff0c;Java虚拟机栈首先会在Java虚拟机栈中为该方法创建一块“栈帧”&#xff0c;栈帧中包含局部变量表(基本数据类型变量、引用类型的变量、returnAddress类型的变量)、操作数栈、…

小谈设计模式(29)—访问者模式

小谈设计模式&#xff08;29&#xff09;—访问者模式 专栏介绍专栏地址专栏介绍 访问者模式角色分析访问者被访问者 优缺点分析优点将数据结构与算法分离增加新的操作很容易增加新的数据结构很困难4 缺点增加新的数据结构比较困难增加新的操作会导致访问者类的数量增加34 总结…

windows10系统-16-制作导航网站WebStack-Hugo

上个厕所功夫把AI导航搞定了 使用Hugo搭建静态站点 如何使用Hugo框架搭建一个快如闪电的静态网站 1 Hugo 参考Hugo中文文档 参考使用Hugo搭建个人网站 Hugo是由Go语言实现的静态网站生成器。简单、易用、高效、易扩展、快速部署。 1.1 安装Hugo 二进制安装&#xff08;推荐…

iMeta框架使用方法

&#x1f4e2;&#x1f4e2;&#x1f4e2;&#x1f4e3;&#x1f4e3;&#x1f4e3; 哈喽&#xff01;大家好&#xff0c;我是「奇点」&#xff0c;江湖人称 singularity。刚工作几年&#xff0c;想和大家一同进步&#x1f91d;&#x1f91d; 一位上进心十足的【Java ToB端大厂…

判断一棵树是否为完全二叉树——层序遍历

完全二叉树&#xff08;包括满二叉树 &#xff09; 利用层序遍历&#xff0c;当取顶取到空的时候&#xff08;这个时候取的这一层的所有节点是一定在队列里面的&#xff09;&#xff0c;就结束入队&#xff0c;然后判断他的后面的节点是否都为空 这里重点还是要理解二叉树的层…

求二叉树的高度——函数递归的思想

二叉树的高度&#xff1a;左右两个数最高的那个的1 int TreeHight(BTNode* root) {if (root NULL){return 0;}int lefhightTreeHight(root->left);int righthight TreeHight(root->right);return lefhight > righthight ? TreeHight(root->left) 1 : TreeHight…

集合的进阶

不可变集合 创建不可变的集合 在创建了之后集合的长度内容都不可以变化 静态集合的创建在list &#xff0c;set &#xff0c;map接口当中都可以获取不可变集合 方法名称说明static list of(E …elements)创建一个具有指定元素集合list集合对象staticlist of(E…elements)创…