Open EmhyrVarEmreis opened 1 year ago
Yes, on the server side simply implement the Bindable interface yourself. And put the @GrpcService
annotation on it as usual.
On the client side, you have to implement a StubFactory
as well as the actual AbstractStub
implementation (the Bindable counterpart). You might be able to avoid the StubFactory if you mirror grpc-java's generated ___Grpc
classes instead.
Please note that we cannot provide any further help for the json part of this.
Does this answer help you?
Yes, on the server side simply implement the Bindable interface yourself. And put the @GrpcService annotation on it as usual.
I see.
You might be able to avoid the StubFactory if you mirror grpc-java's generated ___Grpc classes instead.
Could you explain more wtaht do you mean by this part?
Thank you for help.
The grpc-java ___Grpc
files contain both the stub implementations as well as a static ___Stub new___Stub(Channel)
method that will be called here:
So if you follow the grpc-java class layout you don't have to write your own StubFactory
.
You might want to actually let that file generate and just replace the protobuf marschalers/stuff with the JSON variant.
(You don't have to implement/convert all of the class, just the parts you actually need yourself e.g. you might not need the descriptors, or can reuse the protobuf ones even though they aren't technically correct)
* The greeting service definition. **/ @javax.annotation.Generated( value = "by gRPC proto compiler (version 1.54.0)", comments = "Source: helloworld.proto") @io.grpc.stub.annotations.GrpcGenerated public final class SimpleGrpc { private SimpleGrpc() {} public static final String SERVICE_NAME = "Simple"; // Static method descriptors that strictly reflect the proto. private static volatile io.grpc.MethodDescriptor
* The greeting service definition. **/ public interface AsyncService { /** *
* Sends a greeting **/ default void sayHello(net.devh.boot.grpc.examples.lib.HelloRequest request, io.grpc.stub.StreamObserver
* The greeting service definition. **/ public static abstract class SimpleImplBase implements io.grpc.BindableService, AsyncService { @java.lang.Override public final io.grpc.ServerServiceDefinition bindService() { return SimpleGrpc.bindService(this); } } /** * A stub to allow clients to do asynchronous rpc calls to service Simple. *
* The greeting service definition. **/ public static final class SimpleStub extends io.grpc.stub.AbstractAsyncStub
* Sends a greeting **/ public void sayHello(net.devh.boot.grpc.examples.lib.HelloRequest request, io.grpc.stub.StreamObserver
* The greeting service definition. **/ public static final class SimpleBlockingStub extends io.grpc.stub.AbstractBlockingStub
* Sends a greeting **/ public net.devh.boot.grpc.examples.lib.HelloReply sayHello(net.devh.boot.grpc.examples.lib.HelloRequest request) { return io.grpc.stub.ClientCalls.blockingUnaryCall( getChannel(), getSayHelloMethod(), getCallOptions(), request); } } /** * A stub to allow clients to do ListenableFuture-style rpc calls to service Simple. *
* The greeting service definition. **/ public static final class SimpleFutureStub extends io.grpc.stub.AbstractFutureStub
* Sends a greeting **/ public com.google.common.util.concurrent.ListenableFuture
Please note that there is now also grpc-servlet as a library that lets you use grpc with a servlet container such as tomcat. (I think it still uses protobuf though if you don't rewrite the ___Grpc file)
Ok, thanks for clarification.
You might want to actually let that file generate and just replace the protobuf marschalers/stuff with the JSON variant.
I assume it would require manual replacements each time code is generated?
Well, you have to do that (adjust the code) anyway unless you automate that.
https://grpc.io/blog/grpc-with-json/
I would like to achieve something like in tutorial above but with this framework. It requires programatically creating grpc services. Is it possible to do so?