In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the process of using gRPC in Java. In general, it consists of the following three steps
1) define the services provided in the .proto file
2) compile the file using the protocol buffer compiler
3) use gRPC API to create the server and client, and make calls.
Download and install the required software
1) Protocol Buffers
Structured data serialization mechanism
Https://github.com/protocolbuffers/protobuf/releases
Examples of use:
Protoc-- java_out=./ * .proto
2) protoc-gen-grpc-java
Used to generate RPC communication code
Http://jcenter.bintray.com/io/grpc/protoc-gen-grpc-java/
Use example [use Protobuf-Plugin mechanism]:
Protoc--plugin=protoc-gen-grpc-java=protoc-gen-grpc-java-1.19.0-windows-x86_64.exe-- grpc-java_out=./ * .proto uses Maven to build gRPC1) modify pmo.xml UTF-8 3.7.0 1.19.0 io.grpc grpc-netty-shaded ${grpc.version} Io.grpc grpc-protobuf ${grpc.version} io.grpc grpc-stub ${grpc.version} com.google.protobuf protobuf-java ${protobuf.version} com. Google.protobuf protobuf-java-util ${protobuf.version} kr.motd.maven os-maven-plugin 1.6.1 org.xolstice.maven.plugins Protobuf-maven-plugin 0.6.1 False com.google.protobuf:protoc:$ {protobuf.version}: exe:$ {os.detected.classifier} grpc-java io.grpc:protoc-gen-grpc-java:$ {grpc.version}: exe:$ {os.detected.classifier} Compile compile-custom
By default, the plug-in looks for the proto file under the src/main/proto path. Any subfolder under the path will be used as the package path in the proto file.
2) create the proto file (HarLog.proto) syntax = "proto3"; option java_multiple_files = true;option java_package = "com.ultrapower.ioss.proto"; option java_outer_classname = "HarLogProto" under src/main/proto; package com.ultrapower.grpc.har;message HarLogResovleRequest {string url = 1; string file_name = 2; string file_dir = 3; string context = 4;} message HarLogResovleResponse {int32 code = 1;} service HarLogService {rpc ResovleHarLog (HarLogResovleRequest) returns (HarLogResovleResponse) Rpc BatchResovleHarLog (HarLogResovleRequest) returns (HarLogResovleResponse);} 3) compile the file mvn protobuf:compile or mvn compile
The following two folders are generated under target\ generated-sources\ protobuf
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.