Example code to show how to make a gRPC server using Spring Boot & gRPC Spring Boot Starter plugin in Kotlin.
Checkout the repo and then do gradle build
in order to generate the Proto files.
Start the server with java -jar build/libs/kotlin-grpc-demo-1.0-SNAPSHOT.jar
.
gRPC server will run on port 6565
by default.
Install the grpcio-tools package:
$ pip install grpcio-tools
Use the following command to generate the Python code for the protobuf:
$ mkdir python_client
$ cd python_client
$ python -m grpc_tools.protoc -I../src/main/proto --python_out=. --grpc_python_out=. ../src/main/proto/demo.proto
Run this to connect to the server and make a request:
import grpc
import demo_pb2_grpc
import demo_pb2
channel = grpc.insecure_channel('localhost:6565')
stub = demo_pb2_grpc.DemoStub(channel)
request = demo_pb2.DemoRequest()
response = stub.SayHello(request)
print(response)