Issue Sending Request from gRPC Java Client

Viewed 85

I have this code:

ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 9090).usePlaintext().build();
SentenceClassificationServiceGrpc.SentenceClassificationServiceBlockingStub SentenceClassificationStub = SentenceClassificationServiceGrpc.newBlockingStub(channel);

SentenceClassificationRequest request = SentenceClassificationRequest.newBuilder().setDocument("hey").setThreshold(1);
SentenceClassificationResponse response = SentenceClassificationStub.classification(request);

and I keep on getting this error:

java: incompatible types: com.application.SentenceClassificationRequest.Builder cannot be converted to com.application.SentenceClassificationRequest

I've generated the gRPC Java files using the Maven plugin. After looking at multiple examples I'm not sure what my issue is.

1 Answers

Solution

You forgot to build your SentenceClassificationRequest, currently you're assigning your SentenceClassificationRequest.Builder to SentenceClassificationRequest

Just add .build() to the end of the builder

SentenceClassificationRequest request = SentenceClassificationRequest.newBuilder().setDocument("hey").setThreshold(1).build();
Related