整合K8s+SpringCloudK8s+SpringBoot+gRpc

news2024/11/16 5:53:09

本文使用K8s当做服务注册与发现、配置管理,使用gRpc用做服务间的远程通讯

一、先准备K8s

我在本地有个K8s单机

二、准备service-provider

  1. pom

<?xml version="1.0" encoding="UTF-8"?>
<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 https://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.6.7</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>service-provider</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>service-provider</name>
    <description>service-provider</description>
    <properties>
        <java.version>11</java.version>
        <!--        <os.detected.classifier>osx-aarch_64</os.detected.classifier>-->
        <os.detected.classifier>osx-x86_64</os.detected.classifier>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <type>pom</type>
                <scope>import</scope>
                <version>2.6.7</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>2021.0.2</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-kubernetes-dependencies</artifactId>
                <version>1.1.0.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-kubernetes-client-all</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <!-- gRpc -->
        <dependency>
            <groupId>net.devh</groupId>
            <artifactId>grpc-spring-boot-starter</artifactId>
            <version>2.14.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>io.grpc</groupId>
            <artifactId>grpc-protobuf</artifactId>
            <version>1.52.1</version>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
            <version>1.18.24</version>
        </dependency>
    </dependencies>

    <build>
        <extensions>
            <extension>
                <groupId>kr.motd.maven</groupId>
                <artifactId>os-maven-plugin</artifactId>
                <version>1.7.1</version>
            </extension>
        </extensions>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <classifier>exec</classifier>
                </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.21.7:exe:${os.detected.classifier}</protocArtifact>
                    <pluginId>grpc-java</pluginId>
                    <pluginArtifact>io.grpc:protoc-gen-grpc-java:1.52.1:exe:${os.detected.classifier}</pluginArtifact>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>compile-custom</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>
  1. 配置文件 bootstrap.yaml

management:
  endpoint:
    restart:
      enabled: true
    health:
      enabled: true
    info:
      enabled: true
  endpoints:
    web:
      exposure:
        include: '*'

grpc:
  server:
    port: 9090
server:
  port: 30000

spring:
  application:
    name: service-provider
  cloud:
    kubernetes:
      reload:
        enabled: true
      config:
        sources:
          - namespace: service-k8s-demo
            name: service-provider-config
  1. 主类 ServiceProviderApplication

package com.example.service.provider;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@SpringBootApplication
@EnableDiscoveryClient
@RefreshScope
public class ServiceProviderApplication {

    @Value("${maple-test.message}")
    private String mapleTestMessage;

    @Autowired
    private DemoConfig demoConfig;

    public static void main(String[] args) {
        SpringApplication.run(ServiceProviderApplication.class, args);
    }

    @GetMapping("/provider-hello")
    public String sayHello() {
        log.info("hello world");
        return "hello world";
    }

    @GetMapping("/provider-value-config")
    public String valueConfig() {
        log.info("直接@Value获取配置:{}", mapleTestMessage);
        return mapleTestMessage;
    }

    @GetMapping("/demo-config")
    public String demoConfig() {
        log.info("通过ConfigurationProperties注解获取配置:{}", demoConfig.getMessage());
        return demoConfig.getMessage();
    }
}
  1. 在 src/main/proto文件夹下新增PB文件 HelloFacade.proto

syntax = "proto3";

option java_multiple_files = true;
option java_package = "com.example.service.provider.api";
option java_outer_classname = "HelloServiceProto";

service HelloService {
  rpc SayHello (SayHelloRequest) returns (SayHelloResponse) {
  }
}

message SayHelloRequest {
  string name = 1;
}

message SayHelloResponse {
  int32 code = 1;
  string message = 2;
  bool success = 3;
  SayHelloData data = 4;
}

message SayHelloData {
  string name = 1;
  string content = 2;
}
  1. 接口实现类

package com.example.service.provider.facade;

import com.example.service.provider.DemoConfig;
import com.example.service.provider.api.HelloServiceGrpc;
import com.example.service.provider.api.SayHelloData;
import com.example.service.provider.api.SayHelloRequest;
import com.example.service.provider.api.SayHelloResponse;
import lombok.extern.slf4j.Slf4j;
import net.devh.boot.grpc.server.service.GrpcService;
import org.springframework.beans.factory.annotation.Autowired;

@Slf4j
@GrpcService
public class HelloServiceImpl extends HelloServiceGrpc.HelloServiceImplBase {

    @Autowired
    private DemoConfig demoConfig;

