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

为了减轻项目的中间件臃肿,由于我们项目本身就应用了 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.mfbz.cn/a/152130.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

linux之shell

一、是什么 Shell是一个由c语言编写的应用程序&#xff0c;它是用户使用 Linux 的桥梁。Shell 既是一种命令语言&#xff0c;又是一种程序设计语言 它连接了用户和Linux内核&#xff0c;让用户能够更加高效、安全、低成本地使用 Linux 内核 其本身并不是内核的一部分&#x…

Java实现自定义windows右键菜单

要添加Java应用程序到Windows桌面的右键菜单&#xff0c;可以按照以下步骤操作&#xff1a; 创建一个新的.reg文件&#xff0c;并在文本编辑器中打开它。 添加以下代码到.reg文件中&#xff0c;将名称和路径替换为您的Java应用程序的名称和路径。 Windows Registry Editor V…

虚拟化热添加技术在数据备份上的应用

虚拟化中的热添加技术主要是指&#xff1a;无需停止或中断虚拟机的情况下&#xff0c;在线添加物理资源&#xff08;如硬盘、内存、CPU、网卡等&#xff09;的技术。热添加技术也是相比物理机一个非常巨大的优势&#xff0c;其使得资源分配变得更加灵活。 虚拟化中的热添加技术…

SOP作业指导书系统如何帮助厂家实现数字化转型

SOP&#xff08;Standard Operating Procedure&#xff0c;标准操作程序&#xff09;电子作业操作手册的应用对于厂家实现数字化转型起着至关重要的作用。本文将探讨SOP电子作业操作手册如何帮助厂家实现数字化转型的重要性和优势。 首先&#xff0c;SOP作业指导书可以提高生产…

idea菜单栏任务栏放缩比例修改

在编辑自定义VM选项中增加 -Dide.ui.scale0.8 参数 Help -> Edit Custom VM Options

这家提供数据闭环完整链路的企业,已拿下多家头部主机厂定点

“BEV感知数据闭环”已经成为新一代自动驾驶系统的核心架构。 进入2023年&#xff0c;小鹏、理想、阿维塔、智己、华为问界等汽车品牌正在全力推动从高速NOA到城区NOA的升级。在这一过程当中&#xff0c;如何利用高效的算力支撑、完善的算法模型、大量有效的数据形成闭环&…

Ubuntu部署OpenStack踩坑指南:还要看系统版本?

正文共&#xff1a;1515 字 12 图&#xff0c;预估阅读时间&#xff1a;2 分钟 到目前为止&#xff0c;我对OpenStack还不太了解&#xff0c;只知道OpenStack本身是一个云管理平台&#xff08;什么是OpenStack&#xff1f;&#xff09;。那作为云管理平台&#xff0c;我能想到最…

解决网络编程中的EOF违反协议问题:requests库与SSL错误案例分析

1. 问题背景 近期&#xff0c;一个用户在使用requests库进行网络编程时遭遇到了一个不寻常的问题&#xff0c;涉及SSL错误&#xff0c;并提示错误消息为SSLError(SSLEOFError(8, uEOF occurred in violation of protocol (_ssl.c:661)),))。该用户表示已经采取了多种方法来解决…

【深度学习实验】网络优化与正则化(五):数据预处理详解——标准化、归一化、白化、去除异常值、处理缺失值

文章目录 一、实验介绍二、实验环境1. 配置虚拟环境2. 库版本介绍 三、优化算法0. 导入必要的库1. 随机梯度下降SGD算法a. PyTorch中的SGD优化器b. 使用SGD优化器的前馈神经网络 2.随机梯度下降的改进方法a. 学习率调整b. 梯度估计修正 3. 梯度估计修正&#xff1a;动量法Momen…

【文件包含】phpmyadmin 文件包含(CVE-2014-8959)

1.1漏洞描述 漏洞编号CVE-2014-8959漏洞类型文件包含漏洞等级高危漏洞环境Windows漏洞名称phpmyadmin 文件包含&#xff08;CVE-2014-8959&#xff09; 描述: phpMyAdmin是一套开源的、基于Web的MySQL数据库管理工具。其index.php中存在一处文件包含逻辑&#xff0c;通过二次编…

