gRPC编码初探(java)

背景:gRPC是一个高性能、通用的开源RPC框架,其由Google主要面向移动应用开发并基于HTTP/2协议标准而设计,基于ProtoBuf(Protocol Buffers)序列化协议开发,且支持众多开发语言。gRPC提供了一种简单的方法来精确地定义服务和为iOS、Android和后台支持服务自动生成可靠性很强的客户端功能库。客户端充分利用高级流和链接功能,从而有助于节省带宽、降低的TCP链接次数、节省CPU使用、和电池寿命。 以下初探编码过程:

1、安装插件Protobuf-dt最新版本,我的版本为2.2.1

2、下载protobuf

    找到对应操作系统版本(我的系统为OS)直接解压到某个目录(我的目录为:/Users/peng/protoc-3.0.0-beta-2-osx-x86_64),链接:https://github.com/google/protobuf

 3、新建maven项目,过程省略

 4、在pom.xml文件中添加gRPC的相关依赖  

<dependency><groupId>io.grpc</groupId><artifactId>grpc-all</artifactId><version>0.13.2</version></dependency>

 

    添加maven-protobuf-plugin,在pom.xml中添加以下内容

<build> <extensions> <extension> <groupId>kr.motd.maven</groupId> <artifactId>os-maven-plugin</artifactId> <version>1.4.1.Final</version> </extension> </extensions> <plugins> <plugin> <groupId>org.xolstice.maven.plugins</groupId> <artifactId>protobuf-maven-plugin</artifactId> <version>0.5.0</version> <configuration> <!-- The version of protoc must match protobuf-java. If you don't depend on protobuf-java directly, you will be transitively depending on the protobuf-java version that grpc depends on. --> <protocArtifact>com.google.protobuf:protoc:3.0.0-beta-2:exe:${os.detected.classifier}</protocArtifact> <pluginId>grpc-java</pluginId> <pluginArtifact>io.grpc:protoc-gen-grpc-java:0.13.2:exe:${os.detected.classifier}</pluginArtifact> <protocExecutable>/Users/peng/protoc-3.0.0-beta-2-osx-x86_64/protoc</protocExecutable></configuration> <executions> <execution> <goals> <goal>compile</goal> <goal>compile-custom</goal> </goals> </execution> </executions> </plugin> </plugins> </build> 

注意protocExecutable节点后的目录为第2步中protobuf的安装路径

最终的pom.xml文件如下

<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><groupId>com.mzsg.demo</groupId><artifactId>grpc</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>grpc</name><url>http://maven.apache.org</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>3.8.1</version><scope>test</scope></dependency><dependency><groupId>io.grpc</groupId><artifactId>grpc-all</artifactId><version>0.13.2</version></dependency></dependencies><build> <extensions> <extension> <groupId>kr.motd.maven</groupId> <artifactId>os-maven-plugin</artifactId> <version>1.4.1.Final</version> </extension> </extensions> <plugins> <plugin> <groupId>org.xolstice.maven.plugins</groupId> <artifactId>protobuf-maven-plugin</artifactId> <version>0.5.0</version> <configuration> <!-- The version of protoc must match protobuf-java. If you don't depend on protobuf-java directly, you will be transitively depending on the protobuf-java version that grpc depends on. --> <protocArtifact>com.google.protobuf:protoc:3.0.0-beta-2:exe:${os.detected.classifier}</protocArtifact> <pluginId>grpc-java</pluginId> <pluginArtifact>io.grpc:protoc-gen-grpc-java:0.13.2:exe:${os.detected.classifier}</pluginArtifact> <protocExecutable>/Users/peng/protoc-3.0.0-beta-2-osx-x86_64/protoc</protocExecutable></configuration> <executions> <execution> <goals> <goal>compile</goal> <goal>compile-custom</goal> </goals> </execution> </executions> </plugin> </plugins> </build> 
</project>
View Code

 

5、编写proto文件,描述入参、出参及远程方法

在src/main下面建立proto目录,protobuf-maven-plugin默认会扫描该目录以生成java文件

在proto目录下新建文件,AccountQry.proto,内容为

syntax = "proto3";
package accountService;
option java_package = "com.mzsg.demo.grpc.qryaccount";
option java_outer_classname = "QryAccountProto";//账户查询请求
message AccountQryRequest {//请求流水string requestId = 1;//用户IDstring userId = 2;
}//账户查询响应
message AccountQryResponse {//请求流水string requestId = 1;//返回码,1:成功; -1:失败int32 rc = 2;//错误消息string msg = 3;//账户余额int32 amount = 4;
}/*** 账户操查询服务*/
service QryAccountService {//账户查询方法
  rpc Qry(AccountQryRequest) returns (AccountQryResponse);
}

 

注意:本例用查账户查询作为demo,因为涉及到后面的性能(包括了序列化,反序列化)对比,故不再简单采用Hello world来测试

6、运行maven-generate-source,生成proto对应的java文件

 

生成文件结构生成文件结构

grpc-java下的为方法,java下的为入参出参,将这两个文件copy到com.mzsg.demo.grpc.qryaccount包下

注意:QryAccountServiceGrpc.java文件会提示@Override注解报错,直接删除注解即可,另外生成的代码也不是很简洁,有点无语

QryAccountServiceGrpc.java内容

