Redis - 订阅发布替换 Etcd 解决方案

news2025/2/26 2:25:09

为了减轻项目的中间件臃肿,由于我们项目本身就应用了 Redis,正好 Redis 的也具备订阅发布监听的特性,正好应对 Etcd 的功能,所以本次给大家讲解如何使用 Redis 消息订阅发布来替代 Etcd 的解决方案。接下来,我们先看 Redis 订阅发布的常见情景……

Redis 订阅发布公共类

RedisConfig.java
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import java.net.UnknownHostException;

@Configuration
@ComponentScan({"cn.hutool.extra.spring"})
public class RedisConfig {

    @Bean
    RedisMessageListenerContainer container (RedisConnectionFactory redisConnectionFactory){
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(redisConnectionFactory);
        return  container;
    }
    
    @Bean
    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) throws UnknownHostException {
        RedisTemplate<String, Object> template = new RedisTemplate();
        // 连接工厂
        template.setConnectionFactory(redisConnectionFactory);
        // 序列化配置
        Jackson2JsonRedisSerializer objectJackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
        objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
        objectJackson2JsonRedisSerializer.setObjectMapper(objectMapper);
        StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
        // 配置具体序列化
        // key采用string的序列化方式
        template.setKeySerializer(stringRedisSerializer);
        // hash的key采用string的序列化方式
        template.setHashKeySerializer(stringRedisSerializer);
        // value序列化采用jackson
        template.setValueSerializer(objectJackson2JsonRedisSerializer);
        // hash的value序列化采用jackson
        template.setHashValueSerializer(objectJackson2JsonRedisSerializer);
        template.afterPropertiesSet();
        return template;
    }
}
RedisUtil.java
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;

@Slf4j
@Component
public class RedisUtil {

    @Resource
    private RedisTemplate redisTemplate;
    /**
     * 消息发送
     * @param topic 主题
     * @param message 消息
     */
    public void publish(String topic, String message) {
        redisTemplate.convertAndSend(topic, message);
    }
}
application.yml
server:
  port: 7077
spring:
  application:
    name: redis-demo
  redis:
    host: localhost
    timeout: 3000
    jedis:
      pool:
        max-active: 300
        max-idle: 100
        max-wait: 10000
    port: 6379
RedisController.java
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

/**
 * @author Lux Sun
 * @date 2023/9/12
 */
@RestController
@RequestMapping("/redis")
public class RedisController {

    @Resource
    private RedisUtil redisUtil;
    
    @PostMapping
    public String publish(@RequestParam String topic, @RequestParam String msg) {
       redisUtil.publish(topic, msg);
       return "发送成功: " + topic + " - " + msg;
    }
}

一、业务情景:1 个消费者监听 1 个 Topic

教程三步走(下文业务情景类似不再描述)
  1. 实现接口 MessageListener
  2. 消息订阅,绑定业务 Topic
  3. 重写 onMessage 消费者业务方法
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;

@Slf4j
@Component
public class RedisReceiver1 implements MessageListener {

    @Resource
    private RedisMessageListenerContainer container;

    /**
     * 重点关注这方法, 进行消息订阅
     */
    @PostConstruct
    public void init() {
        MessageListenerAdapter adapter = new MessageListenerAdapter(this);
        // 绑定 Topic 语法为正则表达式
        container.addMessageListener(adapter, new PatternTopic("topic1.*"));
    }

    @Override
    public void onMessage(Message message, byte[] bytes) {
        String key = new String(message.getChannel());
        String value = new String(message.getBody());
        log.info("Key: {}", key);
        log.info("Value: {}", value);
    }
}
测试
curl --location '127.0.0.1:7077/redis' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'topic=topic1.msg' \
--data-urlencode 'msg=我是消息1'
结果
2023-11-15 10:22:38.445  INFO 59189 --- [    container-2] com.xxx.redis.demo.RedisReceiver1  : Key: topic1.msg
2023-11-15 10:22:38.445  INFO 59189 --- [    container-2] com.xxx.redis.demo.RedisReceiver1  : Value: "我是消息1"

二、业务情景:1 个消费者监听 N 个 Topic

import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;

@Slf4j
@Component
public class RedisReceiver1 implements MessageListener {

    @Resource
    private RedisMessageListenerContainer container;

