Spring boot 整合grpc 运用

news/2024/12/22 10:00:16/

文章目录

    • GRPC基础概念:
    • Protocol Buffers:
      • proto 基础语法:
        • 调用类型:
    • Spring boot 整合 grpc
      • 项目结构:
      • 整合代码:
        • 父 pom
        • proto 模块
        • 服务端:
        • 客户端:
        • 实际调用:
      • 原生集成

GRPC基础概念:

  • GRPC是google开源的一个高性能、跨语言的RPC框架,基于HTTP2协议,基于protobuf 3.x,基于Netty 4.x.

Protocol Buffers:

  • 一个跨语言、跨平台的具有可扩展机制的序列化数据工具。也就是说,我在ubuntu下用python语言序列化一个对象,并使用http协议传输到使用java语言的android客户端,java使用对用的代码工具进行反序列化,也可以得到对应的对象
    1

proto 基础语法:

//指定proto3语法
syntax = "proto3";
//指定作用域
package xxx;
//java_multiple_files = true; 表示在生成Java代码时,每个`.proto`文件都会生成一个独立的Java文件
//声明 rpc 服务接口
//关键字: service 声明需要生成的服务接口"类"
service Greeter {// 关键字: rpc 声明服务方法,包括方法名、请求消息(请求体)、相应消息(响应体)rpc SayHello(HelloRequest) returns (HelloResponse);
}
//声明请求、响应消息
//关键字: message 声明请求体和响应体
message HelloRequest {//标识号 1//编号的范围为1 ~ 536,870,911(2^29-1),其中19000~19999不可用。因为Protobuf协议的实现过程中对预留了这些编号string name = 1;//表示一个人有多个号码repeated string phone = 3;
}message HelloResponse {string message = 1;
}
调用类型:
  • Unary RPC 一元RPC调用,也叫简单RPC调用

    rpc SayHello(HelloRequest) returns (HelloResponse);
    
  • 【服务端 Server Stream RPC】流式RPC. 客户端向服务端发送单个请求,服务端以流的方式返回一系列消息。客户端从流中读取消息,直到没有更多的消息。当然,返回的消息当然不是乱序的,gRPC保证单个请求中的消息顺序

    rpc LotsOfReplies(HelloRequest) returns (stream HelloResponse);
    
  • 【客户端 Client Stream RPC】流式RPC调用。客户端向服务端请求一系列的消息,一旦客户端完成消息写入,就会等待服务端读取所有消息并处理它们。gRPC同样会保证单个请求中消息的顺序性

    rpc LotsOfGreetings(stream HelloRequest) returns (HelloResponse);
    
  • 【双向流式调用 Bidirectional Streaming RPC】就是客户端和服务端均以流的方式进行读写消息。这两个流式完全独立的,因此,服务端和客户端可以按照他们喜欢的方式写入和读取流。比如:服务端可以在等待所有的客户端消息发送到后,再处理;也可以交替读取请求、写入响应信息等。当然,每个流中的消息顺序是可以保证的。

    rpc BidiHello(stream HelloRequest) returns (stream HelloResponse);
    

    Channels通道

    gRPC通道提供了一条链接到指定主机和端口号的服务端的链接。他在创建客户端stub的时候使用。客户端可以指定通道参数来修改gRPC的默认行为,例如:打开或者关闭消息压缩。一个通道是有连接和空闲两个状态的

mvn 插件整合,proto编译,生成代码