package com.mzsg.demo.grpc.qryaccount;import static io.grpc.stub.ClientCalls.asyncUnaryCall;
import static io.grpc.stub.ClientCalls.asyncServerStreamingCall;
import static io.grpc.stub.ClientCalls.asyncClientStreamingCall;
import static io.grpc.stub.ClientCalls.asyncBidiStreamingCall;
import static io.grpc.stub.ClientCalls.blockingUnaryCall;
import static io.grpc.stub.ClientCalls.blockingServerStreamingCall;
import static io.grpc.stub.ClientCalls.futureUnaryCall;
import static io.grpc.MethodDescriptor.generateFullMethodName;
import static io.grpc.stub.ServerCalls.asyncUnaryCall;
import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;@javax.annotation.Generated("by gRPC proto compiler")
public class QryAccountServiceGrpc {private QryAccountServiceGrpc() {}public static final String SERVICE_NAME = "accountService.QryAccountService";// Static method descriptors that strictly reflect the proto.
  @io.grpc.ExperimentalApipublic static final io.grpc.MethodDescriptor<com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest,com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse> METHOD_QRY =io.grpc.MethodDescriptor.create(io.grpc.MethodDescriptor.MethodType.UNARY,generateFullMethodName("accountService.QryAccountService", "Qry"),io.grpc.protobuf.ProtoUtils.marshaller(com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest.getDefaultInstance()),io.grpc.protobuf.ProtoUtils.marshaller(com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse.getDefaultInstance()));public static QryAccountServiceStub newStub(io.grpc.Channel channel) {return new QryAccountServiceStub(channel);}public static QryAccountServiceBlockingStub newBlockingStub(io.grpc.Channel channel) {return new QryAccountServiceBlockingStub(channel);}public static QryAccountServiceFutureStub newFutureStub(io.grpc.Channel channel) {return new QryAccountServiceFutureStub(channel);}public static interface QryAccountService {public void qry(com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest request,io.grpc.stub.StreamObserver<com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse> responseObserver);}public static interface QryAccountServiceBlockingClient {public com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse qry(com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest request);}public static interface QryAccountServiceFutureClient {public com.google.common.util.concurrent.ListenableFuture<com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse> qry(com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest request);}public static class QryAccountServiceStub extends io.grpc.stub.AbstractStub<QryAccountServiceStub>implements QryAccountService {private QryAccountServiceStub(io.grpc.Channel channel) {super(channel);}private QryAccountServiceStub(io.grpc.Channel channel,io.grpc.CallOptions callOptions) {super(channel, callOptions);}@java.lang.Overrideprotected QryAccountServiceStub build(io.grpc.Channel channel,io.grpc.CallOptions callOptions) {return new QryAccountServiceStub(channel, callOptions);}public void qry(com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest request,io.grpc.stub.StreamObserver<com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse> responseObserver) {asyncUnaryCall(getChannel().newCall(METHOD_QRY, getCallOptions()), request, responseObserver);}}public static class QryAccountServiceBlockingStub extends io.grpc.stub.AbstractStub<QryAccountServiceBlockingStub>implements QryAccountServiceBlockingClient {private QryAccountServiceBlockingStub(io.grpc.Channel channel) {super(channel);}private QryAccountServiceBlockingStub(io.grpc.Channel channel,io.grpc.CallOptions callOptions) {super(channel, callOptions);}@java.lang.Overrideprotected QryAccountServiceBlockingStub build(io.grpc.Channel channel,io.grpc.CallOptions callOptions) {return new QryAccountServiceBlockingStub(channel, callOptions);}public com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse qry(com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest request) {return blockingUnaryCall(getChannel(), METHOD_QRY, getCallOptions(), request);}}public static class QryAccountServiceFutureStub extends io.grpc.stub.AbstractStub<QryAccountServiceFutureStub>implements QryAccountServiceFutureClient {private QryAccountServiceFutureStub(io.grpc.Channel channel) {super(channel);}private QryAccountServiceFutureStub(io.grpc.Channel channel,io.grpc.CallOptions callOptions) {super(channel, callOptions);}@java.lang.Overrideprotected QryAccountServiceFutureStub build(io.grpc.Channel channel,io.grpc.CallOptions callOptions) {return new QryAccountServiceFutureStub(channel, callOptions);}public com.google.common.util.concurrent.ListenableFuture<com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse> qry(com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest request) {return futureUnaryCall(getChannel().newCall(METHOD_QRY, getCallOptions()), request);}}private static final int METHODID_QRY = 0;private static 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 QryAccountService serviceImpl;private final int methodId;public MethodHandlers(QryAccountService serviceImpl, int methodId) {this.serviceImpl = serviceImpl;this.methodId = methodId;}@java.lang.SuppressWarnings("unchecked")public void invoke(Req request, io.grpc.stub.StreamObserver<Resp> responseObserver) {switch (methodId) {case METHODID_QRY:serviceImpl.qry((com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest) request,(io.grpc.stub.StreamObserver<com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse>) responseObserver);break;default:throw new AssertionError();}}@java.lang.SuppressWarnings("unchecked")public io.grpc.stub.StreamObserver<Req> invoke(io.grpc.stub.StreamObserver<Resp> responseObserver) {switch (methodId) {default:throw new AssertionError();}}}public static io.grpc.ServerServiceDefinition bindService(final QryAccountService serviceImpl) {return io.grpc.ServerServiceDefinition.builder(SERVICE_NAME).addMethod(METHOD_QRY,asyncUnaryCall(new MethodHandlers<com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest,com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse>(serviceImpl, METHODID_QRY))).build();}
}
View Code

QryAccountProto.java文件内容