通过maven命令手动上传jar私服Nexus

Nexus3在界面上传组件时报&#xff1a; Ext.JSON.decode(): Youre trying to decode an invalid JSON String: 查找了很多资料&#xff0c;都没有解决。有哪位大佬知道的评论告诉一下&#xff0c;万分感谢。 于是换成maven命令上传&#xff1a; mvn deploy:deploy-file -Dgr…

promise时效架构升级方案的实施及落地 | 京东物流技术团队

一、项目背景 为什么需要架构升级 promise时效包含两个子系统&#xff1a;内核时效计算系统&#xff08;系统核心是时效计算&#xff09;和组件化时效系统&#xff08;系统核心是复杂业务处理以及多种时效业务聚合&#xff0c;承接结算下单黄金流程流量&#xff09;&#xff…

Google codelab WebGPU入门教程源码<4> - 使用Uniform类型对象给着色器传数据(源码)

对应的教程文章: https://codelabs.developers.google.com/your-first-webgpu-app?hlzh-cn#5 对应的源码执行效果: 对应的教程源码: 此处源码和教程本身提供的部分代码可能存在一点差异。 class Color4 {r: number;g: number;b: number;a: number;constructor(pr 1.0, …

FactoryIO 分拣仿真博图实现

FC_LightSygnalization FC_Manual Forward Backward

虚幻C++ day5

角色状态的常见机制 创建角色状态设置到UI上 在MainPlayer.h中新建血量&#xff0c;最大血量&#xff0c;耐力&#xff0c;最大耐力&#xff0c;金币变量&#xff0c;作为角色的状态 //主角状态UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category "Playe Stats&…

最新PS 2024 虎标正式版来啦,附带AI神经滤镜(支持win/mac)

软件简介 文件名称 PS2024 虎标正式版 支持系统 windows、Mac 获取方式 文章底部 分享形式 百度网盘 小伙伴们&#xff0c;下午好&#xff01;今天给大家的是PS 2024 25.0虎标正式版。 PS 2024 25.0 正式版介绍 经历了多次Photoshop 2023 Beta 测试之后&#xff0c;今天…

01.智慧商城——项目介绍与初始化

智慧商城 - 授课大纲 接口文档&#xff1a;https://apifox.com/apidoc/shared-12ab6b18-adc2-444c-ad11-0e60f5693f66/doc-2221080 演示地址&#xff1a;http://cba.itlike.com/public/mweb/#/ 01. 项目功能演示 1.明确功能模块 启动准备好的代码&#xff0c;演示移动端面…

Mahony 滤波算法参数自动调节方法 11

Mahony 滤波算法参数自动调节方法 1. 基于无阻尼自由频率设计设置Kp、Ki参数[^1]2.基于时间常数设置Kp&#xff0c; Ki参数[^2][^3] 1. 基于无阻尼自由频率设计设置Kp、Ki参数1 2.基于时间常数设置Kp&#xff0c; Ki参数23 Gain-Scheduled Complementary Filter Design for a M…

Vue3:给表格的单元格增加超链接功能(点击单元格可以跳转到新的页面)

一、目的 在Vue3项目中&#xff0c;给表格某个字段下的全部单元格添加超链接功能&#xff0c;点击对应的单元格可以进入对应的页面 二、定义单元格内容 使用ElementPlus的el-table组件来实现表格 1、代码 <template> <el-table :data"dataAll"> &…

成都瀚网科技有限公司抖音带货正规么

近年来&#xff0c;随着抖音等短视频平台的兴起&#xff0c;越来越多的企业和个人选择在抖音上进行带货。成都瀚网科技有限公司&#xff08;以下简称瀚网科技&#xff09;也提供抖音带货服务&#xff0c;那么&#xff0c;瀚网科技的抖音带货正规吗&#xff1f; 首先&#xff0c…