Recently, I tried using Quarkus with Kotlin for grpc.
I have worked with grpc for communication between microservices in Java & Golang.
But with Kotlin, I don't recall having set it up myself or tweaked a thing or two besides adding a few fields to the protobuf messages as part of syncing with dependent systems.
Most importantly, I had never streamed data using the stream keyword in protobuf file.
Initially it seemed very overwhelming to set up things and get running because originally Quarkus was probably made to work with Java and then ported for Kotlin.
There are 2 things one would ever want to do with gRPC:
1. Implement a new microservice that others can call & get data from
2. Call an existing microservice to get data from it, also called consuming a grpc service.
Quarkus Docs has samples for both at :
1. https://quarkus.io/guides/grpc-service-implementation
2. https://quarkus.io/guides/grpc-service-consumption
But the former only contains a blocking implementation, a non-blocking implementation is missing and not so easy to find elsewhere.
As i read more about streaming, I realized that bidirectional streaming is also possible such as a chat app.
import "google/protobuf/timestamp.proto";
service VenueService {
rpc listVenues(Location) returns (stream Venue) { }
rpc RecordTrip(stream Location) returns (TripSummary) {}
rpc chat(stream Comment) returns (stream Comment) {}
}
message Comment { string text = 1; google.protobuf.Timestamp sentTime = 3; }
There's more to add to this, with a different example, perhaps a hotel reservation. This post shall be updated soon with more details.
References:
- https://genekuo.medium.com/developing-a-rest-service-with-quarkus-and-deploying-to-minikube-c956b9ac900f
- https://medium.com/@georgeleung_7777/seamless-backpressure-handling-with-grpc-kotlin-a6f99cab4b95
- https://codingwithmohit.com/grpc/grpc-kotlin-coroutines/
- https://techdozo.dev/grpc-synchronous-and-asynchronous-unary-rpc-in-java/
- https://techdozo.dev/grpc-interceptor-unary-interceptor-with-code-example/
- https://techdozo.dev/grpc-synchronous-and-asynchronous-server-streaming-rpc/
- https://techdozo.dev/grpc-synchronous-and-asynchronous-unary-rpc-in-java/
- https://techdozo.dev/grpc-bidirectional-streaming-with-code-example/
- https://www.baeldung.com/java-grpc-streaming
No comments:
Post a Comment