grpc java 插件,gRPC-java-.proto文件的编译

I have compiled my .proto file using the protobuf compiler and received a selection of Java files. I received a proto.java file and a .java file for each item in the .proto file, including the message type and each RPC call e.g. publicKeyRequest.java and Quote.java as the RPC and request parameter type.

Is this all the files that are needed as I still cannot seem to to get any simple response back from the server?

I want to generate a request for the PublicKeyRequest RPC call. I generated the request object, but I do not know how to actually send it via the channel.

This is the full .proto file:

syntax = "proto3";

option java_multiple_files = true;

option java_package = "io.grpc.decryptiondevice";

option java_outer_classname = "DecryptionDeviceProto";

package decryptiondevice;

service DecryptionDevice {

// Decryption Request RPC

//

// Request contains ciphertext and proof

// Returns the plaintext record

rpc DecryptRecord(DecryptionRequest) returns (Record) {}

// Get Signed Root Tree Hash RPC

//

// Caller provides a nonce

// Returns a signed RTH and nonce

rpc GetRootTreeHash(RootTreeHashRequest) returns (RootTreeHash) {}

// Get Public key RPC

//

// Returns a Remote attestation report containing the public key as user data

rpc GetPublicKey(PublicKeyRequest) returns (Quote) {}

}

// Decryption Request

// - Byte array containing ciphertext

// - Proofs represented as JSON trees

message DecryptionRequest {

bytes ciphertext = 1;

string proofOfPresence = 2;

string proofOfExtension = 3;

}

// A plaintext record

message Record {

bytes plaintext = 1;

}

// RTH request contains

// - A random nonce

message RootTreeHashRequest {

bytes nonce = 1;

}

// Root Tree Hash

// Random nonce used as message ID

// Signature over rth and nonce

message RootTreeHash {

bytes rth = 1;

bytes nonce = 2;

bytes sig = 3;

}

// Public key request message

message PublicKeyRequest {

bytes nonce = 1;

}

// Attestation Quote, containing the public key

message Quote {

string quote = 1; //some format.. to be defined later

//PEM formatted key

bytes RSA_EncryptionKey = 2;

bytes RSA_VerificationKey = 3;

}

And this is the code I am attempting to run on the client side:

public static void main(String[] args) {

DeviceClient client = new DeviceClient("localhost", 50051);

MannagedChanel channel = ManagedChannelBuilder.forAddress("localhost", 50051).usePlaintext(true);

ByteString nonce = ByteString.copyFromUtf8("someRandomString");

PublicKeyRequest keyRequest = PublicKeyRequest.newBuilder().setNonce(nonce).build();

// Here I want to send this to the server

ByteString response = DecryptionDeviceProto.getKey(keyRequest, channel);//this line is not even close to being valid, but this is the sort thing I wish to achieve

Sys.out.println(response);

}

Apologies if this is very wrong, I am new to gRPC.

A few points about this system:

A client and server has already been written in Go which has been tested and works with this same .proto file.

I am attempting to rewrite the client in Java to communicate with the same server.

解决方案

There are two sets of files that need to be generated: Java Protobuf and Java gRPC. To my knowledge, for all languages except Go, these are two separate generation steps (that can be combined into one protoc invocation, but they are conceptually separate).

It seems you are generating the Java Protobuf code, but not the Java gRPC code. You need to use the protoc-gen-grpc-java plugin to protoc. If you are using Maven or Gradle, read grpc-java's README. If you are running protoc manually, you can download a pre-built binary from Maven Central and see an answer to a similar question.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值