// Generated by the protocol buffer compiler.  DO NOT EDIT!
// source: AccountQry.protopackage com.mzsg.demo.grpc.qryaccount;public final class QryAccountProto {private QryAccountProto() {}public static void registerAllExtensions(com.google.protobuf.ExtensionRegistry registry) {}public interface AccountQryRequestOrBuilder extends// @@protoc_insertion_point(interface_extends:accountService.AccountQryRequest)
      com.google.protobuf.MessageOrBuilder {/*** <code>optional string requestId = 1;</code>** <pre>*请求流水* </pre>*/java.lang.String getRequestId();/*** <code>optional string requestId = 1;</code>** <pre>*请求流水* </pre>*/com.google.protobuf.ByteStringgetRequestIdBytes();/*** <code>optional string userId = 2;</code>** <pre>*用户ID* </pre>*/java.lang.String getUserId();/*** <code>optional string userId = 2;</code>** <pre>*用户ID* </pre>*/com.google.protobuf.ByteStringgetUserIdBytes();}/*** Protobuf type {@code accountService.AccountQryRequest}** <pre>*账户查询请求* </pre>*/public  static final class AccountQryRequest extendscom.google.protobuf.GeneratedMessage implements// @@protoc_insertion_point(message_implements:accountService.AccountQryRequest)
      AccountQryRequestOrBuilder {// Use AccountQryRequest.newBuilder() to construct.private AccountQryRequest(com.google.protobuf.GeneratedMessage.Builder<?> builder) {super(builder);}private AccountQryRequest() {requestId_ = "";userId_ = "";}@java.lang.Overridepublic final com.google.protobuf.UnknownFieldSetgetUnknownFields() {return com.google.protobuf.UnknownFieldSet.getDefaultInstance();}private AccountQryRequest(com.google.protobuf.CodedInputStream input,com.google.protobuf.ExtensionRegistryLite extensionRegistry) {this();int mutable_bitField0_ = 0;try {boolean done = false;while (!done) {int tag = input.readTag();switch (tag) {case 0:done = true;break;default: {if (!input.skipField(tag)) {done = true;}break;}case 10: {java.lang.String s = input.readStringRequireUtf8();requestId_ = s;break;}case 18: {java.lang.String s = input.readStringRequireUtf8();userId_ = s;break;}}}} catch (com.google.protobuf.InvalidProtocolBufferException e) {throw new RuntimeException(e.setUnfinishedMessage(this));} catch (java.io.IOException e) {throw new RuntimeException(new com.google.protobuf.InvalidProtocolBufferException(e.getMessage()).setUnfinishedMessage(this));} finally {makeExtensionsImmutable();}}public static final com.google.protobuf.Descriptors.DescriptorgetDescriptor() {return com.mzsg.demo.grpc.qryaccount.QryAccountProto.internal_static_accountService_AccountQryRequest_descriptor;}protected com.google.protobuf.GeneratedMessage.FieldAccessorTableinternalGetFieldAccessorTable() {return com.mzsg.demo.grpc.qryaccount.QryAccountProto.internal_static_accountService_AccountQryRequest_fieldAccessorTable.ensureFieldAccessorsInitialized(com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest.class, com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest.Builder.class);}public static final int REQUESTID_FIELD_NUMBER = 1;private volatile java.lang.Object requestId_;/*** <code>optional string requestId = 1;</code>** <pre>*请求流水* </pre>*/public java.lang.String getRequestId() {java.lang.Object ref = requestId_;if (ref instanceof java.lang.String) {return (java.lang.String) ref;} else {com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref;java.lang.String s = bs.toStringUtf8();requestId_ = s;return s;}}/*** <code>optional string requestId = 1;</code>** <pre>*请求流水* </pre>*/public com.google.protobuf.ByteStringgetRequestIdBytes() {java.lang.Object ref = requestId_;if (ref instanceof java.lang.String) {com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref);requestId_ = b;return b;} else {return (com.google.protobuf.ByteString) ref;}}public static final int USERID_FIELD_NUMBER = 2;private volatile java.lang.Object userId_;/*** <code>optional string userId = 2;</code>** <pre>*用户ID* </pre>*/public java.lang.String getUserId() {java.lang.Object ref = userId_;if (ref instanceof java.lang.String) {return (java.lang.String) ref;} else {com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref;java.lang.String s = bs.toStringUtf8();userId_ = s;return s;}}/*** <code>optional string userId = 2;</code>** <pre>*用户ID* </pre>*/public com.google.protobuf.ByteStringgetUserIdBytes() {java.lang.Object ref = userId_;if (ref instanceof java.lang.String) {com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref);userId_ = b;return b;} else {return (com.google.protobuf.ByteString) ref;}}private byte memoizedIsInitialized = -1;public final boolean isInitialized() {byte isInitialized = memoizedIsInitialized;if (isInitialized == 1) return true;if (isInitialized == 0) return false;memoizedIsInitialized = 1;return true;}public void writeTo(com.google.protobuf.CodedOutputStream output)throws java.io.IOException {if (!getRequestIdBytes().isEmpty()) {com.google.protobuf.GeneratedMessage.writeString(output, 1, requestId_);}if (!getUserIdBytes().isEmpty()) {com.google.protobuf.GeneratedMessage.writeString(output, 2, userId_);}}public int getSerializedSize() {int size = memoizedSize;if (size != -1) return size;size = 0;if (!getRequestIdBytes().isEmpty()) {size += com.google.protobuf.GeneratedMessage.computeStringSize(1, requestId_);}if (!getUserIdBytes().isEmpty()) {size += com.google.protobuf.GeneratedMessage.computeStringSize(2, userId_);}memoizedSize = size;return size;}private static final long serialVersionUID = 0L;public static com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest parseFrom(com.google.protobuf.ByteString data)throws com.google.protobuf.InvalidProtocolBufferException {return PARSER.parseFrom(data);}public static com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest parseFrom(com.google.protobuf.ByteString data,com.google.protobuf.ExtensionRegistryLite extensionRegistry)throws com.google.protobuf.InvalidProtocolBufferException {return PARSER.parseFrom(data, extensionRegistry);}public static com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest parseFrom(byte[] data)throws com.google.protobuf.InvalidProtocolBufferException {return PARSER.parseFrom(data);}public static com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest parseFrom(byte[] data,com.google.protobuf.ExtensionRegistryLite extensionRegistry)throws com.google.protobuf.InvalidProtocolBufferException {return PARSER.parseFrom(data, extensionRegistry);}public static com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest parseFrom(java.io.InputStream input)throws java.io.IOException {return PARSER.parseFrom(input);}public static com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest parseFrom(java.io.InputStream input,com.google.protobuf.ExtensionRegistryLite extensionRegistry)throws java.io.IOException {return PARSER.parseFrom(input, extensionRegistry);}public static com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest parseDelimitedFrom(java.io.InputStream input)throws java.io.IOException {return PARSER.parseDelimitedFrom(input);}public static com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest parseDelimitedFrom(java.io.InputStream input,com.google.protobuf.ExtensionRegistryLite extensionRegistry)throws java.io.IOException {return PARSER.parseDelimitedFrom(input, extensionRegistry);}public static com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest parseFrom(com.google.protobuf.CodedInputStream input)throws java.io.IOException {return PARSER.parseFrom(input);}public static com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest parseFrom(com.google.protobuf.CodedInputStream input,com.google.protobuf.ExtensionRegistryLite extensionRegistry)throws java.io.IOException {return PARSER.parseFrom(input, extensionRegistry);}public Builder newBuilderForType() { return newBuilder(); }public static Builder newBuilder() {return DEFAULT_INSTANCE.toBuilder();}public static Builder newBuilder(com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest prototype) {return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);}public Builder toBuilder() {return this == DEFAULT_INSTANCE? new Builder() : new Builder().mergeFrom(this);}@java.lang.Overrideprotected Builder newBuilderForType(com.google.protobuf.GeneratedMessage.BuilderParent parent) {Builder builder = new Builder(parent);return builder;}/*** Protobuf type {@code accountService.AccountQryRequest}** <pre>*账户查询请求* </pre>*/public static final class Builder extendscom.google.protobuf.GeneratedMessage.Builder<Builder> implements// @@protoc_insertion_point(builder_implements:accountService.AccountQryRequest)
        com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequestOrBuilder {public static final com.google.protobuf.Descriptors.DescriptorgetDescriptor() {return com.mzsg.demo.grpc.qryaccount.QryAccountProto.internal_static_accountService_AccountQryRequest_descriptor;}protected com.google.protobuf.GeneratedMessage.FieldAccessorTableinternalGetFieldAccessorTable() {return com.mzsg.demo.grpc.qryaccount.QryAccountProto.internal_static_accountService_AccountQryRequest_fieldAccessorTable.ensureFieldAccessorsInitialized(com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest.class, com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest.Builder.class);}// Construct using com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest.newBuilder()private Builder() {maybeForceBuilderInitialization();}private Builder(com.google.protobuf.GeneratedMessage.BuilderParent parent) {super(parent);maybeForceBuilderInitialization();}private void maybeForceBuilderInitialization() {if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {}}public Builder clear() {super.clear();requestId_ = "";userId_ = "";return this;}public com.google.protobuf.Descriptors.DescriptorgetDescriptorForType() {return com.mzsg.demo.grpc.qryaccount.QryAccountProto.internal_static_accountService_AccountQryRequest_descriptor;}public com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest getDefaultInstanceForType() {return com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest.getDefaultInstance();}public com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest build() {com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest result = buildPartial();if (!result.isInitialized()) {throw newUninitializedMessageException(result);}return result;}public com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest buildPartial() {com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest result = new com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest(this);result.requestId_ = requestId_;result.userId_ = userId_;onBuilt();return result;}public Builder mergeFrom(com.google.protobuf.Message other) {if (other instanceof com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest) {return mergeFrom((com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest)other);} else {super.mergeFrom(other);return this;}}public Builder mergeFrom(com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest other) {if (other == com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest.getDefaultInstance()) return this;if (!other.getRequestId().isEmpty()) {requestId_ = other.requestId_;onChanged();}if (!other.getUserId().isEmpty()) {userId_ = other.userId_;onChanged();}onChanged();return this;}public final boolean isInitialized() {return true;}public Builder mergeFrom(com.google.protobuf.CodedInputStream input,com.google.protobuf.ExtensionRegistryLite extensionRegistry)throws java.io.IOException {com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest parsedMessage = null;try {parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);} catch (com.google.protobuf.InvalidProtocolBufferException e) {parsedMessage = (com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest) e.getUnfinishedMessage();throw e;} finally {if (parsedMessage != null) {mergeFrom(parsedMessage);}}return this;}private java.lang.Object requestId_ = "";/*** <code>optional string requestId = 1;</code>** <pre>*请求流水* </pre>*/public java.lang.String getRequestId() {java.lang.Object ref = requestId_;if (!(ref instanceof java.lang.String)) {com.google.protobuf.ByteString bs =(com.google.protobuf.ByteString) ref;java.lang.String s = bs.toStringUtf8();requestId_ = s;return s;} else {return (java.lang.String) ref;}}/*** <code>optional string requestId = 1;</code>** <pre>*请求流水* </pre>*/public com.google.protobuf.ByteStringgetRequestIdBytes() {java.lang.Object ref = requestId_;if (ref instanceof String) {com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref);requestId_ = b;return b;} else {return (com.google.protobuf.ByteString) ref;}}/*** <code>optional string requestId = 1;</code>** <pre>*请求流水* </pre>*/public Builder setRequestId(java.lang.String value) {if (value == null) {throw new NullPointerException();}requestId_ = value;onChanged();return this;}/*** <code>optional string requestId = 1;</code>** <pre>*请求流水* </pre>*/public Builder clearRequestId() {requestId_ = getDefaultInstance().getRequestId();onChanged();return this;}/*** <code>optional string requestId = 1;</code>** <pre>*请求流水* </pre>*/public Builder setRequestIdBytes(com.google.protobuf.ByteString value) {if (value == null) {throw new NullPointerException();}checkByteStringIsUtf8(value);requestId_ = value;onChanged();return this;}private java.lang.Object userId_ = "";/*** <code>optional string userId = 2;</code>** <pre>*用户ID* </pre>*/public java.lang.String getUserId() {java.lang.Object ref = userId_;if (!(ref instanceof java.lang.String)) {com.google.protobuf.ByteString bs =(com.google.protobuf.ByteString) ref;java.lang.String s = bs.toStringUtf8();userId_ = s;return s;} else {return (java.lang.String) ref;}}/*** <code>optional string userId = 2;</code>** <pre>*用户ID* </pre>*/public com.google.protobuf.ByteStringgetUserIdBytes() {java.lang.Object ref = userId_;if (ref instanceof String) {com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref);userId_ = b;return b;} else {return (com.google.protobuf.ByteString) ref;}}/*** <code>optional string userId = 2;</code>** <pre>*用户ID* </pre>*/public Builder setUserId(java.lang.String value) {if (value == null) {throw new NullPointerException();}userId_ = value;onChanged();return this;}/*** <code>optional string userId = 2;</code>** <pre>*用户ID* </pre>*/public Builder clearUserId() {userId_ = getDefaultInstance().getUserId();onChanged();return this;}/*** <code>optional string userId = 2;</code>** <pre>*用户ID* </pre>*/public Builder setUserIdBytes(com.google.protobuf.ByteString value) {if (value == null) {throw new NullPointerException();}checkByteStringIsUtf8(value);userId_ = value;onChanged();return this;}public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) {return this;}public final Builder mergeUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) {return this;}// @@protoc_insertion_point(builder_scope:accountService.AccountQryRequest)
    }// @@protoc_insertion_point(class_scope:accountService.AccountQryRequest)private static final com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest DEFAULT_INSTANCE;static {DEFAULT_INSTANCE = new com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest();}public static com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest getDefaultInstance() {return DEFAULT_INSTANCE;}private static final com.google.protobuf.Parser<AccountQryRequest>PARSER = new com.google.protobuf.AbstractParser<AccountQryRequest>() {public AccountQryRequest parsePartialFrom(com.google.protobuf.CodedInputStream input,com.google.protobuf.ExtensionRegistryLite extensionRegistry)throws com.google.protobuf.InvalidProtocolBufferException {try {return new AccountQryRequest(input, extensionRegistry);} catch (RuntimeException e) {if (e.getCause() instanceofcom.google.protobuf.InvalidProtocolBufferException) {throw (com.google.protobuf.InvalidProtocolBufferException)e.getCause();}throw e;}}};public static com.google.protobuf.Parser<AccountQryRequest> parser() {return PARSER;}@java.lang.Overridepublic com.google.protobuf.Parser<AccountQryRequest> getParserForType() {return PARSER;}public com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest getDefaultInstanceForType() {return DEFAULT_INSTANCE;}}public interface AccountQryResponseOrBuilder extends// @@protoc_insertion_point(interface_extends:accountService.AccountQryResponse)
      com.google.protobuf.MessageOrBuilder {/*** <code>optional string requestId = 1;</code>** <pre>*请求流水* </pre>*/java.lang.String getRequestId();/*** <code>optional string requestId = 1;</code>** <pre>*请求流水* </pre>*/com.google.protobuf.ByteStringgetRequestIdBytes();/*** <code>optional int32 rc = 2;</code>** <pre>*返回码,1:成功; -1:失败* </pre>*/int getRc();/*** <code>optional string msg = 3;</code>** <pre>*错误消息* </pre>*/java.lang.String getMsg();/*** <code>optional string msg = 3;</code>** <pre>*错误消息* </pre>*/com.google.protobuf.ByteStringgetMsgBytes();/*** <code>optional int32 amount = 4;</code>** <pre>*账户余额* </pre>*/int getAmount();}/*** Protobuf type {@code accountService.AccountQryResponse}** <pre>*账户查询响应* </pre>*/public  static final class AccountQryResponse extendscom.google.protobuf.GeneratedMessage implements// @@protoc_insertion_point(message_implements:accountService.AccountQryResponse)
      AccountQryResponseOrBuilder {// Use AccountQryResponse.newBuilder() to construct.private AccountQryResponse(com.google.protobuf.GeneratedMessage.Builder<?> builder) {super(builder);}private AccountQryResponse() {requestId_ = "";rc_ = 0;msg_ = "";amount_ = 0;}@java.lang.Overridepublic final com.google.protobuf.UnknownFieldSetgetUnknownFields() {return com.google.protobuf.UnknownFieldSet.getDefaultInstance();}private AccountQryResponse(com.google.protobuf.CodedInputStream input,com.google.protobuf.ExtensionRegistryLite extensionRegistry) {this();int mutable_bitField0_ = 0;try {boolean done = false;while (!done) {int tag = input.readTag();switch (tag) {case 0:done = true;break;default: {if (!input.skipField(tag)) {done = true;}break;}case 10: {java.lang.String s = input.readStringRequireUtf8();requestId_ = s;break;}case 16: {rc_ = input.readInt32();break;}case 26: {java.lang.String s = input.readStringRequireUtf8();msg_ = s;break;}case 32: {amount_ = input.readInt32();break;}}}} catch (com.google.protobuf.InvalidProtocolBufferException e) {throw new RuntimeException(e.setUnfinishedMessage(this));} catch (java.io.IOException e) {throw new RuntimeException(new com.google.protobuf.InvalidProtocolBufferException(e.getMessage()).setUnfinishedMessage(this));} finally {makeExtensionsImmutable();}}public static final com.google.protobuf.Descriptors.DescriptorgetDescriptor() {return com.mzsg.demo.grpc.qryaccount.QryAccountProto.internal_static_accountService_AccountQryResponse_descriptor;}protected com.google.protobuf.GeneratedMessage.FieldAccessorTableinternalGetFieldAccessorTable() {return com.mzsg.demo.grpc.qryaccount.QryAccountProto.internal_static_accountService_AccountQryResponse_fieldAccessorTable.ensureFieldAccessorsInitialized(com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse.class, com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse.Builder.class);}public static final int REQUESTID_FIELD_NUMBER = 1;private volatile java.lang.Object requestId_;/*** <code>optional string requestId = 1;</code>** <pre>*请求流水* </pre>*/public java.lang.String getRequestId() {java.lang.Object ref = requestId_;if (ref instanceof java.lang.String) {return (java.lang.String) ref;} else {com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref;java.lang.String s = bs.toStringUtf8();requestId_ = s;return s;}}/*** <code>optional string requestId = 1;</code>** <pre>*请求流水* </pre>*/public com.google.protobuf.ByteStringgetRequestIdBytes() {java.lang.Object ref = requestId_;if (ref instanceof java.lang.String) {com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref);requestId_ = b;return b;} else {return (com.google.protobuf.ByteString) ref;}}public static final int RC_FIELD_NUMBER = 2;private int rc_;/*** <code>optional int32 rc = 2;</code>** <pre>*返回码,1:成功; -1:失败* </pre>*/public int getRc() {return rc_;}public static final int MSG_FIELD_NUMBER = 3;private volatile java.lang.Object msg_;/*** <code>optional string msg = 3;</code>** <pre>*错误消息* </pre>*/public java.lang.String getMsg() {java.lang.Object ref = msg_;if (ref instanceof java.lang.String) {return (java.lang.String) ref;} else {com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref;java.lang.String s = bs.toStringUtf8();msg_ = s;return s;}}/*** <code>optional string msg = 3;</code>** <pre>*错误消息* </pre>*/public com.google.protobuf.ByteStringgetMsgBytes() {java.lang.Object ref = msg_;if (ref instanceof java.lang.String) {com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref);msg_ = b;return b;} else {return (com.google.protobuf.ByteString) ref;}}public static final int AMOUNT_FIELD_NUMBER = 4;private int amount_;/*** <code>optional int32 amount = 4;</code>** <pre>*账户余额* </pre>*/public int getAmount() {return amount_;}private byte memoizedIsInitialized = -1;public final boolean isInitialized() {byte isInitialized = memoizedIsInitialized;if (isInitialized == 1) return true;if (isInitialized == 0) return false;memoizedIsInitialized = 1;return true;}public void writeTo(com.google.protobuf.CodedOutputStream output)throws java.io.IOException {if (!getRequestIdBytes().isEmpty()) {com.google.protobuf.GeneratedMessage.writeString(output, 1, requestId_);}if (rc_ != 0) {output.writeInt32(2, rc_);}if (!getMsgBytes().isEmpty()) {com.google.protobuf.GeneratedMessage.writeString(output, 3, msg_);}if (amount_ != 0) {output.writeInt32(4, amount_);}}public int getSerializedSize() {int size = memoizedSize;if (size != -1) return size;size = 0;if (!getRequestIdBytes().isEmpty()) {size += com.google.protobuf.GeneratedMessage.computeStringSize(1, requestId_);}if (rc_ != 0) {size += com.google.protobuf.CodedOutputStream.computeInt32Size(2, rc_);}if (!getMsgBytes().isEmpty()) {size += com.google.protobuf.GeneratedMessage.computeStringSize(3, msg_);}if (amount_ != 0) {size += com.google.protobuf.CodedOutputStream.computeInt32Size(4, amount_);}memoizedSize = size;return size;}private static final long serialVersionUID = 0L;public static com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse parseFrom(com.google.protobuf.ByteString data)throws com.google.protobuf.InvalidProtocolBufferException {return PARSER.parseFrom(data);}public static com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse parseFrom(com.google.protobuf.ByteString data,com.google.protobuf.ExtensionRegistryLite extensionRegistry)throws com.google.protobuf.InvalidProtocolBufferException {return PARSER.parseFrom(data, extensionRegistry);}public static com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse parseFrom(byte[] data)throws com.google.protobuf.InvalidProtocolBufferException {return PARSER.parseFrom(data);}public static com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse parseFrom(byte[] data,com.google.protobuf.ExtensionRegistryLite extensionRegistry)throws com.google.protobuf.InvalidProtocolBufferException {return PARSER.parseFrom(data, extensionRegistry);}public static com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse parseFrom(java.io.InputStream input)throws java.io.IOException {return PARSER.parseFrom(input);}public static com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse parseFrom(java.io.InputStream input,com.google.protobuf.ExtensionRegistryLite extensionRegistry)throws java.io.IOException {return PARSER.parseFrom(input, extensionRegistry);}public static com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse parseDelimitedFrom(java.io.InputStream input)throws java.io.IOException {return PARSER.parseDelimitedFrom(input);}public static com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse parseDelimitedFrom(java.io.InputStream input,com.google.protobuf.ExtensionRegistryLite extensionRegistry)throws java.io.IOException {return PARSER.parseDelimitedFrom(input, extensionRegistry);}public static com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse parseFrom(com.google.protobuf.CodedInputStream input)throws java.io.IOException {return PARSER.parseFrom(input);}public static com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse parseFrom(com.google.protobuf.CodedInputStream input,com.google.protobuf.ExtensionRegistryLite extensionRegistry)throws java.io.IOException {return PARSER.parseFrom(input, extensionRegistry);}public Builder newBuilderForType() { return newBuilder(); }public static Builder newBuilder() {return DEFAULT_INSTANCE.toBuilder();}public static Builder newBuilder(com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse prototype) {return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);}public Builder toBuilder() {return this == DEFAULT_INSTANCE? new Builder() : new Builder().mergeFrom(this);}@java.lang.Overrideprotected Builder newBuilderForType(com.google.protobuf.GeneratedMessage.BuilderParent parent) {Builder builder = new Builder(parent);return builder;}/*** Protobuf type {@code accountService.AccountQryResponse}** <pre>*账户查询响应* </pre>*/public static final class Builder extendscom.google.protobuf.GeneratedMessage.Builder<Builder> implements// @@protoc_insertion_point(builder_implements:accountService.AccountQryResponse)
        com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponseOrBuilder {public static final com.google.protobuf.Descriptors.DescriptorgetDescriptor() {return com.mzsg.demo.grpc.qryaccount.QryAccountProto.internal_static_accountService_AccountQryResponse_descriptor;}protected com.google.protobuf.GeneratedMessage.FieldAccessorTableinternalGetFieldAccessorTable() {return com.mzsg.demo.grpc.qryaccount.QryAccountProto.internal_static_accountService_AccountQryResponse_fieldAccessorTable.ensureFieldAccessorsInitialized(com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse.class, com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse.Builder.class);}// Construct using com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse.newBuilder()private Builder() {maybeForceBuilderInitialization();}private Builder(com.google.protobuf.GeneratedMessage.BuilderParent parent) {super(parent);maybeForceBuilderInitialization();}private void maybeForceBuilderInitialization() {if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {}}public Builder clear() {super.clear();requestId_ = "";rc_ = 0;msg_ = "";amount_ = 0;return this;}public com.google.protobuf.Descriptors.DescriptorgetDescriptorForType() {return com.mzsg.demo.grpc.qryaccount.QryAccountProto.internal_static_accountService_AccountQryResponse_descriptor;}public com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse getDefaultInstanceForType() {return com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse.getDefaultInstance();}public com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse build() {com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse result = buildPartial();if (!result.isInitialized()) {throw newUninitializedMessageException(result);}return result;}public com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse buildPartial() {com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse result = new com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse(this);result.requestId_ = requestId_;result.rc_ = rc_;result.msg_ = msg_;result.amount_ = amount_;onBuilt();return result;}public Builder mergeFrom(com.google.protobuf.Message other) {if (other instanceof com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse) {return mergeFrom((com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse)other);} else {super.mergeFrom(other);return this;}}public Builder mergeFrom(com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse other) {if (other == com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse.getDefaultInstance()) return this;if (!other.getRequestId().isEmpty()) {requestId_ = other.requestId_;onChanged();}if (other.getRc() != 0) {setRc(other.getRc());}if (!other.getMsg().isEmpty()) {msg_ = other.msg_;onChanged();}if (other.getAmount() != 0) {setAmount(other.getAmount());}onChanged();return this;}public final boolean isInitialized() {return true;}public Builder mergeFrom(com.google.protobuf.CodedInputStream input,com.google.protobuf.ExtensionRegistryLite extensionRegistry)throws java.io.IOException {com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse parsedMessage = null;try {parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);} catch (com.google.protobuf.InvalidProtocolBufferException e) {parsedMessage = (com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse) e.getUnfinishedMessage();throw e;} finally {if (parsedMessage != null) {mergeFrom(parsedMessage);}}return this;}private java.lang.Object requestId_ = "";/*** <code>optional string requestId = 1;</code>** <pre>*请求流水* </pre>*/public java.lang.String getRequestId() {java.lang.Object ref = requestId_;if (!(ref instanceof java.lang.String)) {com.google.protobuf.ByteString bs =(com.google.protobuf.ByteString) ref;java.lang.String s = bs.toStringUtf8();requestId_ = s;return s;} else {return (java.lang.String) ref;}}/*** <code>optional string requestId = 1;</code>** <pre>*请求流水* </pre>*/public com.google.protobuf.ByteStringgetRequestIdBytes() {java.lang.Object ref = requestId_;if (ref instanceof String) {com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref);requestId_ = b;return b;} else {return (com.google.protobuf.ByteString) ref;}}/*** <code>optional string requestId = 1;</code>** <pre>*请求流水* </pre>*/public Builder setRequestId(java.lang.String value) {if (value == null) {throw new NullPointerException();}requestId_ = value;onChanged();return this;}/*** <code>optional string requestId = 1;</code>** <pre>*请求流水* </pre>*/public Builder clearRequestId() {requestId_ = getDefaultInstance().getRequestId();onChanged();return this;}/*** <code>optional string requestId = 1;</code>** <pre>*请求流水* </pre>*/public Builder setRequestIdBytes(com.google.protobuf.ByteString value) {if (value == null) {throw new NullPointerException();}checkByteStringIsUtf8(value);requestId_ = value;onChanged();return this;}private int rc_ ;/*** <code>optional int32 rc = 2;</code>** <pre>*返回码,1:成功; -1:失败* </pre>*/public int getRc() {return rc_;}/*** <code>optional int32 rc = 2;</code>** <pre>*返回码,1:成功; -1:失败* </pre>*/public Builder setRc(int value) {rc_ = value;onChanged();return this;}/*** <code>optional int32 rc = 2;</code>** <pre>*返回码,1:成功; -1:失败* </pre>*/public Builder clearRc() {rc_ = 0;onChanged();return this;}private java.lang.Object msg_ = "";/*** <code>optional string msg = 3;</code>** <pre>*错误消息* </pre>*/public java.lang.String getMsg() {java.lang.Object ref = msg_;if (!(ref instanceof java.lang.String)) {com.google.protobuf.ByteString bs =(com.google.protobuf.ByteString) ref;java.lang.String s = bs.toStringUtf8();msg_ = s;return s;} else {return (java.lang.String) ref;}}/*** <code>optional string msg = 3;</code>** <pre>*错误消息* </pre>*/public com.google.protobuf.ByteStringgetMsgBytes() {java.lang.Object ref = msg_;if (ref instanceof String) {com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref);msg_ = b;return b;} else {return (com.google.protobuf.ByteString) ref;}}/*** <code>optional string msg = 3;</code>** <pre>*错误消息* </pre>*/public Builder setMsg(java.lang.String value) {if (value == null) {throw new NullPointerException();}msg_ = value;onChanged();return this;}/*** <code>optional string msg = 3;</code>** <pre>*错误消息* </pre>*/public Builder clearMsg() {msg_ = getDefaultInstance().getMsg();onChanged();return this;}/*** <code>optional string msg = 3;</code>** <pre>*错误消息* </pre>*/public Builder setMsgBytes(com.google.protobuf.ByteString value) {if (value == null) {throw new NullPointerException();}checkByteStringIsUtf8(value);msg_ = value;onChanged();return this;}private int amount_ ;/*** <code>optional int32 amount = 4;</code>** <pre>*账户余额* </pre>*/public int getAmount() {return amount_;}/*** <code>optional int32 amount = 4;</code>** <pre>*账户余额* </pre>*/public Builder setAmount(int value) {amount_ = value;onChanged();return this;}/*** <code>optional int32 amount = 4;</code>** <pre>*账户余额* </pre>*/public Builder clearAmount() {amount_ = 0;onChanged();return this;}public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) {return this;}public final Builder mergeUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) {return this;}// @@protoc_insertion_point(builder_scope:accountService.AccountQryResponse)
    }// @@protoc_insertion_point(class_scope:accountService.AccountQryResponse)private static final com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse DEFAULT_INSTANCE;static {DEFAULT_INSTANCE = new com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse();}public static com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse getDefaultInstance() {return DEFAULT_INSTANCE;}private static final com.google.protobuf.Parser<AccountQryResponse>PARSER = new com.google.protobuf.AbstractParser<AccountQryResponse>() {public AccountQryResponse parsePartialFrom(com.google.protobuf.CodedInputStream input,com.google.protobuf.ExtensionRegistryLite extensionRegistry)throws com.google.protobuf.InvalidProtocolBufferException {try {return new AccountQryResponse(input, extensionRegistry);} catch (RuntimeException e) {if (e.getCause() instanceofcom.google.protobuf.InvalidProtocolBufferException) {throw (com.google.protobuf.InvalidProtocolBufferException)e.getCause();}throw e;}}};public static com.google.protobuf.Parser<AccountQryResponse> parser() {return PARSER;}@java.lang.Overridepublic com.google.protobuf.Parser<AccountQryResponse> getParserForType() {return PARSER;}public com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse getDefaultInstanceForType() {return DEFAULT_INSTANCE;}}private static com.google.protobuf.Descriptors.Descriptorinternal_static_accountService_AccountQryRequest_descriptor;private staticcom.google.protobuf.GeneratedMessage.FieldAccessorTableinternal_static_accountService_AccountQryRequest_fieldAccessorTable;private static com.google.protobuf.Descriptors.Descriptorinternal_static_accountService_AccountQryResponse_descriptor;private staticcom.google.protobuf.GeneratedMessage.FieldAccessorTableinternal_static_accountService_AccountQryResponse_fieldAccessorTable;public static com.google.protobuf.Descriptors.FileDescriptorgetDescriptor() {return descriptor;}private static com.google.protobuf.Descriptors.FileDescriptordescriptor;static {java.lang.String[] descriptorData = {"\n\020AccountQry.proto\022\016accountService\"6\n\021Ac" +"countQryRequest\022\021\n\trequestId\030\001 \001(\t\022\016\n\006us" +"erId\030\002 \001(\t\"P\n\022AccountQryResponse\022\021\n\trequ" +"estId\030\001 \001(\t\022\n\n\002rc\030\002 \001(\005\022\013\n\003msg\030\003 \001(\t\022\016\n\006" +"amount\030\004 \001(\0052a\n\021QryAccountService\022L\n\003Qry" +"\022!.accountService.AccountQryRequest\032\".ac" +"countService.AccountQryResponseB0\n\035com.m" +"zsg.demo.grpc.qryaccountB\017QryAccountProt" +"ob\006proto3"};com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =new com.google.protobuf.Descriptors.FileDescriptor.    InternalDescriptorAssigner() {public com.google.protobuf.ExtensionRegistry assignDescriptors(com.google.protobuf.Descriptors.FileDescriptor root) {descriptor = root;return null;}};com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom(descriptorData,new com.google.protobuf.Descriptors.FileDescriptor[] {}, assigner);internal_static_accountService_AccountQryRequest_descriptor =getDescriptor().getMessageTypes().get(0);internal_static_accountService_AccountQryRequest_fieldAccessorTable = newcom.google.protobuf.GeneratedMessage.FieldAccessorTable(internal_static_accountService_AccountQryRequest_descriptor,new java.lang.String[] { "RequestId", "UserId", });internal_static_accountService_AccountQryResponse_descriptor =getDescriptor().getMessageTypes().get(1);internal_static_accountService_AccountQryResponse_fieldAccessorTable = newcom.google.protobuf.GeneratedMessage.FieldAccessorTable(internal_static_accountService_AccountQryResponse_descriptor,new java.lang.String[] { "RequestId", "Rc", "Msg", "Amount", });}// @@protoc_insertion_point(outer_class_scope)
}7、编写接口实现类QryAccountServiceImpl.javapackage com.mzsg.demo.grpc.qryaccount.impl;import com.mzsg.demo.grpc.qryaccount.QryAccountProto;
import com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest;
import com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse;
import com.mzsg.demo.grpc.qryaccount.QryAccountServiceGrpc.QryAccountService;import io.grpc.stub.StreamObserver;public class QryAccountServiceImpl implements QryAccountService {public void qry(AccountQryRequest request, StreamObserver<AccountQryResponse> responseObserver) {System.out.println("qry " + request.getUserId());AccountQryResponse response = QryAccountProto.AccountQryResponse.newBuilder().setRc(1).setAmount(666).build();responseObserver.onNext(response);responseObserver.onCompleted();}
}
View Code

 

7、编写接口实现类QryAccountServiceImpl.java

 
package com.mzsg.demo.grpc.qryaccount.impl;import com.mzsg.demo.grpc.qryaccount.QryAccountProto;
import com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest;
import com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse;
import com.mzsg.demo.grpc.qryaccount.QryAccountServiceGrpc.QryAccountService;import io.grpc.stub.StreamObserver;public class QryAccountServiceImpl implements QryAccountService {public void qry(AccountQryRequest request, StreamObserver<AccountQryResponse> responseObserver) {System.out.println("qry " + request.getUserId());AccountQryResponse response = QryAccountProto.AccountQryResponse.newBuilder().setRc(1).setAmount(666).build();responseObserver.onNext(response);responseObserver.onCompleted();}
}

8、编码Server端代码Server.java

 

package com.mzsg.demo.grpc;import java.io.IOException;import com.mzsg.demo.grpc.qryaccount.QryAccountServiceGrpc;
import com.mzsg.demo.grpc.qryaccount.impl.QryAccountServiceImpl;public class Server {private static int port = 8883;private static io.grpc.Server server;public void run() {QryAccountServiceGrpc.QryAccountService modifyAccountServiceImpl = new QryAccountServiceImpl();server = io.grpc.ServerBuilder.forPort(port).addService(QryAccountServiceGrpc.bindService(modifyAccountServiceImpl)).build();try {server.start();System.out.println("Server start success on port:" + port);server.awaitTermination();} catch (IOException e) {e.printStackTrace();} catch (InterruptedException e) {e.printStackTrace();}}public static void main(String[] args) {Server server = new Server();server.run();}
}

 

9、编码Client端代码Client.java

package com.mzsg.demo.grpc;import java.io.FileNotFoundException;
import java.io.IOException;import com.mzsg.demo.grpc.qryaccount.QryAccountProto;
import com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryRequest;
import com.mzsg.demo.grpc.qryaccount.QryAccountProto.AccountQryResponse;
import com.mzsg.demo.grpc.qryaccount.QryAccountServiceGrpc;
import com.mzsg.demo.grpc.qryaccount.QryAccountServiceGrpc.QryAccountServiceBlockingStub;import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;public class Client {public static void main( String[] args ) throws FileNotFoundException, IOException{AccountQryRequest request = QryAccountProto.AccountQryRequest.newBuilder().setUserId("20012").setRequestId("123").build();ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 8883).usePlaintext(true).build();QryAccountServiceBlockingStub stub = QryAccountServiceGrpc.newBlockingStub(channel);for (int j = 0; j < 20; j++) {long start = System.currentTimeMillis();for(int i=0; i<10000; i++){AccountQryResponse rsp = stub.qry(request);//System.out.println(rsp);
                }System.out.println(System.currentTimeMillis() - start + " MS");}}
}

 