    /**
     * 重点关注这方法, 进行消息订阅
     */
    @PostConstruct
    public void init() {
        MessageListenerAdapter adapter = new MessageListenerAdapter(this);
        // 绑定 Topic 语法为正则表达式
        container.addMessageListener(adapter, new PatternTopic("topic1.*"));
        // 只需再绑定业务 Topic 即可
        container.addMessageListener(adapter, new PatternTopic("topic2.*"));
    }

    @Override
    public void onMessage(Message message, byte[] bytes) {
        String key = new String(message.getChannel());
        String value = new String(message.getBody());
        log.info("Key: {}", key);
        log.info("Value: {}", value);
    }
}
测试
curl --location '127.0.0.1:7077/redis' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'topic=topic2.msg' \
--data-urlencode 'msg=我是消息2'
结果
2023-11-15 10:22:38.445  INFO 59189 --- [    container-2] com.xxx.redis.demo.RedisReceiver1  : Key: topic2.msg
2023-11-15 10:22:38.445  INFO 59189 --- [    container-2] com.xxx.redis.demo.RedisReceiver1  : Value: "我是消息2"

三、业务情景:N 个消费者监听 1 个 Topic

我们看一下,现在又新增一个 RedisReceiver2,按理讲测试的时候,RedisReceiver1 和 RedisReceiver2 会同时收到消息

import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;

@Slf4j
@Component
public class RedisReceiver2 implements MessageListener {

    @Resource
    private RedisMessageListenerContainer container;

    /**
     * 重点关注这方法, 进行消息订阅
     */
    @PostConstruct
    public void init() {
        MessageListenerAdapter adapter = new MessageListenerAdapter(this);
        // 绑定 Topic 语法为正则表达式
        container.addMessageListener(adapter, new PatternTopic("topic1.*"));
    }

    @Override
    public void onMessage(Message message, byte[] bytes) {
        String key = new String(message.getChannel());
        String value = new String(message.getBody());
        log.info("Key: {}", key);
        log.info("Value: {}", value);
    }
}
测试
curl --location '127.0.0.1:7077/redis' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'topic=topic1.msg' \
--data-urlencode 'msg=我是消息1'
结果
2023-11-15 10:22:38.445  INFO 59189 --- [    container-2] com.xxx.redis.demo.RedisReceiver1  : Key: topic1.msg
2023-11-15 10:22:38.449  INFO 59189 --- [    container-3] com.xxx.redis.demo.RedisReceiver2  : Key: topic1.msg
2023-11-15 10:22:38.545  INFO 59189 --- [    container-2] com.xxx.redis.demo.RedisReceiver1  : Value: "我是消息1"
2023-11-15 10:22:38.645  INFO 59189 --- [    container-3] com.xxx.redis.demo.RedisReceiver2  : Value: "我是消息1"

四、业务情景:N 个消费者监听 N 个 Topic

都到这阶段了,应该不难理解了吧~

import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;

@Slf4j
@Component
public class RedisReceiver2 implements MessageListener {

    @Resource
    private RedisMessageListenerContainer container;

    /**
     * 重点关注这方法, 进行消息订阅
     */
    @PostConstruct
    public void init() {
        MessageListenerAdapter adapter = new MessageListenerAdapter(this);
        // 绑定 Topic 语法为正则表达式
        container.addMessageListener(adapter, new PatternTopic("topic1.*"));
        // 只需再绑定业务 Topic 即可
        container.addMessageListener(adapter, new PatternTopic("topic2.*"));
    }

    @Override
    public void onMessage(Message message, byte[] bytes) {
        String key = new String(message.getChannel());
        String value = new String(message.getBody());
        log.info("Key: {}", key);
        log.info("Value: {}", value);
    }
}
测试
curl --location '127.0.0.1:7077/redis' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'topic=topic2.msg' \
--data-urlencode 'msg=我是消息2'
结果
2023-11-15 10:22:38.445  INFO 59189 --- [    container-2] com.xxx.redis.demo.RedisReceiver1  : Key: topic2.msg
2023-11-15 10:22:38.449  INFO 59189 --- [    container-3] com.xxx.redis.demo.RedisReceiver2  : Key: topic2.msg
2023-11-15 10:22:38.545  INFO 59189 --- [    container-2] com.xxx.redis.demo.RedisReceiver1  : Value: "我是消息2"
2023-11-15 10:22:38.645  INFO 59189 --- [    container-3] com.xxx.redis.demo.RedisReceiver2  : Value: "我是消息2"

