当前位置: 首页 > news >正文

RabbitMQ应用问题——消息补偿机制以及代码示例

RabbitMQ应用问题——消息补偿机制以及代码示例

RabbitMQ应用问题

  • 消息可靠性的保障
    • 消息补偿机制

在这里插入图片描述

详细说明

这里使用了简单的代码进行演示,订单的消费者没有写,在订单的消费同时,发送一条增加积分消息到积分队列。

详细流程途中都有注明。

为了更加清楚代码这里进行表明功能。

在这里插入图片描述

gitee地址

1.创建mq-manager父工程

1.1导入依赖

 <packaging>pom</packaging><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.0</version><relativePath/> <!-- lookup parent from repository -->
</parent><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-amqp</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>2.0.7</version></dependency></dependencies>

2.创建mq-common子模块

2.1导入依赖

<dependencies><!-- mybatis-plus --><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.2</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><scope>runtime</scope></dependency><dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId><version>1.2.6</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency>
</dependencies>

2.2编写实体类

2.2.1Order
package com.qf.entity;import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;import java.math.BigDecimal;
import java.util.Date;
/*{ "bizNo": "20200803173145877","status": 1,"price": 34.12,"goodId": 1002,"userId": 100}*///订单
@TableName("orders")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Order {@TableId(value = "id", type = IdType.AUTO)private Integer id;@TableField(value = "biz_no")private String bizNo; //业务编号@TableField(value = "status")private Integer status;@TableField(value = "price")private BigDecimal price;@TableField(value = "create_time")private Date createTime;@TableField(value = "pay_time")private Date payTime;@TableField(value = "good_id")private Integer goodId;@TableField(value = "user_id")private Integer userId;//exist = false:该属性不使用@TableField(value = "num", exist = false)private Integer num;
}
2.2.2Integral
package com.qf.entity;import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;import java.util.Date;//积分
@TableName("integral")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Integral{@TableId(type = IdType.AUTO)private Integer id;@TableField("user_id")private Integer userId;private Long score;private String msg;@TableField("create_time")private Date createTime;
}
2.2.3Msg
package com.qf.entity;import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;import java.util.Date;//消息
@TableName("message")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Msg {@TableId(value = "id")private String id;@TableField(value = "exchange")private String exchange;@TableField(value = "routing_key")private String routingKey;@TableField(value = "content")private String content; // 消息的内容@TableFieldprivate Integer status; // 消息的状态@TableField(value = "try_count")private int tryCount; //尝试次数@TableField(value = "create_time")private Date createTime;
}

2.3编写公共参数

2.3.1IntegralConstant
package com.qf.contant;//设置系统中的参数
public class IntegralConstant {// 积分系统队列public final static String INTEGRAL_QUEUE = "integral_queue";// 积分系统交换机public final static String INTEGRAL_EXCHANGE = "integral_exchange";// 积分系统的 routing-keypublic final static String INTEGRAL_ROUTING_KEY= "integral_routing_key";
}
2.3.2DeadConstant
package com.qf.contant;//死信
public class DeadConstant {//死信交换机public static final String DEAD_LETTER_EXCHANGE = "dead_letter_exchange";//死信路由键public static final String DEAD_LETTER_ROUTING_KEY = "dead_letter_routing_key";//死信队列public static final String DEAD_LETTER_QUEUE = "dead_letter_queue";
}

3.编写mq-order子模块

3.1导入公共模块

<dependencies><dependency><groupId>com.qf</groupId><artifactId>mq-common</artifactId><version>1.0-SNAPSHOT</version></dependency>
</dependencies>

3.2编写配置文件

server:port: 8080spring:datasource:username: rootpassword: rooturl: jdbc:mysql://localhost:3306/mq?serverTimezone=Asia/Shanghai&characterEncoding=utf8driver-class-name: com.mysql.cj.jdbc.Drivertype: com.alibaba.druid.pool.DruidDataSourcerabbitmq:username: guestpassword: guesthost: 192.168.25.129port: 5672publisher-confirm-type: simplepublisher-returns: truemybatis-plus:mapper-locations: classpath:mapper/*.xmlconfiguration:log-impl: org.apache.ibatis.logging.stdout.StdOutImpl#驼峰形式map-underscore-to-camel-case: true

