Grpc項目集成到java方式調用實踐

背景:由于項目要對接到grcp 的框架,然后需要對接老外的東西,還有簽名和證書剛開始沒有接觸其實有點懵逼。

gRPC 是由 Google 開發的高性能、開源的遠程過程調用(RPC)框架。它建立在 HTTP/2 協議之上,使用 Protocol Buffers 作為其接口定義語言(IDL)。gRPC 被設計為可跨多種環境(包括客戶端、服務器和各種語言)使用,支持多種編程語言,如 C、C++、Java、Go、Python、Ruby、Node.js 等。

gRPC 具有以下特點:

  1. 性能高效:gRPC 使用基于 HTTP/2 的傳輸協議,能夠復用連接、多路復用請求、支持頭部壓縮等特性,從而提高了性能。

  2. 跨語言支持:gRPC 支持多種編程語言,使得客戶端和服務器可以使用不同的編程語言實現,并且它們之間的通信依然高效。

  3. IDL 和自動代碼生成:gRPC 使用 Protocol Buffers 作為接口定義語言(IDL),定義服務接口和消息格式,并提供了自動生成客戶端和服務器代碼的工具。

  4. 多種調用方式:gRPC 支持四種調用方式,包括簡單 RPC、服務器流式 RPC、客戶端流式 RPC 和雙向流式 RPC,可以根據業務需求選擇合適的調用方式。

  5. 安全性:gRPC 支持 TLS/SSL 加密傳輸,保障通信的安全性。

  6. 插件機制:gRPC 提供了插件機制,可以擴展其功能,例如添加認證、日志、監控等功能。

總的來說,gRPC 是一個強大的遠程過程調用框架,適用于構建分布式系統中的各種服務,并且在性能、跨語言支持和安全性方面具有很多優勢。

一,開發工具集成:

安裝指定插件,網上說還要Protobuf buffer 安裝,但是我用的idea2018的版本搜索不到,這個不是必須的,可以不用。

二 protobuf編譯器一定要安裝配置一個:?Releases · protocolbuffers/protobuf · GitHub

三,安裝好插件后就可以看的了這倆個就是生產java代碼的。

四,grpc 的文件格式:

syntax = "proto3";package c3_vanilla_app;option java_package = "com.test.conncar.c3vanillaapp";
option java_outer_classname = "C3VanillaAppProtos";import "google/protobuf/empty.proto";message ExampleRequestMessage {string id = 1;int64 timestamp = 2;string message = 3;
}message ExampleResponseMessage {string message = 1;
}service ExampleService {rpc PostExampleMessages(ExampleRequestMessage) returns (ExampleResponseMessage) {}
}

生成出來的代碼就是:

可以用命令生成,然后也可以用maven自動生成

pom加上這個插件就可以生產代碼了:

 <plugin><groupId>org.xolstice.maven.plugins</groupId><artifactId>protobuf-maven-plugin</artifactId><version>0.6.1</version><configuration><protocArtifact>com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier}</protocArtifact><pluginId>grpc-java</pluginId><pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact></configuration><executions><execution><goals><goal>compile</goal><goal>compile-custom</goal></goals></execution></executions></plugin>