10、运行Server.java,再运行Client.java

          简单性能对比(每万次调用消耗时间比):

  实现  时间(毫秒)  备注
  HTTP接口13000  springboot+json,客户端采用HttpClient  
  Google Grpc  2100  本demo
  Facebook swift(Thrift)  1500  Thrift实现

转载于:https://www.cnblogs.com/mzsg/p/5643367.html

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

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

相关文章

WPF 基础控件之 RadioButton 样式

其他基础控件1.Window2.Button3.CheckBox4.ComboBox5.DataGrid 6.DatePicker7.Expander8.GroupBox9.ListBox10.ListView11.Menu12.PasswordBox13.TextBox14.ProgressBarRadioButton 实现下面的效果1&#xff09;RadioButton来实现动画&#xff1b;Border嵌套 Ellipse并设置Sca…

《看聊天记录都学不会C#?太菜了吧》(6)多晦涩的专业术语原来都会那么简单

本系列文章将会以通俗易懂的对话方式进行教学&#xff0c;对话中将涵盖了新手在学习中的一般问题。此系列将会持续更新&#xff0c;包括别的语言以及实战都将使用对话的方式进行教学&#xff0c;基础编程语言教学适用于零基础小白&#xff0c;之后实战课程也将会逐步更新。 若…

SQLServer2008-镜像数据库实施手册(双机)SQL-Server2014同样适用