    @Override
    public void sayHello(SayHelloRequest request, io.grpc.stub.StreamObserver<SayHelloResponse> responseObserver) {
        log.info("接收consumer的say hello grpc 请求");
        SayHelloData helloData = SayHelloData.newBuilder()
                .setName("maple")
                .setContent(demoConfig.getMessage())
                .build();
        SayHelloResponse.Builder builder = SayHelloResponse.newBuilder()
                .setCode(0)
                .setMessage("success")
                .setSuccess(true)
                .setData(helloData);
        responseObserver.onNext(builder.build());
        responseObserver.onCompleted();
    }
}
  1. Dockerfile

FROM openjdk:11-jdk-slim
ADD service-provider-0.0.1-SNAPSHOT-exec.jar service-provider.jar
ENTRYPOINT ["java", "-jar", "service-provider.jar"]
  1. K8s声明yaml文件 service-provider-deploy.yaml

apiVersion: v1
kind: Namespace
metadata:
  name: service-k8s-demo
  labels:
    name: service-k8s-demo

---

apiVersion: v1
kind: ServiceAccount
metadata:
  name: service-k8s-demo
  namespace: service-k8s-demo

---

kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  namespace: service-k8s-demo
  name: service-k8s-demo
rules:
  - apiGroups:
    - ""
    resources:
    - services
    - configmaps
    - endpoints
    - nodes
    - pods
    - secrets
    - namespaces
    verbs:
    - get
    - list
    - watch

---

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: service-k8s-demo
  namespace: service-k8s-demo
subjects:
- kind: ServiceAccount
  name: service-k8s-demo
  namespace: service-k8s-demo
roleRef:
  kind: ClusterRole
  name: service-k8s-demo
  apiGroup: rbac.authorization.k8s.io

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: service-provider
  namespace: service-k8s-demo
  labels:
    app: service-provider
spec:
  replicas: 1
  template:
    metadata:
      name: service-provider
      labels:
        app: service-provider
    spec:
      containers:
        - name: service-provider
          image: service-provider:1.0
          imagePullPolicy: IfNotPresent
          ports:
            - name: http
              protocol: TCP
              containerPort: 30000
            - name: grpc
              protocol: TCP
              containerPort: 9090
      serviceAccountName: service-k8s-demo
      restartPolicy: Always
  selector:
    matchLabels:
      app: service-provider

---

apiVersion: v1
kind: Service
metadata:
  name: service-provider
  namespace: service-k8s-demo
spec:
  selector:
    app: service-provider
  ports:
    - port: 80
      targetPort: 30000
      name: http
    - port: 9090
      targetPort: 9090
      name: grpc
  #clusterIP: None
  type: NodePort
  1. K8s声明yaml文件 service-provider-config.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: service-provider-config
  namespace: service-k8s-demo
data:
    bean.message: Hello World!
    maple-test.message: maple for dev config map in k8s
    redis.ip: 111 in k8s
  1. 本地启动测试

三、准备service-consumer

  1. pom

<?xml version="1.0" encoding="UTF-8"?>
<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 https://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.6.7</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>service-consumer</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>service-consumer</name>
    <description>service-consumer</description>
    <properties>
        <java.version>11</java.version>
    </properties>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <type>pom</type>
                <scope>import</scope>
                <version>2.6.7</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>2021.0.2</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-kubernetes-dependencies</artifactId>
                <version>1.1.10.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>

        <dependency>
            <groupId>com.example</groupId>
            <artifactId>service-provider</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-kubernetes-client-all</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
            <version>1.18.24</version>
        </dependency>

        <!-- gRpc -->
        <dependency>
            <groupId>net.devh</groupId>
            <artifactId>grpc-spring-boot-starter</artifactId>
            <version>2.14.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>io.grpc</groupId>
            <artifactId>grpc-protobuf</artifactId>
            <version>1.52.1</version>
        </dependency>
    </dependencies>

    <build>
        <extensions>
            <extension>
                <groupId>kr.motd.maven</groupId>
                <artifactId>os-maven-plugin</artifactId>
                <version>1.7.1</version>
            </extension>
        </extensions>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <classifier>exec</classifier>
                </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.21.7:exe:${os.detected.classifier}</protocArtifact>
                    <pluginId>grpc-java</pluginId>
                    <pluginArtifact>io.grpc:protoc-gen-grpc-java:1.52.1:exe:${os.detected.classifier}</pluginArtifact>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>compile-custom</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>
</project>
  1. 配置文件 bootstrap.yaml

management:
  endpoint:
    restart:
      enabled: true
    health:
      enabled: true
    info:
      enabled: true
  endpoints:
    web:
      exposure:
        include: '*'