完整的pom文件:

 <properties><protoc.version>3.25.2</protoc.version><grpc.version>1.61.1</grpc.version><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>io.grpc</groupId><artifactId>grpc-protobuf</artifactId><version>${grpc.version}</version></dependency><dependency><groupId>io.grpc</groupId><artifactId>grpc-stub</artifactId><version>${grpc.version}</version></dependency><dependency><groupId>io.grpc</groupId><artifactId>grpc-core</artifactId><version>${grpc.version}</version></dependency><dependency><groupId>com.google.protobuf</groupId><artifactId>protobuf-java</artifactId><version>3.25.2</version> <!-- 或者與你的 protoc.version 相匹配的版本 --></dependency><dependency><groupId>io.grpc</groupId><artifactId>grpc-netty</artifactId><version>${grpc.version}</version></dependency><dependency><!-- necessary for Java 9+ --><groupId>org.apache.tomcat</groupId><artifactId>annotations-api</artifactId><version>6.0.53</version></dependency></dependencies><build><extensions><extension><groupId>kr.motd.maven</groupId><artifactId>os-maven-plugin</artifactId><version>1.6.2</version></extension></extensions><plugins><plugin><groupId>org.xolstice.maven.plugins</groupId><artifactId>protobuf-maven-plugin</artifactId><version>0.6.1</version><configuration><protocArtifact>com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier}</protocArtifact><pluginId>grpc-java</pluginId><pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact></configuration><executions><execution><goals><goal>compile</goal><goal>compile-custom</goal></goals></execution></executions></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.10.1</version><configuration><source>1.8</source><target>1.8</target></configuration></plugin><plugin><groupId>org.jfrog.buildinfo</groupId><artifactId>artifactory-maven-plugin</artifactId><version>3.3.0</version><inherited>false</inherited><executions><execution><id>build-info</id><goals><goal>publish</goal></goals><configuration><artifactory><includeEnvVars>false</includeEnvVars><timeoutSec>60</timeoutSec><propertiesFile>publish.properties</propertiesFile></artifactory><publisher><contextUrl>${env.ARTIFACTORY_HOST_POM}</contextUrl><username>${env.ARTIFACTORY_CCAR_USER}</username><password>${env.ARTIFACTORY_CCAR_APIKEY}</password><excludePatterns>*-tests.jar</excludePatterns><repoKey>${CI_PROJECT_NAMESPACE}</repoKey><snapshotRepoKey>${CI_PROJECT_NAMESPACE}</snapshotRepoKey></publisher><buildInfo><buildName>${CI_PROJECT_NAME}</buildName><buildNumber>${CI_PIPELINE_ID}</buildNumber><buildUrl>${CI_PROJECT_URL}</buildUrl></buildInfo></configuration></execution></executions></plugin><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build>

生成的代碼路徑:

生成的代碼,記得install的時候注釋掉插件,然后進行install

然后本地寫個client和sever就行了:

server:

package com.grpc.mistra.server;import com.grpc.mistra.generate.MistraRequest;
import com.grpc.mistra.generate.MistraResponse;
import com.grpc.mistra.generate.MistraServiceGrpc;
import io.grpc.BindableService;
import io.grpc.Server;
import io.grpc.ServerBuilder;
import io.grpc.stub.StreamObserver;import java.io.IOException;/*** Time: 14:46* Description:*/
public class MistraServer {private int port = 8001;private Server server;private void start() throws IOException {server = ServerBuilder.forPort(port).addService((BindableService) new MistraHelloWorldImpl()).build().start();System.out.println("------------------- 服務端服務已開啟,等待客戶端訪問 -------------------");Runtime.getRuntime().addShutdownHook(new Thread() {@Overridepublic void run() {System.err.println("*** shutting down gRPC server since JVM is shutting down");MistraServer.this.stop();System.err.println("*** server shut down");}});}private void stop() {if (server != null) {server.shutdown();}}private void blockUntilShutdown() throws InterruptedException {if (server != null) {server.awaitTermination();}}public static void main(String[] args) throws IOException, InterruptedException {final MistraServer server = new MistraServer();//啟動服務server.start();//服務一直在線,不關閉server.blockUntilShutdown();}// 定義一個實現服務接口的類private class MistraHelloWorldImpl extends MistraServiceGrpc.MistraServiceImplBase {@Overridepublic void sayHello(MistraRequest mistraRequest, StreamObserver<MistraResponse> responseObserver) {// 具體其他豐富的業務實現代碼System.err.println("server:" + mistraRequest.getName());MistraResponse reply = MistraResponse.newBuilder().setMessage(("響應信息: " + mistraRequest.getName())).build();responseObserver.onNext(reply);responseObserver.onCompleted();}}
}

client:

package com.grpc.mistra.client;import com.grpc.mistra.generate.MistraRequest;
import com.grpc.mistra.generate.MistraResponse;
import com.grpc.mistra.generate.MistraServiceGrpc;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;import java.util.concurrent.TimeUnit;/*** Time: 14:46* Description:*/
public class MistraClient {private final ManagedChannel channel;private final MistraServiceGrpc.MistraServiceBlockingStub blockingStub;public MistraClient(String host, int port) {channel = ManagedChannelBuilder.forAddress(host, port).usePlaintext(true).build();blockingStub = MistraServiceGrpc.newBlockingStub(channel);}public void shutdown() throws InterruptedException {channel.shutdown().awaitTermination(5, TimeUnit.SECONDS);}public void greet(String name) {MistraRequest request = MistraRequest.newBuilder().setName(name).build();MistraResponse response = blockingStub.sayHello(request);System.out.println(response.getMessage());}public static void main(String[] args) throws InterruptedException {MistraClient client = new MistraClient("127.0.0.1", 8001);System.out.println("-------------------客戶端開始訪問請求-------------------");for (int i = 0; i < 10; i++) {client.greet("你若想生存,絕處也能縫生: " + i);}}
}

效果圖:

grpc的調用類:

package com.grpc.mistra.generate;import static io.grpc.MethodDescriptor.generateFullMethodName;
import static io.grpc.stub.ClientCalls.asyncUnaryCall;
import static io.grpc.stub.ClientCalls.blockingUnaryCall;
import static io.grpc.stub.ClientCalls.futureUnaryCall;
import static io.grpc.stub.ServerCalls.asyncUnaryCall;
import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;/*** <pre>* 聲明一個服務名稱* </pre>*/
@javax.annotation.Generated(value = "by gRPC proto compiler (version 1.11.0)",comments = "Source: helloworld.proto")
public final class MistraServiceGrpc {private MistraServiceGrpc() {}public static final String SERVICE_NAME = "mistra.MistraService";// Static method descriptors that strictly reflect the proto.@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901")@Deprecated // Use {@link #getSayHelloMethod()} instead.public static final io.grpc.MethodDescriptor<MistraRequest,MistraResponse> METHOD_SAY_HELLO = getSayHelloMethodHelper();private static volatile io.grpc.MethodDescriptor<MistraRequest,MistraResponse> getSayHelloMethod;@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901")public static io.grpc.MethodDescriptor<MistraRequest,MistraResponse> getSayHelloMethod() {return getSayHelloMethodHelper();}private static io.grpc.MethodDescriptor<MistraRequest,MistraResponse> getSayHelloMethodHelper() {io.grpc.MethodDescriptor<MistraRequest, MistraResponse> getSayHelloMethod;if ((getSayHelloMethod = MistraServiceGrpc.getSayHelloMethod) == null) {synchronized (MistraServiceGrpc.class) {if ((getSayHelloMethod = MistraServiceGrpc.getSayHelloMethod) == null) {MistraServiceGrpc.getSayHelloMethod = getSayHelloMethod =io.grpc.MethodDescriptor.<MistraRequest, MistraResponse>newBuilder().setType(io.grpc.MethodDescriptor.MethodType.UNARY).setFullMethodName(generateFullMethodName("mistra.MistraService", "SayHello")).setSampledToLocalTracing(true).setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(MistraRequest.getDefaultInstance())).setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(MistraResponse.getDefaultInstance())).setSchemaDescriptor(new MistraServiceMethodDescriptorSupplier("SayHello")).build();}}}return getSayHelloMethod;}/*** Creates a new async stub that supports all call types for the service*/public static MistraServiceStub newStub(io.grpc.Channel channel) {return new MistraServiceStub(channel);}/*** Creates a new blocking-style stub that supports unary and streaming output calls on the service*/public static MistraServiceBlockingStub newBlockingStub(io.grpc.Channel channel) {return new MistraServiceBlockingStub(channel);}/*** Creates a new ListenableFuture-style stub that supports unary calls on the service*/public static MistraServiceFutureStub newFutureStub(io.grpc.Channel channel) {return new MistraServiceFutureStub(channel);}/*** <pre>* 聲明一個服務名稱* </pre>*/public static abstract class MistraServiceImplBase implements io.grpc.BindableService {/*** <pre>* 請求參數MistraRequest   響應參數MistraResponse* </pre>*/public void sayHello(MistraRequest request,io.grpc.stub.StreamObserver<MistraResponse> responseObserver) {asyncUnimplementedUnaryCall(getSayHelloMethodHelper(), responseObserver);}@Overridepublic final io.grpc.ServerServiceDefinition bindService() {return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor()).addMethod(getSayHelloMethodHelper(),asyncUnaryCall(new MethodHandlers<MistraRequest,MistraResponse>(this, METHODID_SAY_HELLO))).build();}}/*** <pre>* 聲明一個服務名稱* </pre>*/public static final class MistraServiceStub extends io.grpc.stub.AbstractStub<MistraServiceStub> {private MistraServiceStub(io.grpc.Channel channel) {super(channel);}private MistraServiceStub(io.grpc.Channel channel,io.grpc.CallOptions callOptions) {super(channel, callOptions);}@Overrideprotected MistraServiceStub build(io.grpc.Channel channel,io.grpc.CallOptions callOptions) {return new MistraServiceStub(channel, callOptions);}/*** <pre>* 請求參數MistraRequest   響應參數MistraResponse* </pre>*/public void sayHello(MistraRequest request,io.grpc.stub.StreamObserver<MistraResponse> responseObserver) {asyncUnaryCall(getChannel().newCall(getSayHelloMethodHelper(), getCallOptions()), request, responseObserver);}}/*** <pre>* 聲明一個服務名稱* </pre>*/public static final class MistraServiceBlockingStub extends io.grpc.stub.AbstractStub<MistraServiceBlockingStub> {private MistraServiceBlockingStub(io.grpc.Channel channel) {super(channel);}private MistraServiceBlockingStub(io.grpc.Channel channel,io.grpc.CallOptions callOptions) {super(channel, callOptions);}@Overrideprotected MistraServiceBlockingStub build(io.grpc.Channel channel,io.grpc.CallOptions callOptions) {return new MistraServiceBlockingStub(channel, callOptions);}/*** <pre>* 請求參數MistraRequest   響應參數MistraResponse* </pre>*/public MistraResponse sayHello(MistraRequest request) {return blockingUnaryCall(getChannel(), getSayHelloMethodHelper(), getCallOptions(), request);}}/*** <pre>* 聲明一個服務名稱* </pre>*/public static final class MistraServiceFutureStub extends io.grpc.stub.AbstractStub<MistraServiceFutureStub> {private MistraServiceFutureStub(io.grpc.Channel channel) {super(channel);}private MistraServiceFutureStub(io.grpc.Channel channel,io.grpc.CallOptions callOptions) {super(channel, callOptions);}@Overrideprotected MistraServiceFutureStub build(io.grpc.Channel channel,io.grpc.CallOptions callOptions) {return new MistraServiceFutureStub(channel, callOptions);}/*** <pre>* 請求參數MistraRequest   響應參數MistraResponse* </pre>*/public com.google.common.util.concurrent.ListenableFuture<MistraResponse> sayHello(MistraRequest request) {return futureUnaryCall(getChannel().newCall(getSayHelloMethodHelper(), getCallOptions()), request);}}private static final int METHODID_SAY_HELLO = 0;private static final class MethodHandlers<Req, Resp> implementsio.grpc.stub.ServerCalls.UnaryMethod<Req, Resp>,io.grpc.stub.ServerCalls.ServerStreamingMethod<Req, Resp>,io.grpc.stub.ServerCalls.ClientStreamingMethod<Req, Resp>,io.grpc.stub.ServerCalls.BidiStreamingMethod<Req, Resp> {private final MistraServiceImplBase serviceImpl;private final int methodId;MethodHandlers(MistraServiceImplBase serviceImpl, int methodId) {this.serviceImpl = serviceImpl;this.methodId = methodId;}@Override@SuppressWarnings("unchecked")public void invoke(Req request, io.grpc.stub.StreamObserver<Resp> responseObserver) {switch (methodId) {case METHODID_SAY_HELLO:serviceImpl.sayHello((MistraRequest) request,(io.grpc.stub.StreamObserver<MistraResponse>) responseObserver);break;default:throw new AssertionError();}}@Override@SuppressWarnings("unchecked")public io.grpc.stub.StreamObserver<Req> invoke(io.grpc.stub.StreamObserver<Resp> responseObserver) {switch (methodId) {default:throw new AssertionError();}}}private static abstract class MistraServiceBaseDescriptorSupplierimplements io.grpc.protobuf.ProtoFileDescriptorSupplier, io.grpc.protobuf.ProtoServiceDescriptorSupplier {MistraServiceBaseDescriptorSupplier() {}@Overridepublic com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() {return MistraProto.getDescriptor();}@Overridepublic com.google.protobuf.Descriptors.ServiceDescriptor getServiceDescriptor() {return getFileDescriptor().findServiceByName("MistraService");}}private static final class MistraServiceFileDescriptorSupplierextends MistraServiceBaseDescriptorSupplier {MistraServiceFileDescriptorSupplier() {}}private static final class MistraServiceMethodDescriptorSupplierextends MistraServiceBaseDescriptorSupplierimplements io.grpc.protobuf.ProtoMethodDescriptorSupplier {private final String methodName;MistraServiceMethodDescriptorSupplier(String methodName) {this.methodName = methodName;}@Overridepublic com.google.protobuf.Descriptors.MethodDescriptor getMethodDescriptor() {return getServiceDescriptor().findMethodByName(methodName);}}private static volatile io.grpc.ServiceDescriptor serviceDescriptor;public static io.grpc.ServiceDescriptor getServiceDescriptor() {io.grpc.ServiceDescriptor result = serviceDescriptor;if (result == null) {synchronized (MistraServiceGrpc.class) {result = serviceDescriptor;if (result == null) {serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME).setSchemaDescriptor(new MistraServiceFileDescriptorSupplier()).addMethod(getSayHelloMethodHelper()).build();}}}return result;}
}

咋們就完成了grpc接入到java里面調用了本質上其實代碼沒有區別,小楊看了一下,他就是多了一些設計模式生產的代碼,工廠構建等。?

?————沒有與生俱來的天賦,都是后天的努力拼搏(我是小楊,謝謝你的關注和支持)

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/718655.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/718655.shtml
英文地址,請注明出處:http://en.pswp.cn/news/718655.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

D7805 正電壓穩壓電路應用——體積小,成本低,性能好

D7805 構成的 5V 穩壓電源為輸出電壓5V&#xff0c;輸出電流 1000mA 的穩壓電源它由濾波電容 C1,C3,防止自激電容 C2、C3 和一只固定三端穩壓器&#xff08;7805&#xff09;后級加 LC 濾波極為簡潔方便地搭成&#xff0c;輸入直流電壓范圍為 7~35V&#xff0c;此直流電壓經過D…

yolov8-更換卷積模塊-ContextGuidedBlock_Down

源碼解讀 class ContextGuidedBlock_Down(nn.Module):"""the size of feature map divided 2, (H,W,C)---->(H/2, W/2, 2C)"""def __init__(self, nIn, dilation_rate2, reduction16):"""args:nIn: the channel of input fea…

Hack The Box-Bizness

目錄 信息收集 nmap dirsearch WEB Get shell 提權 get user flag get root flag 信息收集 nmap 端口掃描┌──(root?ru)-[~/kali/hackthebox] └─# nmap -p- 10.10.11.252 --min-rate 10000 -oA port Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-03-04 1…

實測VLLM的加速效果

為了測試vllm的并行加速效果&#xff0c;采用同樣的5個提問&#xff0c;編寫兩個不同的python腳本&#xff0c;分別是compare_vllm.py和compare_chatglm3.py&#xff0c;其中compare_vllm.py采用vllm加速。 服務器參數&#xff1a; 操作系統ubuntu 22.04CPUi7 14700k內存dd5 …

hive中常見參數優化總結

1.with as 的cte優化&#xff0c;一般開發中習慣使用with as方便閱讀&#xff0c;但如果子查詢結果在下游被多次引用&#xff0c;可以使用一定的參數優化手段減少表掃描次數 默認set hive.optimize.cte.materialize.threshold-1;不自動物化到內存&#xff0c;一般可以設置為 se…

力扣 第 387 場周賽 解題報告 | 珂學家 | 離散化樹狀數組 + 模擬場

前言 整體評價 手速場模擬場&#xff0c;思路和解法都蠻直接的。 所以搞點活 如果T2&#xff0c;如果不固定左上角&#xff0c;批量查詢某個點為左上角&#xff0c;求滿足總和 ≤ k \le k ≤k的子矩陣個數 如果T2&#xff0c;如果不固定左上角&#xff0c;求總和 ≤ k \le k…

Spring的Bean的生命周期 | 有圖有案例

Spring的Bean的生命周期 Spring的Bean的生命周期整體過程實例化初始化服務銷毀循環依賴問題 完整生命周期演示 Spring的Bean的生命周期 Spring Bean的生命周期&#xff1a;從Bean的實例化之后&#xff0c;通過反射創建出對象之后&#xff0c;到Bean稱為一個完整的對象&#xf…

EXPLAIN:mysql 執行計劃分析詳解

目錄 EXPLAIN命令 查看執行計劃 分析執行計劃 優化查詢 EXPLAIN中的 type 列類型 在MySQL中&#xff0c;你可以使用EXPLAIN命令來生成查詢的執行計劃。EXPLAIN命令可以顯示MySQL如何使用鍵來處理SELECT和DELETE語句&#xff0c;以及INSERT或UPDATE語句的WHERE子句。這對于…

SRS Stack提供的鑒權、私人直播間、多平臺轉播、錄制等高級功能的具體使用方法是什么?

SRS Stack提供的鑒權、私人直播間、多平臺轉播、錄制等高級功能的具體使用方法是什么&#xff1f; 鑒權功能&#xff1a;SRS Stack支持通過系統配置中的OpenAPI獲取Bearer鑒權&#xff0c;并可以嘗試HTTP API。用戶可以通過點擊網頁上的按鈕請求HTTP API&#xff0c;或者使用cu…

快上車:什么是人工智能?人工智能和普通程序的區別

什么是人工智能&#xff1f; 雖然AI歷史很悠久&#xff0c;上個世紀50年代就有各種概念&#xff0c;但是發展很慢。第一次對人類的沖擊就是1997年IBM深藍擊敗國際象棋世界冠軍&#xff0c;引起了人們的廣泛關注&#xff0c;之后又銷聲匿跡。突然間2016人工智能alphaGO戰勝了圍…

具身智能計算系統,機器人時代的 Android | 新程序員

【導讀】具身智能作為一種新興的研究視角和方法論&#xff0c;正在刷新我們對智能本質及其發展的理解&#xff1a;傳統的 AI 模型往往將智能視為一種獨立于實體存在的抽象能力&#xff0c;而具身智能則主張智能是實體與其環境持續互動的結果。 本文深度剖析了具身智能計算系統…

【CSS】初學了解Grid布局

目錄 什么是Grid布局如何開始使用Grid布局Grid容器的屬性Grid項目的屬性舉個例子 什么是Grid布局 Grid布局是一種二維的布局系統&#xff0c;它允許我們在水平和垂直方向上同時控制網格中的項目位置。通過將頁面劃分為行和列&#xff0c;我們可以輕松地創建出復雜的布局結構&a…

程序員如何選擇職業賽道?

一、自我評估與興趣探索 程序員選擇職業賽道時&#xff0c;可以考慮以下幾個關鍵因素&#xff1a; 1、興趣與熱情&#xff1a;首先要考慮自己的興趣和熱情&#xff0c;選擇符合個人喜好和激情的領域&#xff0c;能夠激勵自己持續學習和進步。 2、技術能力&am…

2.python72變筆記(自用未修改版)

以前寫的python筆記 1.二進制與字符編碼 #8bit&#xff08;位&#xff09;1byte&#xff08;字節&#xff09; #1024byte 1KB 千字節 #1024KB 1MB 兆字節 #1024MB 1TB 太字節 print(chr(0b100111001010000)) print(ord("陳")) #ord 十進制 #無論英語還是漢語在計算…

mysql5.7配置主從

原理&#xff1a; MySQL主從復制的工作原理如下:1. 主服務器產生Binlog日志當主服務器的數據庫發生數據修改操作時,如INSERT、UPDATE、DELETE語句執行,主服務器會記錄這些操作的日志信息到二進制日志文件中。2. 從服務器讀取Binlog日志 從服務器會向主服務器發送請求,主服務器把…

微信小程序開發學習筆記《18》uni-app框架-網絡請求與輪播圖

微信小程序開發學習筆記《18》uni-app框架-網絡請求 博主正在學習微信小程序開發&#xff0c;希望記錄自己學習過程同時與廣大網友共同學習討論。建議仔細閱讀uni-app對應官方文檔 一、下載網絡請求包 這個包是以前黑馬程序員老師寫的一個包&#xff0c;跟著課程學習&#x…

Open3D(C++) 指定點數的體素濾波

目錄 一、算法原理1、算法過程2、參考文獻二、代碼實現三、結果展示本文由CSDN點云俠原創,原文鏈接。如果你不是在點云俠的博客中看到該文章,那么此處便是不要臉的爬蟲與GPT。 一、算法原理 1、算法過程 對于數據量較大的點云,在后期進行配準時會影響計算效率。而體素格網…

vue3ts websocket通信

前端&#xff1a;vue3ts 后端&#xff1a;springboot npm安裝依賴 cnpm install sockjs-client stompjs 前端代碼 <template><div><el-input v-model"message" type"text" placeholder"發送" /><el-button-group><…

LCR 170. 交易逆序對的總數

解題思路&#xff1a; 歸并排序&#xff0c;在歸并的過程中不斷計算逆序對的個數 count mid -i 1&#xff1b;的來源見下圖&#xff0c;因為兩個數組都是單調遞增的&#xff0c;所以如果第一個數組的前一個元素大于第二個數組的對應元素&#xff0c;那么第一個數組的這一元素…

借助Aspose.SVG圖像控件,在 C# 中將圖像轉換為 Base64

Base64 編碼是一種二進制到文本的編碼方案&#xff0c;可有效地將二進制數據轉換為 ASCII 字符&#xff0c;為數據交換提供通用格式。在某些情況下&#xff0c;我們可能需要將JPG或PNG圖像轉換為 Base64 字符串數據。在這篇博文中&#xff0c;我們將學習如何在 C# 中將圖像轉換…