好了,Redis 订阅发布的教程到此为止。接下来,我们看下如何用它来替代 Etcd 的业务情景?

这之前,我们先大概聊下 Etcd 的 2 个要点:

  1. Etcd 消息事件类型
  2. Etcd 持久层数据

那么问题来了,Redis 虽然具备基本的消息订阅发布,但是如何契合 Etcd 的这 2 点特性,我们目前给出对应的解决方案是:

  1. 使用 Redis K-V 的 value 作为 Etcd 消息事件类型
  2. 使用 MySQL 作为 Etcd 持久层数据:字段 id 随机 UUID、字段 key 对应 Etcd key、字段 value 对应 Etcd value,这样做的一个好处是无需重构数据结构
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;


DROP TABLE IF EXISTS `t_redis_msg`;
CREATE TABLE `t_redis_msg` (
`id` varchar(32) NOT NULL,
`key` varchar(255) NOT NULL,
`value` longtext,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;


SET FOREIGN_KEY_CHECKS = 1;

所以,如果想平替 Etcd 的事件类型和持久层数据的解决方案需要 MySQL & Redis 结合,接下来直接上代码……

Redis & MySQL 整合

application.yml(升级)
spring:
  application:
    name: redis-demo
  datasource:
    username: root
    password: 123456
    url: jdbc:mysql://localhost:3306/db_demo?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
    driver-class-name: com.mysql.cj.jdbc.Driver
    hikari:
      connection-test-query: SELECT 1
      idle-timeout: 40000
      max-lifetime: 1880000
      connection-timeout: 40000
      minimum-idle: 1
      validation-timeout: 60000
      maximum-pool-size: 20
RedisMsg.java
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 lombok.experimental.SuperBuilder;

/**
 * @author Lux Sun
 * @date 2021/2/19
 */
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@TableName(value = "t_redis_msg", autoResultMap = true)
public class RedisMsg {

    @TableId(type = IdType.ASSIGN_UUID)
    private String id;
    
    @TableField(value = "`key`")
    private String key;
    
    private String value;
}
RedisMsgEnum.java
/**
 * @author Lux Sun
 * @date 2022/11/11
 */
public enum RedisMsgEnum {
    PUT("PUT"),
    DEL("DEL");

    private String code;

    RedisMsgEnum(String code) {
       this.code = code;
    }

    public String getCode() {
       return code;
    }

}
RedisMsgService.java
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
import java.util.Map;

/**
 * @author Lux Sun
 * @date 2020/6/16
 */
public interface RedisMsgService extends IService<RedisMsg> {

    /**
     * 获取消息
     * @param key
     */
    RedisMsg get(String key);

    /**
     * 获取消息列表
     * @param key
     */
    Map<String, String> map(String key);

    /**
     * 获取消息值
     * @param key
     */
    String getValue(String key);

    /**
     * 获取消息列表
     * @param key
     */
    List<RedisMsg> list(String key);

    /**
     * 插入消息
     * @param key
     * @param value
     */
    void put(String key, String value);

    /**
     * 删除消息
     * @param key
     */
    void del(String key);
}
RedisMsgServiceImpl.java
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author Lux Sun
 * @date 2020/6/16
 */
@Slf4j
@Service
public class RedisMsgServiceImpl extends ServiceImpl<RedisMsgDao, RedisMsg> implements RedisMsgService {

    @Resource
    private RedisMsgDao redisMsgDao;

    @Resource
    private RedisUtil redisUtil;

    /**
     * 获取消息
     *
     * @param key
     */
    @Override
    public RedisMsg get(String key) {
        LambdaQueryWrapper<RedisMsg> lqw = new LambdaQueryWrapper<>();
        lqw.eq(RedisMsg::getKey, key);
        return redisMsgDao.selectOne(lqw);
    }

    /**
     * 获取消息列表
     *
     * @param key
     */
    @Override
    public Map<String, String> map(String key) {
        List<RedisMsg> redisMsgs = this.list(key);
        return redisMsgs.stream().collect(Collectors.toMap(RedisMsg::getKey, RedisMsg::getValue));
    }

    /**
     * 获取消息值
     *
     * @param key
     */
    @Override
    public String getValue(String key) {
        RedisMsg redisMsg = this.get(key);
        return redisMsg.getValue();
    }

    /**
     * 获取消息列表
     *
     * @param key
     */
    @Override
    public List<RedisMsg> list(String key) {
        LambdaQueryWrapper<RedisMsg> lqw = new LambdaQueryWrapper<>();
        lqw.likeRight(RedisMsg::getKey, key);
        return redisMsgDao.selectList(lqw);
    }

    /**
     * 插入消息
     *
     * @param key
     * @param value
     */
    @Override
    public void put(String key, String value) {
        log.info("开始添加 - key: {},value: {}", key, value);
        LambdaQueryWrapper<RedisMsg> lqw = new LambdaQueryWrapper<>();
        lqw.eq(RedisMsg::getKey, key);
        this.saveOrUpdate(RedisMsg.builder().key(key).value(value).build(), lqw);
        redisUtil.putMsg(key);
        log.info("添加成功 - key: {},value: {}", key, value);
    }

    /**
     * 删除消息
     *
     * @param key
     */
    @Override
    public void del(String key) {
        log.info("开始删除 - key: {}", key);
        LambdaQueryWrapper<RedisMsg> lqw = new LambdaQueryWrapper<>();
        lqw.likeRight(RedisMsg::getKey, key);
        redisMsgDao.delete(lqw);
        redisUtil.delMsg(key);
        log.info("删除成功 - key: {}", key);
    }
}
RedisUtil.java(升级)
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;

@Slf4j
@Component
public class RedisUtil {

    @Resource
    private RedisTemplate redisTemplate;

    /**
     * 消息发送
     * @param topic 主题
     * @param message 消息
     */
    public void publish(String topic, String message) {
        redisTemplate.convertAndSend(topic, message);
    }

    /**
     * 消息发送 PUT
     * @param topic 主题
     */
    public void putMsg(String topic) {
        redisTemplate.convertAndSend(topic, RedisMsgEnum.PUT);
    }

    /**
     * 消息发送 DELETE
     * @param topic 主题
     */
    public void delMsg(String topic) {
        redisTemplate.convertAndSend(topic, RedisMsgEnum.DEL);
    }
}

演示 DEMO

RedisMsgController.java
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

/**
 * @author Lux Sun
 * @date 2023/9/12
 */
@RestController
@RequestMapping("/redisMsg")
public class RedisMsgController {

    @Resource
    private RedisMsgService redisMsgService;

    @PostMapping
    public String publish(@RequestParam String topic, @RequestParam String msg) {
       redisMsgService.put(topic, msg);
       return "发送成功: " + topic + " - " + msg;
    }
}
RedisMsgReceiver.java
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;

@Slf4j
@Component
public class RedisMsgReceiver implements MessageListener {

    @Resource
    private RedisMsgService redisMsgService;

    @Resource
    private RedisMessageListenerContainer container;

    @PostConstruct
    public void init() {
        MessageListenerAdapter adapter = new MessageListenerAdapter(this);
        container.addMessageListener(adapter, new PatternTopic("topic3.*"));
    }

    @Override
    public void onMessage(Message message, byte[] bytes) {
        String key = new String(message.getChannel());
        String event = new String(message.getBody());
        String value = redisMsgService.getValue(key);
        log.info("Key: {}", key);
        log.info("Event: {}", event);
        log.info("Value: {}", value);
    }
}
测试
curl --location '127.0.0.1:7077/redisMsg' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'topic=topic3.msg' \
--data-urlencode 'msg=我是消息3'
结果
2023-11-16 10:24:35.721  INFO 43794 --- [nio-7077-exec-1] c.c.redis.demo.RedisMsgServiceImpl       : 开始添加 - key: topic3.msg,value: 我是消息3
2023-11-16 10:24:35.935  INFO 43794 --- [nio-7077-exec-1] c.c.redis.demo.RedisMsgServiceImpl       : 添加成功 - key: topic3.msg,value: 我是消息3
2023-11-16 10:24:35.950  INFO 43794 --- [    container-2] c.xxx.redis.demo.RedisMsgReceiver  : Key: topic3.msg
2023-11-16 10:24:35.950  INFO 43794 --- [    container-2] c.xxx.redis.demo.RedisMsgReceiver  : Event: "PUT"
2023-11-16 10:24:35.950  INFO 43794 --- [    container-2] c.xxx.redis.demo.RedisMsgReceiver  : Value: 我是消息3

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

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

相关文章

解决Python Requests库中处理重定向时的多重Cookie问题

问题背景 在更新至f73bda06e9版本后&#xff0c;用户发现某些请求会引发CookieConflictError。具体来说&#xff0c;任何设置饼干且重定向到设置相同饼干的页面的请求都会引发CookieConflictError。 重现步骤 1、更新Requests至上述版本。 2、从中国以外的任何地方向baidu…

Java 设计模式——中介者模式

目录 1.概述2.结构3.案例实现3.1.抽象中介类3.2.抽象同事类3.3.具体同事类3.4.具体中介类3.5.测试 4.优缺点5.使用场景 1.概述 &#xff08;1&#xff09;一般来说&#xff0c;同事类之间的关系是比较复杂的&#xff0c;多个同事类之间互相关联时&#xff0c;他们之间的关系会…

Redis最新2023年面试题高级面试题及附答案解析(2)【Redis最新2023年面试题高级面试题及附答案解析-第三十九刊】

文章目录 Redis最新2023年面试题高级面试题及附答案解析(2)01、Redis 集群方案应该怎么做&#xff1f;都有哪些方案&#xff1f;02、Redis 的内存用完了会发生什么&#xff1f;03、怎么测试 Redis 的连通性&#xff1f;04、Redis 集群会有写操作丢失吗&#xff1f;为什么&#…

C/C++ 实现获取硬盘序列号

获取硬盘的序列号、型号和固件版本号&#xff0c;此类功能通常用于做硬盘绑定或硬件验证操作&#xff0c;通过使用Windows API的DeviceIoControl函数与物理硬盘驱动程序进行通信&#xff0c;发送ATA命令来获取硬盘的信息。 以下是该程序的主要功能和流程&#xff1a; 定义常量…

青年作家考公引热议,体制内可能不是你想的那样

点击文末“阅读原文”即可参与节目互动 剪辑、音频 / 阿福 运营 / SandLiu 卷圈 监制 / 姝琦 封面 / 姝琦Midjourney 产品统筹 / bobo 场地支持 / 声湃轩天津录音间 最近&#xff0c;班宇、陈春成、王苏辛三名青年作家出现在了武汉市文联所属事业单位专项招聘拟聘用人员名…

如何有效防止公司内部的信息泄露?

信息泄露对公司可能带来严重影响&#xff0c;因此采取一系列措施以确保信息安全至关重要。以下是一些建议&#xff1a; 部署综合的防泄密软件&#xff1a; 在公司内部&#xff0c;使用专业的防泄密软件如华企盾DSC系统&#xff0c;涵盖文件加密、U盘管控、桌面行为管理、日志审…

前端 react 面试题 (一)

文章目录 vue与react的区别。react的生命周期有哪些及它们的作用。setState是同步的还是异步的。如何更新数据后&#xff0c;立刻获取最新的dom或者更新后的数据。使用回调函数&#xff1a;在生命周期方法中处理&#xff1a; 函数式组件和class组件的区别。class组件函数式组件…

浏览器怎么更新?4个高效设置方法!

“我在使用浏览器时&#xff0c;有时候会提示说浏览器版本太低&#xff0c;需要更新后才能使用。有什么方法可以更新浏览器呢&#xff1f;快给我支支招吧&#xff01;” 在快速发展的科技时代&#xff0c;浏览器更新是确保网络安全和性能优化的关键步骤。如果浏览器的版本太低&…

windows系统下修改nginx配置后reload重加载后不生效解决方案

windows系统下修改nginx配置后reload重加载后不生效解决方案 1、Nginx配置在重启&#xff08;reload&#xff09;后也不生效的原因2、通过服务启动的Nginx&#xff0c;通过stop命令是关闭不了的&#xff1a;(Access is denied)。 1、Nginx配置在重启&#xff08;reload&#xf…

大语言模型量化方法对比:GPTQ、GGUF、AWQ

在过去的一年里&#xff0c;大型语言模型(llm)有了飞速的发展&#xff0c;在本文中&#xff0c;我们将探讨几种(量化)的方式&#xff0c;除此以外&#xff0c;还会介绍分片及不同的保存和压缩策略。 说明&#xff1a;每次加载LLM示例后&#xff0c;建议清除缓存&#xff0c;以…

前端跨界面之间的通信解决方案

主要是这两个方案&#xff0c;其他的&#xff0c;还有 SharedWorker 、IndexedDB、WebSocket、Service Worker 如果是&#xff0c;父子嵌套 iframe 还可以使用 window.parent.postMessage(“需要传递的参数”, ‘*’) 1、localStorage 核心点 同源&#xff0c;不能跨域(协议、端…

9.MyBatis-Plus

1、前期准备 a. 创建数据库 CREATE TABLE USER (id BIGINT(20)NOT NULL COMMENT 主键ID,NAME VARCHAR(30)NULL DEFAULT NULL COMMENT 姓名,age INT(11)NULL DEFAULT NULL COMMENT 年龄,email VARCHAR(50)NULL DEFAULT NULL COMMENT 邮箱,PRIMARY KEY (id) );INSERT INTO user…

短路语法 [SUCTF 2019]EasySQL1

打开题目 输入字符的时候啥也不回显。只有输入数字的时候页面有回显 但是当我们输入union&#xff0c;from&#xff0c;sleep&#xff0c;where&#xff0c;order等&#xff0c;页面回显nonono&#xff0c;很明显过滤了这些关键词 最开始我的思路是打算尝试双写绕过 1;ununion…

TS-08-A-2D、TS-08-B-1H插装式电磁比例溢流阀放大器

TS-08-A-2D、TS-08-B-1H插装式电磁比例溢流阀放大器持续的电磁铁、高效能的电磁铁结构、可选的线圈电压和终端、工业化通用插孔、紧凑的结构。 螺纹插装式、先导滑阀式减压溢流阀&#xff0c;利用可变电流输入可实现指定范围内的输出压力连续调节。输出压力与 DC 电流输入成比…

[Jenkins] 物理机 安装 Jenkins

这里介绍Linux CentOS系统直接Yum 安装 Jenkins&#xff0c;不同系统之间类似&#xff0c;操作命令差异&#xff0c;如&#xff1a;Ubuntu用apt&#xff1b; 0、安装 Jenkins Jenkins是一个基于Java语言开发的持续构建工具平台&#xff0c;主要用于持续、自动的构建/测试你的软…

Linux学习教程(第三章 Linux文件和目录管理)1

第三章 Linux文件和目录管理&#xff08;初识Linux命令&#xff09; 对初学者来说&#xff0c;管理 Linux 系统中的文件和目录&#xff0c;是学习 Linux 至关重要的一步。 为了方便管理文件和目录&#xff0c;Linux 系统将它们组织成一个以根目录 / 开始的倒置的树状结构。Li…

【架构师】的修炼之道都需要学习哪些?看看这些就够了

&#x1f468;‍&#x1f393;博主简介 &#x1f3c5;云计算领域优质创作者   &#x1f3c5;华为云开发者社区专家博主   &#x1f3c5;阿里云开发者社区专家博主 &#x1f48a;交流社区&#xff1a;运维交流社区 欢迎大家的加入&#xff01; &#x1f40b; 希望大家多多支…

代码随想录图论|130. 被围绕的区域 417太平洋大西洋水流问题

130. 被围绕的区域 **题目&#xff1a;**给你一个 m x n 的矩阵 board &#xff0c;由若干字符 ‘X’ 和 ‘O’ &#xff0c;找到所有被 ‘X’ 围绕的区域&#xff0c;并将这些区域里所有的 ‘O’ 用 ‘X’ 填充。 题目链接&#xff1a;130. 被围绕的区域 解题思路&#xff1a…

《向量数据库指南》——2023云栖大会现场,向量数据库Milvus Cloud成关注焦点

近期,广受关注的2023 云栖大会正式收官,来自全球各地的开发者集聚一堂,共同探索 AI 时代的更多可能性。 云栖大会是由阿里巴巴集团主办的科技盛宴,是中国最早的开发者创新展示平台。据悉,今年云栖大会的主题为“计算,为了无法计算的价值”,共吸引了全球 44 个国家和地区…

用封面预测书的价格【图像回归】

今天&#xff0c;我将介绍计算机视觉的深度学习应用&#xff0c;用封面简单地估算一本书的价格。 我没有看到很多关于图像回归的文章&#xff0c;所以我为你们写这篇文章。 距离我上一篇文章已经过去很长时间了&#xff0c;我不得不承认&#xff0c;作为一名数据科学家&#x…