grpc:
  server:
    port: 9091
  client:
    service-provider:
      negotiation-type: plaintext
      enable-keep-alive: true
      keep-alive-without-calls: true
      address: 'static://service-provider:9090'

server:
  port: 30001
spring:
  application:
    name: service-consumer
  cloud:
    kubernetes:
      reload:
        enabled: true
      config:
        sources:
          - namespace: service-k8s-demo
            name: service-consumer-config
  1. 主类 ServiceConsumerApplication

package com.example.service.consumer;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@EnableDiscoveryClient
@SpringBootApplication
@RequiredArgsConstructor
@RefreshScope
public class ServiceConsumerApplication {

    private final DiscoveryClient discoveryClient;
    private final ProviderServiceGrpcClient providerServiceGrpcClient;

    public static void main(String[] args) {
        SpringApplication.run(ServiceConsumerApplication.class, args);
    }

    @Value("${consumer.body}")
    private String consumerBody;

    @GetMapping("/grpc/hello")
    public String sayHello() {
        log.info("消费服务:service-consumer grpc 调用 service-provider");
        return providerServiceGrpcClient.sayHello();
    }

    @GetMapping("/consumerBody")
    public String consumerBody() {
        log.info("获取配置consumerBody:{}", consumerBody);
        return consumerBody;
    }

    @GetMapping("/consumers/services")
    public List<String> findServices() {
        log.info("当前注册中心下所有服务");
        List<String> services = discoveryClient.getServices();
        services.stream().map(discoveryClient::getInstances).forEach(v ->
                v.forEach(s -> System.out.printf("%s:%s  uri:%s%n", s.getHost(), s.getPort(), s.getUri())));

        return services;
    }
}
  1. gRpc调用Provider ProviderServiceGrpcClient

package com.example.service.consumer;

import com.example.service.provider.api.HelloServiceGrpc;
import com.example.service.provider.api.SayHelloRequest;
import com.example.service.provider.api.SayHelloResponse;
import net.devh.boot.grpc.client.inject.GrpcClient;
import org.springframework.stereotype.Service;

@Service
public class ProviderServiceGrpcClient {

    @GrpcClient("service-provider")
    private HelloServiceGrpc.HelloServiceBlockingStub helloServiceBlockingStub;

    public String sayHello() {

        SayHelloRequest request = SayHelloRequest.newBuilder().setName("maple123").build();

        SayHelloResponse sayHelloResponse = helloServiceBlockingStub.sayHello(request);

        return sayHelloResponse.toString();
    }
}
  1. Dockerfile

FROM openjdk:11-jdk-slim
ADD service-consumer-0.0.1-SNAPSHOT-exec.jar service-consumer.jar
ENTRYPOINT java -jar  service-consumer.jar
  1. K8s声明yaml文件 service-consumer-deploy.yaml

apiVersion: v1
kind: Namespace
metadata:
  name: service-k8s-demo
  labels:
    name: service-k8s-demo

---

apiVersion: v1
kind: ServiceAccount
metadata:
  name: service-k8s-demo
  namespace: service-k8s-demo

---

kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  namespace: service-k8s-demo
  name: service-k8s-demo
rules:
  - apiGroups:
      - ""
    resources:
      - services
      - configmaps
      - endpoints
      - nodes
      - pods
      - secrets
      - namespaces
    verbs:
      - get
      - list
      - watch

---

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: service-k8s-demo
  namespace: service-k8s-demo
subjects:
  - kind: ServiceAccount
    name: service-k8s-demo
    namespace: service-k8s-demo
roleRef:
  kind: ClusterRole
  name: service-k8s-demo
  apiGroup: rbac.authorization.k8s.io

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: service-consumer
  namespace: service-k8s-demo
  labels:
    app: service-consumer
spec:
  replicas: 1
  template:
    metadata:
      name: service-consumer
      labels:
        app: service-consumer
    spec:
      containers:
        - name: service-consumer
          image: service-consumer:1.0
          imagePullPolicy: IfNotPresent
          ports:
            - name: http
              protocol: TCP
              containerPort: 30001
            - name: grpc
              protocol: TCP
              containerPort: 9091
      serviceAccountName: service-k8s-demo
      restartPolicy: Always
  selector:
    matchLabels:
      app: service-consumer

---

apiVersion: v1
kind: Service
metadata:
  name: service-consumer
  namespace: service-k8s-demo
spec:
  selector:
    app: service-consumer
  ports:
    - port: 80
      targetPort: 30001
      name: http
    - port: 9091
      targetPort: 9091
      name: grpc
  type: NodePort
  1. K8s声明yaml文件 service-consumer-config.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: service-consumer-config
  namespace: service-k8s-demo