SQL Server2008R2-镜像数据库实施手册(双机)SQL Server2014同样适用 一、配置主备机 1、 服务器基本信息 主机名称为&#xff1a;HOST_A&#xff0c;IP地址为&#xff1a;192.168.1.155 备机名称为&#xff1a;HOST_B&#xff0c;IP地址为&#xff1a;192.168.1.156 二、主备实…

一万字一篇文20分钟学会C语言和Python,十四年编程经验老鸟传授经验之道

前言 昨天在直播中有粉丝问我如何快速的对编程语言入门&#xff0c;我想这个问题是有必要让大家知道的&#xff0c;相必也有很多新手对于如何快速完成编程语言的入门学习很感兴趣&#xff0c;本篇文将会使用 C 语言以及 Python 为例&#xff0c;做出对比&#xff0c;让大家对编…

【Python可视化】Windows 10系统上Pyecharts安装教程

简单的Python库&#xff0c;如Numpy&#xff0c;可以直接在PyCharm中自动下载并安装。 同添加Python环境变量一样&#xff0c;需要先添加pip环境变量。pip位于C:\Python27\ArcGIS10.8\Scripts路径下。 WinR→cmd&#xff1a; 安装完成&#xff01;

使用.Net分析.Net达人挑战赛参与情况

背景C#是我2012年在大学课程中接触的&#xff0c;.NET Framework 我也一直使用至今。从2014年.NET 开源&#xff0c;2019年发布.NET Core 3 的时候&#xff0c;公司刚好有 Nvidia Jetson 平台 Linux 嵌入式设备的开发任务&#xff0c;.NET 又刚是适用于 Windows, Linux, 和 mac…

