ftp怎么设置网站首页广州有哪些做网站的公司
ftp怎么设置网站首页,广州有哪些做网站的公司,建设网站条件,四川微信网站建设公背景#xff1a;由于项目要对接到grcp 的框架#xff0c;然后需要对接老外的东西#xff0c;还有签名和证书刚开始没有接触其实有点懵逼。
gRPC 是由 Google 开发的高性能、开源的远程过程调用#xff08;RPC#xff09;框架。它建立在 HTTP/2 协议之上#xff0c;使用 …背景由于项目要对接到grcp 的框架然后需要对接老外的东西还有签名和证书刚开始没有接触其实有点懵逼。
gRPC 是由 Google 开发的高性能、开源的远程过程调用RPC框架。它建立在 HTTP/2 协议之上使用 Protocol Buffers 作为其接口定义语言IDL。gRPC 被设计为可跨多种环境包括客户端、服务器和各种语言使用支持多种编程语言如 C、C、Java、Go、Python、Ruby、Node.js 等。
gRPC 具有以下特点 性能高效gRPC 使用基于 HTTP/2 的传输协议能够复用连接、多路复用请求、支持头部压缩等特性从而提高了性能。 跨语言支持gRPC 支持多种编程语言使得客户端和服务器可以使用不同的编程语言实现并且它们之间的通信依然高效。 IDL 和自动代码生成gRPC 使用 Protocol Buffers 作为接口定义语言IDL定义服务接口和消息格式并提供了自动生成客户端和服务器代码的工具。 多种调用方式gRPC 支持四种调用方式包括简单 RPC、服务器流式 RPC、客户端流式 RPC 和双向流式 RPC可以根据业务需求选择合适的调用方式。 安全性gRPC 支持 TLS/SSL 加密传输保障通信的安全性。 插件机制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加上这个插件就可以生产代码了 plugingroupIdorg.xolstice.maven.plugins/groupIdartifactIdprotobuf-maven-plugin/artifactIdversion0.6.1/versionconfigurationprotocArtifactcom.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier}/protocArtifactpluginIdgrpc-java/pluginIdpluginArtifactio.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}/pluginArtifact/configurationexecutionsexecutiongoalsgoalcompile/goalgoalcompile-custom/goal/goals/execution/executions/plugin
完整的pom文件 propertiesprotoc.version3.25.2/protoc.versiongrpc.version1.61.1/grpc.versionproject.build.sourceEncodingUTF-8/project.build.sourceEncoding/propertiesdependenciesdependencygroupIdio.grpc/groupIdartifactIdgrpc-protobuf/artifactIdversion${grpc.version}/version/dependencydependencygroupIdio.grpc/groupIdartifactIdgrpc-stub/artifactIdversion${grpc.version}/version/dependencydependencygroupIdio.grpc/groupIdartifactIdgrpc-core/artifactIdversion${grpc.version}/version/dependencydependencygroupIdcom.google.protobuf/groupIdartifactIdprotobuf-java/artifactIdversion3.25.2/version !-- 或者与你的 protoc.version 相匹配的版本 --/dependencydependencygroupIdio.grpc/groupIdartifactIdgrpc-netty/artifactIdversion${grpc.version}/version/dependencydependency!-- necessary for Java 9 --groupIdorg.apache.tomcat/groupIdartifactIdannotations-api/artifactIdversion6.0.53/version/dependency/dependenciesbuildextensionsextensiongroupIdkr.motd.maven/groupIdartifactIdos-maven-plugin/artifactIdversion1.6.2/version/extension/extensionspluginsplugingroupIdorg.xolstice.maven.plugins/groupIdartifactIdprotobuf-maven-plugin/artifactIdversion0.6.1/versionconfigurationprotocArtifactcom.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier}/protocArtifactpluginIdgrpc-java/pluginIdpluginArtifactio.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}/pluginArtifact/configurationexecutionsexecutiongoalsgoalcompile/goalgoalcompile-custom/goal/goals/execution/executions/pluginplugingroupIdorg.apache.maven.plugins/groupIdartifactIdmaven-compiler-plugin/artifactIdversion3.10.1/versionconfigurationsource1.8/sourcetarget1.8/target/configuration/pluginplugingroupIdorg.jfrog.buildinfo/groupIdartifactIdartifactory-maven-plugin/artifactIdversion3.3.0/versioninheritedfalse/inheritedexecutionsexecutionidbuild-info/idgoalsgoalpublish/goal/goalsconfigurationartifactoryincludeEnvVarsfalse/includeEnvVarstimeoutSec60/timeoutSecpropertiesFilepublish.properties/propertiesFile/artifactorypublishercontextUrl${env.ARTIFACTORY_HOST_POM}/contextUrlusername${env.ARTIFACTORY_CCAR_USER}/usernamepassword${env.ARTIFACTORY_CCAR_APIKEY}/passwordexcludePatterns*-tests.jar/excludePatternsrepoKey${CI_PROJECT_NAMESPACE}/repoKeysnapshotRepoKey${CI_PROJECT_NAMESPACE}/snapshotRepoKey/publisherbuildInfobuildName${CI_PROJECT_NAME}/buildNamebuildNumber${CI_PIPELINE_ID}/buildNumberbuildUrl${CI_PROJECT_URL}/buildUrl/buildInfo/configuration/execution/executions/pluginplugingroupIdorg.springframework.boot/groupIdartifactIdspring-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, StreamObserverMistraResponse 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.MethodDescriptorMistraRequest,MistraResponse METHOD_SAY_HELLO getSayHelloMethodHelper();private static volatile io.grpc.MethodDescriptorMistraRequest,MistraResponse getSayHelloMethod;io.grpc.ExperimentalApi(https://github.com/grpc/grpc-java/issues/1901)public static io.grpc.MethodDescriptorMistraRequest,MistraResponse getSayHelloMethod() {return getSayHelloMethodHelper();}private static io.grpc.MethodDescriptorMistraRequest,MistraResponse getSayHelloMethodHelper() {io.grpc.MethodDescriptorMistraRequest, MistraResponse getSayHelloMethod;if ((getSayHelloMethod MistraServiceGrpc.getSayHelloMethod) null) {synchronized (MistraServiceGrpc.class) {if ((getSayHelloMethod MistraServiceGrpc.getSayHelloMethod) null) {MistraServiceGrpc.getSayHelloMethod getSayHelloMethod io.grpc.MethodDescriptor.MistraRequest, MistraResponsenewBuilder().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.StreamObserverMistraResponse responseObserver) {asyncUnimplementedUnaryCall(getSayHelloMethodHelper(), responseObserver);}Overridepublic final io.grpc.ServerServiceDefinition bindService() {return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor()).addMethod(getSayHelloMethodHelper(),asyncUnaryCall(new MethodHandlersMistraRequest,MistraResponse(this, METHODID_SAY_HELLO))).build();}}/*** pre* 声明一个服务名称* /pre*/public static final class MistraServiceStub extends io.grpc.stub.AbstractStubMistraServiceStub {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.StreamObserverMistraResponse responseObserver) {asyncUnaryCall(getChannel().newCall(getSayHelloMethodHelper(), getCallOptions()), request, responseObserver);}}/*** pre* 声明一个服务名称* /pre*/public static final class MistraServiceBlockingStub extends io.grpc.stub.AbstractStubMistraServiceBlockingStub {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.AbstractStubMistraServiceFutureStub {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.ListenableFutureMistraResponse sayHello(MistraRequest request) {return futureUnaryCall(getChannel().newCall(getSayHelloMethodHelper(), getCallOptions()), request);}}private static final int METHODID_SAY_HELLO 0;private static final class MethodHandlersReq, Resp implementsio.grpc.stub.ServerCalls.UnaryMethodReq, Resp,io.grpc.stub.ServerCalls.ServerStreamingMethodReq, Resp,io.grpc.stub.ServerCalls.ClientStreamingMethodReq, Resp,io.grpc.stub.ServerCalls.BidiStreamingMethodReq, Resp {private final MistraServiceImplBase serviceImpl;private final int methodId;MethodHandlers(MistraServiceImplBase serviceImpl, int methodId) {this.serviceImpl serviceImpl;this.methodId methodId;}OverrideSuppressWarnings(unchecked)public void invoke(Req request, io.grpc.stub.StreamObserverResp responseObserver) {switch (methodId) {case METHODID_SAY_HELLO:serviceImpl.sayHello((MistraRequest) request,(io.grpc.stub.StreamObserverMistraResponse) responseObserver);break;default:throw new AssertionError();}}OverrideSuppressWarnings(unchecked)public io.grpc.stub.StreamObserverReq invoke(io.grpc.stub.StreamObserverResp 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.mzph.cn/diannao/89948.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!