data:
    consumer.body: "1234567890"
  1. 本地启动测试

四、打镜像

docker build -t service-provider:1.0 .
docker build -t service-consumer:1.0 .

五、执行K8s yaml文件 创建命名空间、账号、角色、部署应用、暴露端口等

kubetl apply -f service-provider-config.yaml
kubetl apply -f service-provider-deploy.yaml

kubetl apply -f service-consumer-config.yaml
kubetl apply -f service-consumer-deploy.yaml

六、查看与测试

gRpc正常访问,但是发现一个问题,下面的图片,上面三个是Provider,发现负载均衡失效了,请求全都打在了一个Provider里,搜了下发现和 gRpc基于HTTP2.0 多路复用 有关,之后再处理吧。

配置测试

动态配置测试

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

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

相关文章

2023年PMP考试教材有哪些?(含pmp资料)

PMP考试教材是《PMBOK指南》&#xff0c;但这次的考试因为大纲的更新&#xff0c;而需要另外的敏捷书籍来备考。且官方发了通知&#xff0c;3、5月还是第六版指南&#xff0c;8月及8月之后&#xff0c;使用第七版教材。 新版考纲将专注于以下三个新领域: 人 – 强调与有效领导项…

java设计模式——观察者模式

概述 定义:又被称为发布-订阅(Publish/Subscribe)模式&#xff0c;它定义了一种一对多的依赖关系&#xff0c;让多个观察者对象同时监听某一个主题对象。这个主题对象在状态变化时&#xff0c;会通知所有的观察者对象&#xff0c;使他们能够自动更新自己。 结构 在观察者模式…

数据分析:旅游景点销售门票和消费情况分析

数据分析&#xff1a;旅游景点销售门票和消费情况分析 文章目录数据分析&#xff1a;旅游景点销售门票和消费情况分析一、前言二、数据准备三、分析数据四、用户购买门票数量分析五、用户复购分析六、用户回购分析七、占比分析1.每个月分层用户占比情况。2.每月不同用户的占比3…

网络模型OSI

网络模型OSI定义模型分布数据封装、解封过程数据链路层1.LLC逻辑链路控制子层(Logic Link Control Sub Layer)2.MAC媒介访问控制子层(Medium Acess Control Sub Layer)CSMA/CARST-CST原理OSI定义 OSI&#xff1a;Open Systems Interconnection Reference Model&#xff0c;开放…

2023年前端开发的八大趋势,值得你关注下

随着新年的到来&#xff0c;许多人制定了提高自己和工作的决心。对于前端开发人员而言&#xff0c;跟上最新的潮流趋势是成功的关键。特别是在经济不好的情况下&#xff0c;很多科技专家在最近一个季度内被解雇&#xff0c;这更加强调了这一点。在2023年&#xff0c;有许多令人…

学习 Python 之 Pygame 开发坦克大战(五)

学习 Python 之 Pygame 开发坦克大战&#xff08;五&#xff09;坦克大战完善地图1. 创建砖墙2. 给砖墙增加子弹击中的碰撞效果3. 给砖墙坦克不能通过的碰撞效果坦克大战完善地图 我的素材放到了百度网盘里&#xff0c;里面还有原版坦克大战素材&#xff0c;我都放在一起来&am…

Blazor入门100天 : 身份验证和授权 (2) - 角色/组件/特性/过程逻辑

目录 建立默认带身份验证 Blazor 程序角色/组件/特性/过程逻辑DB 改 Sqlite将自定义字段添加到用户表脚手架拉取IDS文件,本地化资源freesql 生成实体类,freesql 管理ids数据表初始化 Roles,freesql 外键 > 导航属性完善 freesql 和 bb 特性 本节源码 https://github.com/…

Flink03: 集群安装部署

Flink支持多种安装部署方式 StandaloneON YARNMesos、Kubernetes、AWS… 这些安装方式我们主要讲一下standalone和on yarn。 如果是一个独立环境的话&#xff0c;可能会用到standalone集群模式。 在生产环境下一般还是用on yarn 这种模式比较多&#xff0c;因为这样可以综合利…

C++入门:引用

目录 一. 什么是引用 1.1 引用的概念 1.2 引用的定义 二. 引用的性质和用途 2.1 引用的三大主要性质 2.2 引用的主要应用 三. 引用的效率测试 3.1 传值调用和传引用调用的效率对比 3.2 值返回和引用返回的效率对比 四. 常引用 4.1 权限放大和权限缩小问题 4.2 跨…

【超好用】自定义的mybatis-plus代码生成器