十分钟如何学会C语言?掌握规律举一反三考试提50分!

前言 上周写了一篇 20 分钟学会 C 语言与Python的文章——《一万字一篇文20分钟学会C语言和Python&#xff0c;十四年编程经验老鸟传授经验之道》&#xff0c;之后见粉丝转了一个话题“十分钟如何学会C语言”&#xff0c;我就在想是否能够十分钟呢&#xff1f;答案是可以的&am…

c语言在win8系统不兼容,Win8系统中存在不兼容软件如何解决?

最近有刚升级Win8系统的用户反映&#xff0c;FastStone Capture截图软件在Win7系统中可以兼容&#xff0c;正常打开&#xff0c;可是在Win8系统中就不能兼容了&#xff0c;这让用户非常烦恼。那么&#xff0c;Win8系统中存在不兼容软件如何解决呢&#xff1f;下面&#xff0c;我…

Python 3.6出现报错解决方案:No Python 3.6 installation was detected,无法卸载Python

卸载Python 3.6时错误提示&#xff0c;No Python 3.6 installation was detected。 解决办法是&#xff0c;先右键→更改→Repair。 然后再卸载&#xff0c;完成&#xff01;

MASA Auth - 权限设计

权限术语Subject&#xff1a;用户&#xff0c;用户组Action&#xff1a;对Object的操作&#xff0c;如增删改查等Object&#xff1a;权限作用的对象&#xff0c;也可以理解为资源Effect&#xff1a;规则的作用&#xff0c;如允许&#xff0c;拒绝Condition&#xff1a;生效条件…