3.3编写启动类

package com.qf;import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
@MapperScan("com.qf.mapper")
public class OrderApplication {public static void main(String[] args) {SpringApplication.run(OrderApplication.class,args);}
}

3.4编写OrderController

package com.qf.controller;import com.qf.entity.Order;
import com.qf.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
@RequestMapping("order")
public class OrderController {@Autowiredprivate OrderService orderService;@PostMapping("insertOrder")public String insertOrder(@RequestBody Order order){orderService.insertOrder(order);return "success";}}

3.5编写OrderService

package com.qf.service;import com.qf.entity.Order;public interface OrderService {/*** 插入订单* @param order*/void insertOrder(Order order);
}

3.6编写OrderServiceImpl

package com.qf.service.impl;import com.alibaba.fastjson.JSON;
import com.qf.contant.IntegralConstant;
import com.qf.entity.Integral;
import com.qf.entity.Msg;
import com.qf.entity.Order;
import com.qf.mapper.MsgMapper;
import com.qf.mapper.OrderMapper;
import com.qf.service.OrderService;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;import javax.annotation.Resource;
import java.util.Date;
import java.util.UUID;@Service
@Transactional
public class OrderServiceImpl implements OrderService {@Autowiredprivate OrderMapper orderMapper;@Autowiredprivate MsgMapper msgMapper;@Resourceprivate RabbitTemplate rabbitTemplate;@Overridepublic void insertOrder(Order order) {//插入订单orderMapper.insert(order);//插入积分,是把积分信息发送到消息队列中Integral integral = new Integral();integral.setUserId(order.getUserId());//积分对应的用户id就是下订单的用户idintegral.setScore(10L);integral.setMsg("购物积分");integral.setCreateTime(new Date());//把积分对象,转换为Json类型,发送到消息队列中String integralJson = JSON.toJSONString(integral);//创建消息对象,如果消息消费成功了,再去删除对应的消息Msg msg = new Msg();//分布式环境下,id必须是唯一的,解决方案:百度的uid-generator,美团开源项目LeafString uuid = UUID.randomUUID().toString();msg.setId(uuid);msg.setExchange(IntegralConstant.INTEGRAL_EXCHANGE);//积分对应的交换机msg.setRoutingKey(IntegralConstant.INTEGRAL_ROUTING_KEY);//积分对象的路由的keymsg.setContent(integralJson);//积分的Json对象msg.setStatus(-1);//状态msg.setTryCount(0);//尝试次数msg.setCreateTime(new Date());//时间//插入消息msgMapper.insert(msg);//发送消息,需要把Msg对象的id(就是uuid)传过来,一旦消息消费成功,还要去Msg对应表中把该消息删除CorrelationData correlationData = new CorrelationData(uuid);System.out.println("uuid:" + uuid);System.out.println("correlationData.getId():" + correlationData.getId());//发送rabbitTemplate.convertAndSend(IntegralConstant.INTEGRAL_EXCHANGE,IntegralConstant.INTEGRAL_ROUTING_KEY,buildMessage(integralJson,uuid),correlationData);}//构建消息private Message buildMessage(String body,String messageId){//获取MessagePropertiesBuilder对象MessagePropertiesBuilder messagePropertiesBuilder = MessagePropertiesBuilder.newInstance();//获取MessageProperties对象MessageProperties messageProperties = messagePropertiesBuilder.build();messageProperties.setMessageId(messageId);messageProperties.setDeliveryMode(MessageDeliveryMode.PERSISTENT);//消息持久化Message message = new Message(body.getBytes(),messageProperties);System.out.println("message传递的内容:" + new String(message.getBody()));System.out.println("message传递的uuid:" + message.getMessageProperties().getMessageId());return message;}
}

3.7编写OrderMapper

package com.qf.mapper;import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qf.entity.Order;
import org.springframework.stereotype.Repository;@Repository
public interface OrderMapper extends BaseMapper<Order> {
}

3.8编写MsgMapper

package com.qf.mapper;import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qf.entity.Msg;
import org.springframework.stereotype.Repository;@Repository
public interface MsgMapper extends BaseMapper<Msg> {
}

3.9编写配置类

3.9.1DeadConfig
package com.qf.config;import com.qf.constant.DeadConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
public class DeadConfig {//创建队列@Beanpublic Queue createDeadQueue(){return new Queue(DeadConstant.DEAD_LETTER_QUEUE);}//创建交换机@Beanpublic DirectExchange createDeadExchange(){//交换机默认持久化return new DirectExchange(DeadConstant.DEAD_LETTER_EXCHANGE);}//绑定:交换机中的消息可以发送到不同的队列@Beanpublic Binding bindingDeadQueue(){//需要设置routingKeyreturn BindingBuilder.bind(createDeadQueue()).to(createDeadExchange()).with(DeadConstant.DEAD_LETTER_ROUTING_KEY);//和发送消息时的routingKey一致}
}
3.9.2IntegralConfig
package com.qf.config;import com.qf.constant.DeadConstant;
import com.qf.constant.IntegralConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;import java.util.HashMap;
import java.util.Map;//路由模式
@Configuration
public class IntegralConfig {//创建队列@Beanpublic Queue createIntegralQueue(){Map<String, Object> arguments = new HashMap<>();arguments.put("x-dead-letter-exchange", DeadConstant.DEAD_LETTER_EXCHANGE);arguments.put("x-dead-letter-routing-key", DeadConstant.DEAD_LETTER_ROUTING_KEY);return new Queue(IntegralConstant.INTEGRAL_QUEUE,true,false,false,arguments);}//创建交换机@Beanpublic DirectExchange createIntegralExchange(){//交换机默认持久化return new DirectExchange(IntegralConstant.INTEGRAL_EXCHANGE);}//绑定:交换机中的消息可以发送到不同的队列@Beanpublic Binding bindingIntegralQueue(){//需要设置routingKeyreturn BindingBuilder.bind(createIntegralQueue()).to(createIntegralExchange()).with(IntegralConstant.INTEGRAL_ROUTING_KEY);//和发送消息时的routingKey一致}}
3.9.3PublisherConfirmAndReturnConfig
package com.qf.config;import com.qf.entity.Msg;
import com.qf.mapper.MsgMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.ReturnedMessage;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;@Slf4j
@Configuration
public class PublisherConfirmAndReturnConfig implementsRabbitTemplate.ConfirmCallback,RabbitTemplate.ReturnsCallback {@Resourceprivate RabbitTemplate rabbitTemplate;@Autowiredprivate MsgMapper msgMapper;@PostConstructpublic void init(){rabbitTemplate.setConfirmCallback(this);rabbitTemplate.setReturnsCallback(this);}@Overridepublic void confirm(CorrelationData correlationData, boolean ack, String s) {//判断if(ack){log.info("已到达broker");log.info("correlationData id is {}",correlationData.getId());//删除存到数据库中的消息//msgMapper.deleteById(correlationData.getId());//通过id删除//设置删除条件HashMap<String, Object> map = new HashMap<>();map.put("id",correlationData.getId());map.put("status",-1);//多条件删除msgMapper.deleteByMap(map);}else{log.info("没有到达broker,实际上消息已经保存到mysql中,也可以保存到redis中");}}//return机制,该方法比confirm先执行,只要未到达队列的时候才执行@Overridepublic void returnedMessage(ReturnedMessage returnedMessage) {log.info("消息未到达队列");//如果消息到达队列不执行以下代码//消息已经从数据库被删除了//考虑人工干预,获取消息信息进行保存String exchange = returnedMessage.getExchange();String routingKey = returnedMessage.getRoutingKey();Message message = returnedMessage.getMessage();//创建消息对象,如果消息消费成功了,再去删除对应的消息Msg msg = new Msg();msg.setId(message.getMessageProperties().getMessageId());msg.setExchange(exchange);//积分对应的交换机msg.setRoutingKey(routingKey);//积分对象的路由的keymsg.setContent(new String(message.getBody()));//积分的Json对象msg.setStatus(-2);//状态可以设置为和之前不一样msg.setTryCount(0);//尝试次数msg.setCreateTime(new Date());//时间//插入消息msgMapper.insert(msg);//做进一步处理:给管理员发邮件,发短信....}
}

4.创建mq-integral子模块

4.1导入依赖

<dependencies><dependency><groupId>com.qf</groupId><artifactId>mq-common</artifactId><version>1.0-SNAPSHOT</version></dependency><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.8.4</version></dependency>
</dependencies>

4.2编写配置文件

server:port: 8081spring:datasource:username: rootpassword: rooturl: jdbc:mysql://localhost:3306/mq?serverTimezone=Asia/Shanghai&characterEncoding=utf8driver-class-name: com.mysql.cj.jdbc.Drivertype: com.alibaba.druid.pool.DruidDataSourcerabbitmq:username: guestpassword: guesthost: 192.168.25.134port: 5672listener:simple:retry:enabled: true #开启消息重试max-attempts: 3 #最大重试次数initial-interval: 2000ms #每次重试的时间间隔multiplier: 2 #每次重试时间乘以当前倍数#重试机制必须是自动ack,才能放到死信队列中acknowledge-mode: automybatis-plus:mapper-locations: classpath:mapper/*.xmlconfiguration:log-impl: org.apache.ibatis.logging.stdout.StdOutImpl#驼峰形式map-underscore-to-camel-case: true

4.3编写启动类

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
@MapperScan("com.qf.mapper")
public class IntegralApplication {public static void main(String[] args) {SpringApplication.run(IntegralApplication.class,args);}
}

4.4编写IntegralImpl

package com.qf.service.impl;import com.alibaba.fastjson.JSON;
import com.qf.constant.IntegralConstant;
import com.qf.entity.Integral;
import com.qf.mapper.IntegralMapper;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;import java.util.Random;
import java.util.concurrent.TimeUnit;@Service
public class IntegralImpl {@Autowiredpublic IntegralMapper integralMapper;@Autowiredprivate StringRedisTemplate stringRedisTemplate;//    //第一种方式    
//    @RabbitListener(
//            bindings = @QueueBinding(
//                    value = @Queue(name = IntegralConstant.INTEGRAL_QUEUE,
//                    durable = "true"
//            ),
//            key = {IntegralConstant.INTEGRAL_ROUTING_KEY},
//            exchange = @Exchange(name = IntegralConstant.INTEGRAL_EXCHANGE, durable = "true")
//    ))
//    public void insertIntegral(Message message){
//        //积分信息
//        String integralJson = new String(message.getBody());
//        System.out.println(integralJson);
//
//        //类型转换
//        Integral integral = JSON.parseObject(integralJson, Integral.class);
//        System.out.println(integral);
//        //插入数据库
//        integralMapper.insert(integral);
//    }//    //第二种方式  
//    @RabbitListener(queues = IntegralConstant.INTEGRAL_QUEUE)
//    public void insertIntegral(Message message) throws InterruptedException {
//        //积分信息
//        String integralJson = new String(message.getBody());
//        System.out.println(integralJson);
//
//        //运行成功
//        //类型转换
//        Integral integral = JSON.parseObject(integralJson, Integral.class);
//        System.out.println(integral);
//        //插入数据库
//        integralMapper.insert(integral);
//
//        //测试消息重复消费
//        //直到方法执行完毕,才会ack
//        Thread.sleep(500000);
//
//        //测试消息重试
//        //System.out.println("当前系统时间:"+System.currentTimeMillis());
//        //运行失败
//        //throw new RuntimeException("消息消费异常...");
//    }@RabbitListener(queues = IntegralConstant.INTEGRAL_QUEUE)public void receiveIntegralMessage(Message message){//获取要被消息的消息idString messageId = message.getMessageProperties().getMessageId();//判断,如果redis中没有这个消息id的key,则是第一次消费该消息if(!stringRedisTemplate.hasKey(messageId)){//获取积分信息String integralJson = new String(message.getBody());//类型转换Integral integral = JSON.parseObject(integralJson, Integral.class);//插入到数据库integralMapper.insert(integral);//使用hutool工具类生成随机数int randomInt = RandomUtil.randomInt(10, 100);//往redis中也存一份stringRedisTemplate.opsForValue().setIfAbsent(messageId,String.valueOf(randomInt),600, TimeUnit.SECONDS);}}

4.5编写IntegralMapper

package com.qf.mapper;import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qf.entity.Integral;
import org.springframework.stereotype.Repository;@Repository
public interface IntegralMapper extends BaseMapper<Integral> {
}

5.创建mq-compensate子工程

5.1导入依赖

<dependencies><dependency><groupId>com.qf</groupId><artifactId>mq-order</artifactId><version>1.0-SNAPSHOT</version></dependency>
</dependencies>

4.2编写配置文件

server:port: 8082spring:datasource:username: rootpassword: rooturl: jdbc:mysql://localhost:3306/mq?serverTimezone=Asia/Shanghai&characterEncoding=utf8driver-class-name: com.mysql.cj.jdbc.Drivertype: com.alibaba.druid.pool.DruidDataSourcerabbitmq:username: guestpassword: guesthost: 192.168.25.134port: 5672publisher-confirm-type: simplepublisher-returns: truemybatis-plus:mapper-locations: classpath:mapper/*.xmlconfiguration:log-impl: org.apache.ibatis.logging.stdout.StdOutImpl#驼峰形式map-underscore-to-camel-case: true

4.3编写启动类

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;@SpringBootApplication
@EnableScheduling
public class CompensateApplication {public static void main(String[] args) {SpringApplication.run(CompensateApplication.class,args);}
}

4.4编写MassageCompensateTask

package com.qf.task;import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.contant.IntegralConstant;
import com.qf.entity.Msg;
import com.qf.mapper.MsgMapper;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageDeliveryMode;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.core.MessagePropertiesBuilder;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;import javax.annotation.Resource;
import java.util.List;/**** 消息补偿:隔一段时间,去数据库查询未消费掉的消息,再次执行*/@Configuration
public class MassageCompensateTask {@Autowiredprivate MsgMapper msgMapper;@Resourceprivate RabbitTemplate rabbitTemplate;@Scheduled(cron = "10 * * * * ?")public void compensateTask(){//设置查询条件QueryWrapper<Msg> queryWrapper = new QueryWrapper<>();queryWrapper.eq("status","-2");queryWrapper.lt("try_count","3");//查询消息List<Msg> msgList = msgMapper.selectList(queryWrapper);//判断if(msgList.size() > 0){for(Msg msg : msgList){System.out.println("数据库中的消息id:" + msg.getId());//发送rabbitTemplate.convertAndSend(msg.getExchange(),msg.getRoutingKey(),buildMessage(msg.getContent(),msg.getId()),new CorrelationData(msg.getId()));//设置尝试次数msg.setTryCount(msg.getTryCount() + 1);//修改数据库中的消息msgMapper.updateById(msg);}}}//构建消息private Message buildMessage(String body, String messageId){//获取MessagePropertiesBuilder对象MessagePropertiesBuilder messagePropertiesBuilder = MessagePropertiesBuilder.newInstance();//获取MessageProperties对象MessageProperties messageProperties = messagePropertiesBuilder.build();messageProperties.setMessageId(messageId);messageProperties.setDeliveryMode(MessageDeliveryMode.PERSISTENT);//消息持久化Message message = new Message(body.getBytes(),messageProperties);System.out.println("message传递的内容:" + new String(message.getBody()));System.out.println("message传递的uuid:" + message.getMessageProperties().getMessageId());return message;}
}

相关文章:

RabbitMQ应用问题——消息补偿机制以及代码示例

RabbitMQ应用问题——消息补偿机制以及代码示例 RabbitMQ应用问题 消息可靠性的保障 消息补偿机制 详细说明 这里使用了简单的代码进行演示&#xff0c;订单的消费者没有写&#xff0c;在订单的消费同时&#xff0c;发送一条增加积分消息到积分队列。 详细流程途中都有注明…...

量化特征贡献度函数:feature_importances_函数/LGBMClassifier/XGBClassifier

feature_importances_是scikit-learn机器学习库中许多模型对象的属性&#xff0c;在训练模型之后调用该属性可以输出各个特征在模型中的重要性。 示例代码&#xff1a; from sklearn.ensemble import RandomForestRegressor from sklearn.datasets import make_regression# 生…...

总结JVM重要知识点

一.类加载和创建对象的过程 1.类加载 1.编译 : 将源码文件(.java)编译成JVM可以解释的.class文件 . 语法分析>语义分析>注解处理 , 生成class文件 2.加载 : 装载 : 字节码本来存储在硬盘上 , 需要运行时 , 有类加载系统负责将类的信息加载到内存中(方法区) , 使用的是类…...

奇技淫巧第8期

学无止境。 下面是对去年11月至今年5月的零散知识点总结。 春节期间好好放松了一两个月&#xff0c;来校后又懒散的度过了一两个月&#xff0c;直到论文评审意见下来&#xff0c;才开启冲刺模式狂干了一两个月。总的来说&#xff0c;这半年来摸的时间比较多。好&#xff0c;不废…...

这个 归并排序详解过程 我能吹一辈子!!!

文章目录 归并排序概念归并排序算法思路归并排序递归实现归并排序非递归实现 归并排序概念 1945年&#xff0c;约翰冯诺依曼&#xff08;John von Neumann&#xff09;发明了归并排序&#xff0c;这是典型的分治算法的应用。 归并排序&#xff08;Merge sort&#xff09;是建立…...

docker版jxTMS使用指南:自动生成代码

本文讲解4.0版jxTMS的自动生成代码功能&#xff0c; 整个系列的文章请查看&#xff1a;docker版jxTMS使用指南&#xff1a;4.0版升级内容 docker版本的使用&#xff0c;请参考&#xff1a;docker版jxTMS使用指南 任何一个管理系统都需要对管理对象进行管理&#xff0c;包括最…...

聚观早报 | 小冰启动GPT克隆人计划;ofo创始人在美创业改做咖啡

今日要闻&#xff1a;小冰启动“GPT克隆人计划”&#xff1b;ofo创始人在美创业改做咖啡&#xff1b;OpenAI正准备新的开源AI模型&#xff1b;青年失业率首破20&#xff05;创新高&#xff1b;微软收购动视暴雪获批 小冰启动“GPT克隆人计划” 5 月 16 日&#xff0c;小冰公司…...

面试造航母,入职拧螺丝,工资离了个大谱...

有粉丝跟我吐槽说&#xff1a;金三银四去面试软件测试岗&#xff0c;真的是面试造航母&#xff0c;入职拧螺丝&#xff0c;工资还低 这种现象很正常&#xff0c;因为找一个测试员&#xff0c;当然希望他能做的业务越多越好&#xff0c;最好像机器猫一样&#xff0c;啥事儿都能…...

Python+selenium自动化元素定位防踩坑

在自动化UI测试过程中常常会在元素定位阶段就踩坑&#xff0c;碰到困扰已久的问题。 以下是个人整理元素定位报错原因和解决方法。 踩坑一&#xff1a;StaleElementReferenceException selenium.common.exceptions.StaleElementReferenceException: Message: stale element re…...

【计算机组成原理】实验一

文章目录 实验一 数据传送实验1. 实验目的2. 实验仪器3. 原理概述4. 实验内容步骤4.1 手动实验环境的建立4.2 手控传送实验 5. 实验结论及问题讨论 实验一 数据传送实验 1. 实验目的 2. 实验仪器 3. 原理概述 4. 实验内容步骤 4.1 手动实验环境的建立 1)初始待令状态 上电或…...

前端022_广告模块_修改功能

广告模块_修改功能 1、需求分析2、Mock添加查询数据3、Mock修改数据4、Api调用回显数据5、提交修改后的数据6、效果1、需求分析 需求分析 当点击 编辑 按钮后,弹出编辑窗口,并查询出分类相关信息进行渲染。修改后点击 确定 提交修改后的数据。 2、Mock添加查询数据 请求URL…...

makefile 学习(3):C++的编译及库文件的生成与链接

1. 介绍 C语言的相关后缀 .a 文件是一个静态库文件.c,.c ,.cp,.cpp,.cc,.cxx 这几种后缀都可以表示c的源文件.h ,.hpp c语言的头文件.i 是c预处理文件.o 目标文件.s汇编语言的文件.so 动态库或者共享库或者称为运行时库 2. C编译 2.1 预处理 g -E helloworld.cpp # 虽…...

Ceph crush运行图

Crush map介绍 ceph集群中由monitor负责维护的运行图包括&#xff1a; Monitor map&#xff1a;监视器运行图osd map&#xff1a;osd运行图PG map&#xff1a;PG运行图Crush map&#xff1a;crush运行图Mds map&#xff1a;mds运行图 crush map是ceph集群物理拓扑的抽象&…...

【分布族谱】泊松分布和二项分布、正态分布的关系

文章目录 泊松分布和二项分布的关系和正态分布的关系 泊松分布 如果在有限时间 ( 0 , 1 ) (0,1) (0,1)内进行 n n n次伯努利实验&#xff0c;那么每次伯努利实验所占用的时间为 1 n \frac{1}{n} n1​&#xff0c;按照自然规律&#xff0c;一件事情肯定是时间越长越容易发生&am…...

关于QTreeWidget的setData函数

当使用 Q T r e e W i d g e t I t e m QTreeWidgetItem QTreeWidgetItem 的 s e t D a t a setData setData 方法时&#xff0c;需要传递三个参数&#xff0c;分别是列索引、角色和数据。 列索引&#xff1a;表示要设置数据的列的索引。 Q T r e e W i d g e t I t e m QTre…...

Microsoft Office 2003的安装

哈喽&#xff0c;大家好。今天一起学习的是office2003的安装&#xff0c;这个老版本的office可是XP操作系统的老搭档了&#xff0c;有兴趣的小伙伴也可以来一起试试手。 一、测试演示参数 演示操作系统&#xff1a;Windows XP 不建议win7及以上操作系统使用 系统类型&#xff…...

使用Spring Boot和Spring Cloud实现多租户架构:支持应用多租户部署和管理

使用Spring Boot和Spring Cloud实现多租户架构&#xff1a;支持应用多租户部署和管理 一、概述1 什么是多租户架构&#xff1f;2 多租户架构的优势3 实现多租户架构的技术选择 二、设计思路1 架构选型1.1 Spring Boot1.2 Spring Cloud 2 数据库设计3 应用多租户部署3.1 应用隔离…...

智聚北京!相约全球人力资源数智化峰会

人力资源是推动经济社会发展的第一资源。作为我国经济压舱石的中央企业在对标世界一流企业和管理提升方面的持续创新&#xff0c;各行业领军企业围绕组织变革、管理升级、全球化发展走深走实。人力资源管理正从传统职能管理与管控&#xff0c;向紧贴业务战略实现、组织边界和人…...

工业缺陷检测数据及代码(附代码)

介绍 目前,基于机器视觉的表面缺陷检测设备已广泛取代人工视觉检测,在包括3C、汽车、家电、机械制造、半导体与电子、化工、制药、航空航天、轻工等多个行业领域得到应用。传统的基于机器视觉的表面缺陷检测方法通常采用常规图像处理算法或人工设计的特征加分类器。一般而言…...

CentOS 安装MongoDB 6.0

一、安装依赖 yum install libcurl openssl xz-libs 二、下载安装包 安装包下载地址https://www.mongodb.com/try/download/community这里我选择的是 选择RedHat / CentOS 7.0平台的原因是我的操作系统使用的是CentOS 7.0的&#xff0c;需要下载与操作系统匹配的安装包 三、…...

在软件开发中正确使用MySQL日期时间类型的深度解析

在日常软件开发场景中&#xff0c;时间信息的存储是底层且核心的需求。从金融交易的精确记账时间、用户操作的行为日志&#xff0c;到供应链系统的物流节点时间戳&#xff0c;时间数据的准确性直接决定业务逻辑的可靠性。MySQL作为主流关系型数据库&#xff0c;其日期时间类型的…...

应用升级/灾备测试时使用guarantee 闪回点迅速回退

1.场景 应用要升级,当升级失败时,数据库回退到升级前. 要测试系统,测试完成后,数据库要回退到测试前。 相对于RMAN恢复需要很长时间&#xff0c; 数据库闪回只需要几分钟。 2.技术实现 数据库设置 2个db_recovery参数 创建guarantee闪回点&#xff0c;不需要开启数据库闪回。…...

golang循环变量捕获问题​​

在 Go 语言中&#xff0c;当在循环中启动协程&#xff08;goroutine&#xff09;时&#xff0c;如果在协程闭包中直接引用循环变量&#xff0c;可能会遇到一个常见的陷阱 - ​​循环变量捕获问题​​。让我详细解释一下&#xff1a; 问题背景 看这个代码片段&#xff1a; fo…...

Java 加密常用的各种算法及其选择

在数字化时代&#xff0c;数据安全至关重要&#xff0c;Java 作为广泛应用的编程语言&#xff0c;提供了丰富的加密算法来保障数据的保密性、完整性和真实性。了解这些常用加密算法及其适用场景&#xff0c;有助于开发者在不同的业务需求中做出正确的选择。​ 一、对称加密算法…...

TRS收益互换:跨境资本流动的金融创新工具与系统化解决方案

一、TRS收益互换的本质与业务逻辑 &#xff08;一&#xff09;概念解析 TRS&#xff08;Total Return Swap&#xff09;收益互换是一种金融衍生工具&#xff0c;指交易双方约定在未来一定期限内&#xff0c;基于特定资产或指数的表现进行现金流交换的协议。其核心特征包括&am…...

GruntJS-前端自动化任务运行器从入门到实战

Grunt 完全指南&#xff1a;从入门到实战 一、Grunt 是什么&#xff1f; Grunt是一个基于 Node.js 的前端自动化任务运行器&#xff0c;主要用于自动化执行项目开发中重复性高的任务&#xff0c;例如文件压缩、代码编译、语法检查、单元测试、文件合并等。通过配置简洁的任务…...

C++ 设计模式 《小明的奶茶加料风波》

&#x1f468;‍&#x1f393; 模式名称&#xff1a;装饰器模式&#xff08;Decorator Pattern&#xff09; &#x1f466; 小明最近上线了校园奶茶配送功能&#xff0c;业务火爆&#xff0c;大家都在加料&#xff1a; 有的同学要加波霸 &#x1f7e4;&#xff0c;有的要加椰果…...

LangFlow技术架构分析

&#x1f527; LangFlow 的可视化技术栈 前端节点编辑器 底层框架&#xff1a;基于 &#xff08;一个现代化的 React 节点绘图库&#xff09; 功能&#xff1a; 拖拽式构建 LangGraph 状态机 实时连线定义节点依赖关系 可视化调试循环和分支逻辑 与 LangGraph 的深…...

消息队列系统设计与实践全解析

文章目录 &#x1f680; 消息队列系统设计与实践全解析&#x1f50d; 一、消息队列选型1.1 业务场景匹配矩阵1.2 吞吐量/延迟/可靠性权衡&#x1f4a1; 权衡决策框架 1.3 运维复杂度评估&#x1f527; 运维成本降低策略 &#x1f3d7;️ 二、典型架构设计2.1 分布式事务最终一致…...

【技巧】dify前端源代码修改第一弹-增加tab页

回到目录 【技巧】dify前端源代码修改第一弹-增加tab页 尝试修改dify的前端源代码&#xff0c;在知识库增加一个tab页"HELLO WORLD"&#xff0c;完成后的效果如下 [gif01] 1. 前端代码进入调试模式 参考 【部署】win10的wsl环境下启动dify的web前端服务 启动调试…...