BACKGROUND你是否也有这样的烦恼&#xff1a;每次写代码都需要创建很多包很多层很多类很多接口&#xff1f;耗时且费力姑且不谈&#xff0c;有时可能还大意了没有闪&#xff0c;搞出一堆bug这谁顶得住啊都3202年了&#xff0c;让程序自力更生吧&#xff01;&#xff01;教程 le…

原创|关于一次产品需求程序设计及优化的经历

文章目录一、流程梳理二、设计梳理三、技术方案3.1、下单接口扩展3.3.1、Request类新增deviceType3.3.2、申请单新增字段产品策略(productStrategy)3.3.3、下单产品策略的处理逻辑3.2、询价模块的设计3.2.1、Context设计3.2.2、ProductStrategy类设计3.2.2.1、AbstractProductS…

k8s篇之概念介绍

文章目录时光回溯什么是K8SK8S不是什么一、K8S构成组件控制平面组件&#xff08;Control Plane Components&#xff09;kube-apiserveretcdkube-schedulerkube-controller-managercloud-controller-managerNode 组件kubeletkube-proxy容器运行时&#xff08;Container Runtime&…

Spring Cloud Nacos实战(七)- Nacos之Linux版本安装

Nacos之Linux版本安装 Linux版NacosMySql生产环境配置 ​ 已经给大家讲解过了Nacos生产环境下需要搭建集群配置&#xff0c;那么这里我们预计需要&#xff1a;1个Nginx3个Nacos注册中心1个MySql 具体配置&#xff1a; 在官网上下载NacosLinux版本&#xff1a;https://github…

基于SSM框架的CMS内容管理系统的设计与实现

基于SSM框架的CMS内容管理系统的设计与实现 ✌全网粉丝20W,csdn特邀作者、博客专家、CSDN新星计划导师、java领域优质创作者,博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和毕业项目实战✌ &#x1f345;文末获取项目下载方式&#x1f345; 一、项目…

并查集(高级数据结构)-蓝桥杯

一、并查集并查集(Disioint Set)&#xff1a;一种非常精巧而实用的数据结构用于处理不相交集合的合并问题。用于处理不相交集合的合并问题。经典应用&#xff1a;连通子图。最小生成树Kruskal算法。最近公共祖先。二、应用场景有n个人&#xff0c;他们属于不同的帮派。 已知这些…

Kafka漏洞修复之CVE-2023-25194修复措施验证

Kafka漏洞修复之CVE-2023-25194修复措施验证前言风险分析解决方案AdoptOpenJDK Zookeeper Kafka多版本OpenJDK安装切换Zookeeper安装Kafka安装与使用其他Kafka消息发送流程Linux配置加载顺序参考链接前言 场景介绍 Kafka最近爆出高危漏洞CNNVD-202302-515&#xff0c;导致Apa…

LeetCode刷题复盘笔记—一文搞懂贪心算法之56. 合并区间(贪心算法系列第十四篇)

今日主要总结一下可以使用贪心算法解决的一道题目&#xff0c;56. 合并区间 题目&#xff1a;56. 合并区间 Leetcode题目地址 题目描述&#xff1a; 以数组 intervals 表示若干个区间的集合&#xff0c;其中单个区间为 intervals[i] [starti, endi] 。请你合并所有重叠的区间…

QXlsx(访问Excel)

再Qt中已经有了QAxObject来访问Excel&#xff0c;但访问的是微软的com&#xff0c;只能访问正版的Excl中的 .xls//xlsx ,而且使用起来及其不方便&#xff08;本人亲测&#xff09;。 在这里使用QXlsx,能更简单的访问Excel数据&#xff0c;但QXlsx这个类并没有在Qt Creator中&a…

《MySQL学习》 MySQL优化器选择如何选择索引

一.优化器的选择逻辑 建表语句 CREATE TABLE t (id int(11) NOT NULL AUTO_INCREMENT,a int(11) DEFAULT NULL,b int(11) DEFAULT NULL,PRIMARY KEY (id),KEY a (a),KEY b (b) ) ENGINEInnoDB;往表中插入10W条数据 delimiter ;; create procedure idata() begindeclare i in…

目标检测三大数据格式VOC,YOLO,COCO的详细介绍

注&#xff1a;本文仅供学习&#xff0c;未经同意请勿转载 说明&#xff1a;该博客来源于xiaobai_Ry:2020年3月笔记 对应的PDF下载链接在&#xff1a;待上传 目录 目标检测常见数据集总结 V0C数据集(Annotation的格式是xmI) A. 数据集包含种类: B. V0C2007和V0C2012的区别…