【必懂】C语言水仙花数题解

若是大一学子或者是真心想学习刚入门的小伙伴可以私聊我&#xff0c;若你是真心学习可以送你书籍&#xff0c;指导你学习&#xff0c;给予你目标方向的学习路线&#xff0c;无套路&#xff0c;博客为证。 前言 本专栏内容将会以轻松、简单的方式完成习题的解答&#xff0c;用…

【ArcGIS风暴】ArcGIS 10.8中计算体积的方法总结

ArcGIS 10.8提供了表面体积和面体积两种计算体积的方法。 一、表面体积 用途:用于计算表面和参考平面之间区域的面积和体积。 Situation 1:参考面以上 Situation 2:参考面以下 Python脚本: import arcpy from arcpy import envarcpy.CheckOutExtension("3D")…

.NET7:更细致的时间

当年在做go时&#xff0c;很羡慕它的时间有微秒&#xff0c;纳秒&#xff0c;在做性能优化时&#xff0c;能很小颗粒度的查看引入方法执行的时间&#xff0c;当时.net的DateTime只有毫秒&#xff08;虽然也有别的办法获取&#xff09;。现在&#xff0c;在最新的.NET7 Preview4…

案例:无人测量船水库水下地形测量及库容量计算

本文讲解利用南方方洲号无人船,该系统可用于水下地形地貌测绘、水库库容测量、水文勘测、疏浚检测、水环境监测等领域。 一、无人船水深测量 1、水岸线范围的获取 水岸线有助于布设航线,获取方式有两种: (1)无人船获取 对于