<build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><excludes><exclude><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></exclude></excludes></configuration></plugin><!-- 生成插件 --><plugin><groupId>org.xolstice.maven.plugins</groupId><artifactId>protobuf-maven-plugin</artifactId><version>0.6.1</version><configuration><protocArtifact>com.google.protobuf:protoc:3.5.1:exe:${os.detected.classifier}</protocArtifact><pluginId>grpc-java</pluginId><pluginArtifact>io.grpc:protoc-gen-grpc-java:1.11.0:exe:${os.detected.classifier}</pluginArtifact><protoSourceRoot>${project.basedir}/src/main/proto</protoSourceRoot><!--设置grpc生成代码到指定路径--><outputDirectory>${project.basedir}/src/main/java</outputDirectory><!--生成代码前是否清空目录--><clearOutputDirectory>false</clearOutputDirectory></configuration><executions><execution><goals><goal>compile</goal><goal>compile-custom</goal></goals></execution></executions></plugin></plugins><extensions><extension><groupId>kr.motd.maven</groupId><artifactId>os-maven-plugin</artifactId><version>1.6.2</version></extension></extensions></build>

在这里插入图片描述

Spring boot 整合 grpc

大致流程:
1

项目结构:

在这里插入图片描述

整合代码:

父 pom
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.17</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.xiaoshu</groupId><artifactId>grpc-demo</artifactId><version>1.0-SNAPSHOT</version><packaging>pom</packaging><name>grpc-demo</name><modules><module>grpc-server</module><module>grpc-client</module><module>grpc-proto</module></modules><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version><grpc.version>2.15.0.RELEASE</grpc.version></properties><!-- 通用依赖 --><dependencies><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.10</version><scope>provided</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>net.devh</groupId><artifactId>grpc-spring-boot-starter</artifactId><version>${grpc.version}</version><type>pom</type><scope>import</scope></dependency><dependency><groupId>net.devh</groupId><artifactId>grpc-server-spring-boot-starter</artifactId><version>${grpc.version}</version><type>pom</type><scope>import</scope></dependency><dependency><groupId>net.devh</groupId><artifactId>grpc-client-spring-boot-starter</artifactId><version>${grpc.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>
proto 模块
syntax = "proto3";package com.ht.meta;
// 生成类的包名
option java_multiple_files = true;
// 生成代码位置
option java_package = "com.meta";
// 定义的所有消息、枚举和服务生成对应的多个类文件,而不是以内部类的形式出现
option java_outer_classname = "HtMetaInfoSyncProto";service HtMetaInfoSyncService {rpc syncMeta (HtMetaSyncRequest) returns (HtMetaSyncResponse) {}
}//同步类型
enum SyncType {ADD  = 0; // 新增DEL  = 1; // 删除EDIT = 2; // 修改
}//同步Request
message HtMetaSyncRequest {//json内容string syncJson = 1;//同步类型SyncType syncType = 2;
}//响应Response
message HtMetaSyncResponse {//响应码string code = 1;//提示string msg = 2;
}
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>com.xiaoshu</groupId><artifactId>grpc-demo</artifactId><version>1.0-SNAPSHOT</version></parent><artifactId>grpc-proto</artifactId><packaging>jar</packaging><name>grpc-proto</name><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>net.devh</groupId><artifactId>grpc-spring-boot-starter</artifactId><version>${grpc.version}</version></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><excludes><exclude><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></exclude></excludes></configuration></plugin><!-- 生成插件 --><plugin><groupId>org.xolstice.maven.plugins</groupId><artifactId>protobuf-maven-plugin</artifactId><version>0.6.1</version><configuration><protocArtifact>com.google.protobuf:protoc:3.5.1:exe:${os.detected.classifier}</protocArtifact><pluginId>grpc-java</pluginId><pluginArtifact>io.grpc:protoc-gen-grpc-java:1.11.0:exe:${os.detected.classifier}</pluginArtifact><protoSourceRoot>${project.basedir}/src/main/proto</protoSourceRoot><!--设置grpc生成代码到指定路径--><outputDirectory>${project.basedir}/src/main/java</outputDirectory><!--生成代码前是否清空目录--><clearOutputDirectory>false</clearOutputDirectory></configuration><executions><execution><goals><goal>compile</goal><goal>compile-custom</goal></goals></execution></executions></plugin></plugins><extensions><extension><groupId>kr.motd.maven</groupId><artifactId>os-maven-plugin</artifactId><version>1.6.2</version></extension></extensions></build></project>
服务端:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>com.xiaoshu</groupId><artifactId>grpc-demo</artifactId><version>1.0-SNAPSHOT</version></parent><artifactId>grpc-server</artifactId><packaging>jar</packaging><name>grpc-server</name><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>com.xiaoshu</groupId><artifactId>grpc-proto</artifactId><version>1.0-SNAPSHOT</version></dependency><dependency><groupId>net.devh</groupId><artifactId>grpc-server-spring-boot-starter</artifactId><version>${grpc.version}</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.28</version></dependency><!-- fastjson --><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.83</version></dependency></dependencies></project>
server:port: 8080spring:application:name: spring-boot-grpc-server# gRPC有关的配置,这里只需要配置服务端口号
grpc:server:port: 9898

服务端代码:

import com.meta.HtMetaInfoSyncServiceGrpc;
import com.meta.HtMetaSyncRequest;
import com.meta.HtMetaSyncResponse;
import com.meta.SyncType;
import com.util.JsonUtil;
import com.vo.HtMetaClusterInfoVo;
import io.grpc.stub.StreamObserver;
import lombok.extern.slf4j.Slf4j;
import net.devh.boot.grpc.server.service.GrpcService;
import java.util.List;/*** @author 何永豪* @className HtMetaSyncService* @description TODO* @date 2023/11/6 15:25*/
@Slf4j
@GrpcService
public class HtMetaSyncService extends HtMetaInfoSyncServiceGrpc.HtMetaInfoSyncServiceImplBase {@Overridepublic void syncMeta(HtMetaSyncRequest request, StreamObserver<HtMetaSyncResponse> responseObserver) {String syncJson = request.getSyncJson();log.info("接收到json:{}",syncJson);List<HtMetaClusterInfoVo> list = JsonUtil.toList(syncJson, HtMetaClusterInfoVo.class);SyncType syncType = request.getSyncType();int number = syncType.getNumber();log.info("同步类型:{}",number);HtMetaSyncResponse syncResponse = HtMetaSyncResponse.newBuilder().setCode("1000").setMsg("同步成功").build();responseObserver.onNext(syncResponse);responseObserver.onCompleted();}}
客户端:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>com.xiaoshu</groupId><artifactId>grpc-demo</artifactId><version>1.0-SNAPSHOT</version></parent><artifactId>grpc-client</artifactId><packaging>jar</packaging><name>grpc-client</name><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>com.xiaoshu</groupId><artifactId>grpc-proto</artifactId><version>1.0-SNAPSHOT</version></dependency><dependency><groupId>net.devh</groupId><artifactId>grpc-client-spring-boot-starter</artifactId><version>${grpc.version}</version></dependency></dependencies></project>

yml

server:port: 8088spring:application:name: local-clientgrpc:client:# gRPC配置的名字,GrpcClient注解会用到local-grpc-server:# gRPC服务端地址address: 'static://127.0.0.1:9898'enableKeepAlive: truekeepAliveWithoutCalls: true#认证类型,无加密negotiationType: plaintext

客户端stub

import com.meta.HtMetaInfoSyncServiceGrpc;
import com.meta.HtMetaSyncRequest;
import com.meta.HtMetaSyncResponse;
import com.meta.SyncType;
import io.grpc.StatusRuntimeException;
import net.devh.boot.grpc.client.inject.GrpcClient;
import org.springframework.stereotype.Service;/*** @author xiaoshu*/
@Service
public class HtMetaInfoSyncClient {@GrpcClient("local-grpc-server")private HtMetaInfoSyncServiceGrpc.HtMetaInfoSyncServiceBlockingStub stub;public String syncMeta(final String json,final SyncType syncType) {try {HtMetaSyncResponse htMetaSyncResponse = stub.syncMeta((HtMetaSyncRequest.newBuilder().setSyncJson(json).setSyncType(syncType).build()));String code = htMetaSyncResponse.getCode();String msg = htMetaSyncResponse.getMsg();return code+":"+msg;} catch (final StatusRuntimeException e) {return "FAILED with " + e.getStatus().getCode().name();}}}
实际调用:
@Autowired
private HtMetaInfoSyncClient htMetaInfoSyncClient;@RequestMapping("/htMetaSync")
public String htMetaSync() {String json="";return htMetaInfoSyncClient.syncMeta(json, SyncType.ADD);
}

原生集成

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.14</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.xiaoshuzxc</groupId><artifactId>grpc-native-api</artifactId><packaging>jar</packaging><name>grpc-native-api</name><description>grpc原生api整合方式</description><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><grpc.version>1.29.0</grpc.version><proto.version>3.12.0</proto.version><netty.tcnative.version>2.0.30.Final</netty.tcnative.version></properties><dependencyManagement><dependencies><dependency><groupId>io.grpc</groupId><artifactId>grpc-bom</artifactId><version>${grpc.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-configuration-processor</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>com.xiaoshu</groupId><artifactId>grpc-proto</artifactId><version>1.0-SNAPSHOT</version></dependency><dependency><groupId>io.grpc</groupId><artifactId>grpc-protobuf</artifactId></dependency><dependency><groupId>io.grpc</groupId><artifactId>grpc-stub</artifactId></dependency><dependency><groupId>io.grpc</groupId><artifactId>grpc-netty</artifactId></dependency><dependency><groupId>io.netty</groupId><artifactId>netty-tcnative-boringssl-static</artifactId><version>${netty.tcnative.version}</version><scope>runtime</scope></dependency></dependencies>
</project>
import org.springframework.stereotype.Service;
import java.lang.annotation.*;@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Service
public @interface GrpcService {}

启动grpc服务监听:

import com.annotation.GrpcService;
import io.grpc.BindableService;
import io.grpc.Server;
import io.grpc.netty.GrpcSslContexts;
import io.grpc.netty.NettyServerBuilder;
import io.netty.handler.ssl.ClientAuth;
import io.netty.handler.ssl.SslContextBuilder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.Map;
import java.util.stream.Stream;/*** @author 何永豪* @className GrpcServer* @description TODO* @date 2023/11/7 15:56*/
@Slf4j
public class GrpcServer implements CommandLineRunner, DisposableBean {private Server server;@Resourceprivate AbstractApplicationContext applicationContext;@Resourceprivate GrpcProperties grpcProperties;@Overridepublic void destroy() {stop();}@Overridepublic void run(String... args) throws Exception {start();}private SslContextBuilder getSslContextBuilder(){SslContextBuilder sslContextBuilder = SslContextBuilder.forServer(new File(grpcProperties.getServerCertPath()), new File(grpcProperties.getServerPrivateKeyPath()));sslContextBuilder.trustManager(new File(grpcProperties.getServerTrustCertPath()));sslContextBuilder.clientAuth(ClientAuth.REQUIRE);return GrpcSslContexts.configure(sslContextBuilder);}private void start() throws IOException {NettyServerBuilder nettyServerBuilder = NettyServerBuilder.forPort(grpcProperties.getPort());
//                .sslContext(getSslContextBuilder().build()
//                        );scanBeanWithAnnotation(GrpcService.class, BindableService.class).forEach(e->{BindableService bindableService = applicationContext.getBeanFactory().getBean(e, BindableService.class);nettyServerBuilder.addService(bindableService.bindService());});server = nettyServerBuilder.build().start();log.info("grpc start listen {}",grpcProperties.getPort());Thread thread = new Thread(() -> {try {GrpcServer.this.blockUntilShutdown();} catch (InterruptedException e) {log.error("grpc server stopped");throw new RuntimeException(e);}});thread.setDaemon(false);thread.start();}private void stop(){if (server !=null){server.shutdown();}}private void blockUntilShutdown() throws InterruptedException {if (server !=null ){server.awaitTermination();}}private <T> Stream<String> scanBeanWithAnnotation(Class<? extends Annotation> annotionType,Class<T> beanType){String[] beanNamesForType = applicationContext.getBeanNamesForType(beanType);return Stream.of(beanNamesForType).filter(e->{BeanDefinition beanDefinition = applicationContext.getBeanFactory().getBeanDefinition(e);Map<String, Object> beansWithAnnotation = applicationContext.getBeansWithAnnotation(annotionType);if (beansWithAnnotation.containsKey(e)){return true;}else if (beanDefinition.getSource() instanceof AnnotatedTypeMetadata){return AnnotatedTypeMetadata.class.cast(beanDefinition.getSource()).isAnnotated(annotionType.getName());}return false;});}}

服务端:

@Slf4j
@GrpcService
public class HtMetaSyncService extends HtMetaInfoSyncServiceGrpc.HtMetaInfoSyncServiceImplBase {@Overridepublic void syncMeta(HtMetaSyncRequest request, StreamObserver<HtMetaSyncResponse> responseObserver) {String syncJson = request.getSyncJson();log.info("接收到json:{}",syncJson);SyncType syncType = request.getSyncType();int number = syncType.getNumber();log.info("同步类型:{}",number);HtMetaSyncResponse syncResponse = HtMetaSyncResponse.newBuilder().setCode("1000").setMsg("同步成功").build();responseObserver.onNext(syncResponse);responseObserver.onCompleted();}}

客户端

import com.config.GrpcProperties;
import com.meta.HtMetaInfoSyncServiceGrpc;
import com.meta.HtMetaSyncRequest;
import com.meta.HtMetaSyncResponse;
import com.meta.SyncType;
import io.grpc.ManagedChannel;
import io.grpc.StatusRuntimeException;
import io.grpc.netty.NettyChannelBuilder;
import lombok.SneakyThrows;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Objects;/*** @author xiaoshu*/
@Component
public class HtMetaInfoSyncClient {@Resourceprivate GrpcProperties grpcProperties;@SneakyThrowspublic String syncMeta(final String json,final SyncType syncType) {ManagedChannel channel = null;try {channel=NettyChannelBuilder.forAddress(grpcProperties.getServerIp(),grpcProperties.getPort())//非加密连接.usePlaintext()//加密//.sslContext(grpcProperties.buildClentSslContext()).build();HtMetaInfoSyncServiceGrpc.HtMetaInfoSyncServiceBlockingStub stub = HtMetaInfoSyncServiceGrpc.newBlockingStub(channel);HtMetaSyncResponse htMetaSyncResponse = stub.syncMeta((HtMetaSyncRequest.newBuilder().setSyncJson(json).setSyncType(syncType).build()));String code = htMetaSyncResponse.getCode();String msg = htMetaSyncResponse.getMsg();return code+":"+msg;} catch (final StatusRuntimeException e) {return "FAILED with " + e.getStatus().getCode().name();}finally {if (Objects.nonNull(channel)){channel.shutdown();}}}
}
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;/*** @author 何永豪* @className GrpcConfig* @description TODO* @date 2023/11/7 16:58*/
@Configuration
public class GrpcConfig {@Bean@ConditionalOnProperty(value = "grpc.enable",havingValue = "true",matchIfMissing = true)public GrpcServer grpcServer(){return new GrpcServer();}}
@Component
@ConfigurationProperties(prefix = "grpc")
@Data
public class GrpcProperties {private Integer port;private String  serverIp;private String serverCertPath;private String serverPrivateKeyPath;private String serverTrustCertPath;private String clientCertPath;private String clientCertChainPath;private String clientPrivateKeyPath;/*public SslContext buildClentSslContext() throws SSLException {SslContextBuilder sslContextBuilder = GrpcSslContexts.forClient();sslContextBuilder.trustManager(new File(clientCertPath));sslContextBuilder.keyManager(new File(clientCertChainPath),new File(clientPrivateKeyPath));return sslContextBuilder.build();}*/}
server:port: 8077spring:application:name: grpc-apigrpc:#监听端口port: 6100#目标IPserver-ip: 127.0.0.1#ssl配置server-cert-path: /ca/server/server.crtserver-private-key-path: /ca/server/server.pemserver-trust-cert-path: /ca/server/ca.crt

http://www.ppmy.cn/news/1209990.html

相关文章

【算法】最短路计数(计算最短路的数量)

题目 给出一个 N 个顶点 M 条边的无向无权图&#xff0c;顶点编号为 1 到 N。 问从顶点 1 开始&#xff0c;到其他每个点的最短路有几条。 输入格式 第一行包含 2 个正整数 N,M&#xff0c;为图的顶点数与边数。 接下来 M 行&#xff0c;每行两个正整数 x,y&#xff0c;表示有…

CSS3 用户界面、图片、按钮

一、CSS3用户界面&#xff1a; 在CSS3中&#xff0c;增加了一些新的用户界面特性来调整元素尺寸、框尺寸和外边框。CSS3用户界面属性&#xff1a;resize、box-sizing、outline-offset。 1、resize&#xff1a; resize属性指定一个元素是否应该由用户去调整大小。 <style…

重温数据结构与算法之前缀和

文章目录 前言一、基础1.1 定义1.2 时间复杂度 二、扩展2.1 二维前缀和2.2 差分数组2.3 前缀积 三、LeetCode 实战3.1 长度最小的子数组3.2 二维区域和检索 - 矩阵不可变 参考 前言 前缀和&#xff08;Prefix Sum&#xff09;&#xff0c;也被称为累计和&#xff0c;是一种在计…

HTML页面模拟了一个类似Excel的表格在线diy修改表格内容

html实现在线表格编辑&#xff0c;可以修改每个表格内容&#xff0c;并且可以添加行和列 这个HTML页面模拟了一个类似Excel的表格&#xff0c;可以添加和删除行和列&#xff0c;并且可以编辑每个表格的内容。通过点击按钮可以添加新的行和列&#xff0c;通过按钮可以删除最后一…

个人怎么投资伦敦金?

伦敦金是一种被广泛交易的黄金合约&#xff0c;是投资者参与黄金市场的一种交易方式。伦敦金投资也是黄金交易中最为方便快捷的一个种类&#xff0c;在黄金交易市场中占有较大的比例&#xff0c;每天都有来自全球各地的投资者参与买卖&#xff0c;是实现财富增益的一个有效途径…

YOLOv8模型ONNX格式INT8量化轻松搞定

ONNX格式模型量化 深度学习模型量化支持深度学习模型部署框架支持的一种轻量化模型与加速模型推理的一种常用手段&#xff0c;ONNXRUNTIME支持模型的简化、量化等脚本操作&#xff0c;简单易学&#xff0c;非常实用。 ONNX 模型量化常见的量化方法有三种&#xff1a;动态量化…

Zookeeper篇---第三篇

系列文章目录 文章目录 系列文章目录一、Zookeeper 集群中Server有哪些工作状态?二、 Zookeeper 集群中是怎样选举leader的?三、Zookeeper 是如何保证事务的顺序一致性的呢?一、Zookeeper 集群中Server有哪些工作状态? LOOKING 寻找 Leader 状态;当服务器处于该状态时,它…

jenkins通知

构建失败邮件通知 配置自己的邮箱 配置邮件服务&#xff0c;密码是授权码 添加构建后操作 扩展 配置流水线 添加扩展 钉钉通知 Jenkins安装钉钉插件 钉钉添加机器人 加签 https://oapi.dingtalk.com/robot/send?access_token98437f84ffb6cd64fa2d7698ef44191d49a11…