小米android系统耗电量大,小米手机耗电快的解决方法,亲测有效~

原标题&#xff1a;小米手机耗电快的解决方法&#xff0c;亲测有效~各位机友大家好&#xff0c;据小安观察&#xff0c;平台故障报修的小米手机用户还会蛮多的。那么今天就来讲讲小米手机的一些问题和解决方法&#xff0c;如果你感觉手机耗电较快&#xff0c;按照以下方式排查&…

【小白必懂】C语言最大、最小公约数题解

若是大一学子或者是真心想学习刚入门的小伙伴可以私聊我&#xff0c;若你是真心学习可以送你书籍&#xff0c;指导你学习&#xff0c;给予你目标方向的学习路线&#xff0c;无套路&#xff0c;博客为证。 前言 本专栏内容将会以轻松、简单的方式完成习题的解答&#xff0c;用…

如何为微服务选择正确的消息队列

微服务及消息队列简史自从 Peter Rodgers 博士 2005 年在 Web Services Edge 会议上首次提出 Micro-Web-Services 一词后&#xff0c;IT 行业慢慢地从单体架构转向了微服务。2009 年&#xff0c;Netflix 决定把其单体架构拆分为微服务。2010 年&#xff0c;Best Buy 开始把它们…

【小白必懂】C语言回文数判断

若是大一学子或者是真心想学习刚入门的小伙伴可以私聊我&#xff0c;若你是真心学习可以送你书籍&#xff0c;指导你学习&#xff0c;给予你目标方向的学习路线&#xff0c;无套路&#xff0c;博客为证。 情景再现 &#x1f478;小媛&#xff1a;小C&#xff0c;今天可以教我…

『技术群里聊些啥』查看 dotnet 源码,用它!用它!用它!

前言有网友在交流群中询问&#xff0c;怎么找到 System.Linq 源码的库&#xff1a;其实&#xff0c;我一直使用http://source.dot.net查看 dotnet 源码&#xff0c;这可是David Fowler&#xff08;微软 .NET 架构师&#xff09;也推荐的&#xff1a;功能演示那它到底有哪些功能…

(7)3分钟搞定 C# 逻辑运算

本系列文章将会以通俗易懂的对话方式进行教学&#xff0c;对话中将涵盖了新手在学习中的一般问题。此系列将会持续更新&#xff0c;包括别的语言以及实战都将使用对话的方式进行教学&#xff0c;基础编程语言教学适用于零基础小白&#xff0c;之后实战课程也将会逐步更新。 若…