SlideShare a Scribd company logo
Managing gRPC Services
with an API Gateway
By João Esperancinha
(2024/05/13)
Summary
- gRPC theory
- What is it?
- What are the benefits?
- What are the drawbacks?
- Making a gRPC service in the backend in Kotlin
- Making a gRPC client to communicate with the backend in Kotlin
- Creating a gRPC-web client for the front end in Javascript
- Using the gRPC gateway plugin
- Using the gRPC web plugin
- Conclusion
About me
João Esperancinha
● Java
● Kotlin
● Groovy
● Scala
● Software Engineer 10+ years
● JESPROTECH owner for 1 year Kong Champion/Java Professional/Spring Professional
Part - I - gRPC Introduction
gRPC
General Remote Procedure Call
Modern open source network
protocol that allows invocations of
functions and or procedures in the
remote machine as if they were
executed locally. The result of the
function is returned as if the call
was made locally. This is what RPC
means. General, in this context ,
turns RPC into gRPC and it means
that gRPC can be generically used
in different frameworks and
platforms
Theory
How is this made generic?
Protobuffer files!
syntax = "proto3";
package org.jesperancinha.wlsm.messenger;
service Messenger {
rpc Send (Message) returns (MessageResponse);
}
message Message {
string text = 1;
string author = 2;
}
message MessageResponse {
int32 result = 1;
}
● Language Agnostic
● Platform neutral
● Binary serialization
● Own Language
gRPC backend services start out as
protobuf files. The word protobuf
means Protocol Buffer and it
essentially means what it actually
does. This is the data structure
format used in the buffers created
to transmit data.
Backend Service
How to generate
protobuf {
protoc {
artifact =
libs.protoc.asProvider().get().toString()
}
plugins {
create("grpc") {
artifact =
libs.protoc.gen.grpc.java.get().toString()
}
create("grpckt") {
artifact =
libs.protoc.gen.grpc.kotlin.get().toString() +
":jdk8@jar"
}
}
generateProtoTasks {
all().forEach {
it.plugins {
create("grpc")
create("grpckt")
}
it.builtins {
create("kotlin")
}
}
}
}
gradle.kts
MessengerService
syntax = "proto3";
package org.jesperancinha.wlsm.messenger;
service Messenger {
rpc Send (Message) returns (MessageResponse);
}
message Message {
string text = 1;
string author = 2;
}
message MessageResponse {
int32 result = 1;
}
Proto3 Syntax
Request Message
Response Message
Package
RPC Protocol
MessengerService
public abstract class MessengerCoroutineImplBase(
coroutineContext: CoroutineContext = EmptyCoroutineContext,
) : AbstractCoroutineServerImpl(coroutineContext) {
public open suspend fun send(request: MessengerOuterClass.Message):
MessengerOuterClass.MessageResponse = throw
StatusException(UNIMPLEMENTED.withDescription("Method
org.jesperancinha.wlsm.messenger.Messenger.Send is unimplemented"))
final override fun bindService(): ServerServiceDefinition =
builder(getServiceDescriptor())
.addMethod(unaryServerMethodDefinition(
context = this.context,
descriptor = MessengerGrpc.getSendMethod(),
implementation = ::send
)).build()
}
}
MessengerService
internal class MessengerService : MessengerGrpcKt.MessengerCoroutineImplBase() {
override suspend fun send(request: MessengerOuterClass.Message) =
messageResponse {
println(request)
this.result = 0
}
}
Generated by proto
MessengerService
class MessengerServer(private val port: Int) {
val server: Server =
ServerBuilder
.forPort(port)
.addService(MessengerService())
.build()
fun start() {
server.start()
println("Server started, listening on $port")
Runtime.getRuntime().addShutdownHook(
Thread {
println("*** shutting down gRPC server since JVM is shutting down")
this@MessengerServer.stop()
println("*** server shut down")
},
)
}
Just as the gRPC services, the
client files get also generated with
the protobuf plugin. Once that is
created, we can easily use the client
to access the service.
Client
MessengerService - client
@StubFor(MessengerGrpc::class)
public class MessengerCoroutineStub @JvmOverloads constructor(
channel: Channel,
callOptions: CallOptions = DEFAULT,
) : AbstractCoroutineStub<MessengerCoroutineStub>(channel, callOptions) {
override fun build(channel: Channel, callOptions: CallOptions):
MessengerCoroutineStub =
MessengerCoroutineStub(channel, callOptions)
public suspend fun send(request: MessengerOuterClass.Message, headers: Metadata =
Metadata()):
MessengerOuterClass.MessageResponse = unaryRpc(
channel,
MessengerGrpc.getSendMethod(),
request,
callOptions,
headers
)
MessengerService - client
class MessengerClient(private val channel: ManagedChannel) : Closeable {
private val stub: MessengerCoroutineStub = MessengerCoroutineStub(channel)
suspend fun sendMessage(text: String, author: String) {
val request = message {
this.text = text
this.author = author
}
val response = stub.send(request)
println("Received: ${response.result}")
}
override fun close() {
channel.shutdown().awaitTermination(5, TimeUnit.SECONDS)
}
}
Generated by proto
gRPC without gradle
gRPC with gradle
Creating gRPC
DEMO
Part - II - gRPC in Kong Konnect
Where and how do we make the
tests?
How do we connect Kong
KONNECT to our containerized
environment?
How do we see gRPC in action?
How to use
docker-compose
Direct connection via gRPC
Connection to gRPC service via
JSON requests
Connection to the gRPC service via
web requests (all requests made
from a browser)
Kong Konnect
Goals
Managing gRPC Services using Kong KONNECT and the KONG API Gateway
Managing gRPC Services using Kong KONNECT and the KONG API Gateway
Managing gRPC Services using Kong KONNECT and the KONG API Gateway
Conclusions
● Use HTTP/HTTPS requests
For both plugins
● Translate requests to gRPC
● Need a protobuf (.proto) file
● Service configured with gRPC and a Route with HTTP/HTTPS
Conclusions
● JSON to gRPC conversion
For the gateway plugin
For the web plugin
● gRPC-web to gRPC
Direct gRPC
● Both Service and Path need to be configured for gRPC
● Source Repository
○ https://github.com/jesperancinha/wild-life-safety-monitor
Use git clone from the command prompt to download the full code base:
> git clone https://github.com/jesperancinha/wild-life-safety-monitor.git
You’ll be prompted for a username and password which should be your github account.
The easy way:
> make b
> make run
The manual way:
> gradle build
> ./gradlew run
Project Location
Resources:
● https://kodekloud.com/blog/grpc/
● https://docs.konghq.com/hub/kong-inc/grpc-gateway/
● https://grpc-ecosystem.github.io/grpc-gateway/
● https://github.com/protocolbuffers/protobuf
● https://konghq.com/blog/engineering/manage-grpc-services-kong
● https://grpc.io/docs/languages/kotlin/quickstart/
● https://docs.gradle.org/current/userguide/platforms.html#sub:version-catalog
● https://docs.konghq.com/hub/kong-inc/grpc-web/
● https://github.com/grpc/grpc-web/tree/master/net/grpc/gateway/examples/helloworld
Questions?
Thank you!

More Related Content

Similar to Managing gRPC Services using Kong KONNECT and the KONG API Gateway (20)

PPTX
CocoaConf: The Language of Mobile Software is APIs
Tim Burks
 
PPTX
Building API Using GRPC And Scala
Knoldus Inc.
 
PDF
"gRPC-Web: It’s All About Communication": Devoxx Ukraine 2019
Alex Borysov
 
PDF
Building REST APIs using gRPC and Go
Alvaro Viebrantz
 
PPTX
Building your First gRPC Service
Jessie Barnett
 
PDF
gRPC Design and Implementation
Varun Talwar
 
PDF
gRPC & Kubernetes
Kausal
 
PDF
Inter-Process Communication in Microservices using gRPC
Shiju Varghese
 
PDF
Driving containerd operations with gRPC
Docker, Inc.
 
PDF
gRPC services testing
Thivya Lakshmi
 
PDF
gRPC with java
Knoldus Inc.
 
PDF
gRPC: The Story of Microservices at Square
Apigee | Google Cloud
 
PDF
Power-up services with gRPC
The Software House
 
PPTX
What I learned about APIs in my first year at Google
Tim Burks
 
PDF
Usable APIs at Scale
Tim Burks
 
PDF
gRPC or Rest, why not both?
Mohammad Murad
 
PPTX
Grpc present
Phạm Hải Anh
 
PDF
Building Language Agnostic APIs with gRPC - JavaDay Istanbul 2017
Mustafa AKIN
 
PPTX
Introduction to gRPC. Advantages and Disadvantages
abdulrehmanlatif65
 
CocoaConf: The Language of Mobile Software is APIs
Tim Burks
 
Building API Using GRPC And Scala
Knoldus Inc.
 
"gRPC-Web: It’s All About Communication": Devoxx Ukraine 2019
Alex Borysov
 
Building REST APIs using gRPC and Go
Alvaro Viebrantz
 
Building your First gRPC Service
Jessie Barnett
 
gRPC Design and Implementation
Varun Talwar
 
gRPC & Kubernetes
Kausal
 
Inter-Process Communication in Microservices using gRPC
Shiju Varghese
 
Driving containerd operations with gRPC
Docker, Inc.
 
gRPC services testing
Thivya Lakshmi
 
gRPC with java
Knoldus Inc.
 
gRPC: The Story of Microservices at Square
Apigee | Google Cloud
 
Power-up services with gRPC
The Software House
 
What I learned about APIs in my first year at Google
Tim Burks
 
Usable APIs at Scale
Tim Burks
 
gRPC or Rest, why not both?
Mohammad Murad
 
Grpc present
Phạm Hải Anh
 
Building Language Agnostic APIs with gRPC - JavaDay Istanbul 2017
Mustafa AKIN
 
Introduction to gRPC. Advantages and Disadvantages
abdulrehmanlatif65
 

More from João Esperancinha (17)

PDF
Decoding Kotlin - Your Guide to Solving the Mysterious in Kotlin - Devoxx PL ...
João Esperancinha
 
PPTX
Decoding Kotlin - Your guide to solving the mysterious in Kotlin - JNation2025
João Esperancinha
 
PPTX
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
João Esperancinha
 
PPTX
Boosting performance and functional style with Project Arrow from a practical...
João Esperancinha
 
PPTX
Start from the Package in Spring CDS - Basic course
João Esperancinha
 
PPTX
Apollo 4 Kotlin made me Graphql and I learned how to use it
João Esperancinha
 
PPTX
Monads are no Nomads - Unlocking the basics
João Esperancinha
 
PPTX
C.R.a.C in Spring - I froze my server! (15 minute session for NLJUG speaker a...
João Esperancinha
 
PPTX
Could Virtual Threads cast away the usage of Kotlin Coroutines
João Esperancinha
 
PPTX
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
João Esperancinha
 
PPTX
Kuma Meshes Part I - The basics - A tutorial
João Esperancinha
 
PPTX
Fields in Java and Kotlin and what to expect.pptx
João Esperancinha
 
PPTX
Demystifying Co, Contra, In Kotlin modifier keywords.pptx
João Esperancinha
 
PPTX
Unlocking the Power of Kotlin Channels.pptx
João Esperancinha
 
PPTX
Exploring Tailrec Through Time Until Kotlin.pptx
João Esperancinha
 
PPTX
Reactive programming with Spring Webflux.pptx
João Esperancinha
 
PPTX
KONNECT Kong-Presentation How to protect web applications
João Esperancinha
 
Decoding Kotlin - Your Guide to Solving the Mysterious in Kotlin - Devoxx PL ...
João Esperancinha
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin - JNation2025
João Esperancinha
 
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
João Esperancinha
 
Boosting performance and functional style with Project Arrow from a practical...
João Esperancinha
 
Start from the Package in Spring CDS - Basic course
João Esperancinha
 
Apollo 4 Kotlin made me Graphql and I learned how to use it
João Esperancinha
 
Monads are no Nomads - Unlocking the basics
João Esperancinha
 
C.R.a.C in Spring - I froze my server! (15 minute session for NLJUG speaker a...
João Esperancinha
 
Could Virtual Threads cast away the usage of Kotlin Coroutines
João Esperancinha
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
João Esperancinha
 
Kuma Meshes Part I - The basics - A tutorial
João Esperancinha
 
Fields in Java and Kotlin and what to expect.pptx
João Esperancinha
 
Demystifying Co, Contra, In Kotlin modifier keywords.pptx
João Esperancinha
 
Unlocking the Power of Kotlin Channels.pptx
João Esperancinha
 
Exploring Tailrec Through Time Until Kotlin.pptx
João Esperancinha
 
Reactive programming with Spring Webflux.pptx
João Esperancinha
 
KONNECT Kong-Presentation How to protect web applications
João Esperancinha
 
Ad

Recently uploaded (20)

PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
Digital Circuits, important subject in CS
contactparinay1
 
Ad

Managing gRPC Services using Kong KONNECT and the KONG API Gateway

  • 1. Managing gRPC Services with an API Gateway By João Esperancinha (2024/05/13)
  • 2. Summary - gRPC theory - What is it? - What are the benefits? - What are the drawbacks? - Making a gRPC service in the backend in Kotlin - Making a gRPC client to communicate with the backend in Kotlin - Creating a gRPC-web client for the front end in Javascript - Using the gRPC gateway plugin - Using the gRPC web plugin - Conclusion
  • 3. About me João Esperancinha ● Java ● Kotlin ● Groovy ● Scala ● Software Engineer 10+ years ● JESPROTECH owner for 1 year Kong Champion/Java Professional/Spring Professional
  • 4. Part - I - gRPC Introduction
  • 5. gRPC General Remote Procedure Call Modern open source network protocol that allows invocations of functions and or procedures in the remote machine as if they were executed locally. The result of the function is returned as if the call was made locally. This is what RPC means. General, in this context , turns RPC into gRPC and it means that gRPC can be generically used in different frameworks and platforms Theory
  • 6. How is this made generic? Protobuffer files! syntax = "proto3"; package org.jesperancinha.wlsm.messenger; service Messenger { rpc Send (Message) returns (MessageResponse); } message Message { string text = 1; string author = 2; } message MessageResponse { int32 result = 1; } ● Language Agnostic ● Platform neutral ● Binary serialization ● Own Language
  • 7. gRPC backend services start out as protobuf files. The word protobuf means Protocol Buffer and it essentially means what it actually does. This is the data structure format used in the buffers created to transmit data. Backend Service
  • 8. How to generate protobuf { protoc { artifact = libs.protoc.asProvider().get().toString() } plugins { create("grpc") { artifact = libs.protoc.gen.grpc.java.get().toString() } create("grpckt") { artifact = libs.protoc.gen.grpc.kotlin.get().toString() + ":jdk8@jar" } } generateProtoTasks { all().forEach { it.plugins { create("grpc") create("grpckt") } it.builtins { create("kotlin") } } } } gradle.kts
  • 9. MessengerService syntax = "proto3"; package org.jesperancinha.wlsm.messenger; service Messenger { rpc Send (Message) returns (MessageResponse); } message Message { string text = 1; string author = 2; } message MessageResponse { int32 result = 1; } Proto3 Syntax Request Message Response Message Package RPC Protocol
  • 10. MessengerService public abstract class MessengerCoroutineImplBase( coroutineContext: CoroutineContext = EmptyCoroutineContext, ) : AbstractCoroutineServerImpl(coroutineContext) { public open suspend fun send(request: MessengerOuterClass.Message): MessengerOuterClass.MessageResponse = throw StatusException(UNIMPLEMENTED.withDescription("Method org.jesperancinha.wlsm.messenger.Messenger.Send is unimplemented")) final override fun bindService(): ServerServiceDefinition = builder(getServiceDescriptor()) .addMethod(unaryServerMethodDefinition( context = this.context, descriptor = MessengerGrpc.getSendMethod(), implementation = ::send )).build() } }
  • 11. MessengerService internal class MessengerService : MessengerGrpcKt.MessengerCoroutineImplBase() { override suspend fun send(request: MessengerOuterClass.Message) = messageResponse { println(request) this.result = 0 } } Generated by proto
  • 12. MessengerService class MessengerServer(private val port: Int) { val server: Server = ServerBuilder .forPort(port) .addService(MessengerService()) .build() fun start() { server.start() println("Server started, listening on $port") Runtime.getRuntime().addShutdownHook( Thread { println("*** shutting down gRPC server since JVM is shutting down") [email protected]() println("*** server shut down") }, ) }
  • 13. Just as the gRPC services, the client files get also generated with the protobuf plugin. Once that is created, we can easily use the client to access the service. Client
  • 14. MessengerService - client @StubFor(MessengerGrpc::class) public class MessengerCoroutineStub @JvmOverloads constructor( channel: Channel, callOptions: CallOptions = DEFAULT, ) : AbstractCoroutineStub<MessengerCoroutineStub>(channel, callOptions) { override fun build(channel: Channel, callOptions: CallOptions): MessengerCoroutineStub = MessengerCoroutineStub(channel, callOptions) public suspend fun send(request: MessengerOuterClass.Message, headers: Metadata = Metadata()): MessengerOuterClass.MessageResponse = unaryRpc( channel, MessengerGrpc.getSendMethod(), request, callOptions, headers )
  • 15. MessengerService - client class MessengerClient(private val channel: ManagedChannel) : Closeable { private val stub: MessengerCoroutineStub = MessengerCoroutineStub(channel) suspend fun sendMessage(text: String, author: String) { val request = message { this.text = text this.author = author } val response = stub.send(request) println("Received: ${response.result}") } override fun close() { channel.shutdown().awaitTermination(5, TimeUnit.SECONDS) } } Generated by proto
  • 16. gRPC without gradle gRPC with gradle Creating gRPC DEMO
  • 17. Part - II - gRPC in Kong Konnect
  • 18. Where and how do we make the tests? How do we connect Kong KONNECT to our containerized environment? How do we see gRPC in action? How to use docker-compose
  • 19. Direct connection via gRPC Connection to gRPC service via JSON requests Connection to the gRPC service via web requests (all requests made from a browser) Kong Konnect Goals
  • 23. Conclusions ● Use HTTP/HTTPS requests For both plugins ● Translate requests to gRPC ● Need a protobuf (.proto) file ● Service configured with gRPC and a Route with HTTP/HTTPS
  • 24. Conclusions ● JSON to gRPC conversion For the gateway plugin For the web plugin ● gRPC-web to gRPC Direct gRPC ● Both Service and Path need to be configured for gRPC
  • 25. ● Source Repository ○ https://github.com/jesperancinha/wild-life-safety-monitor Use git clone from the command prompt to download the full code base: > git clone https://github.com/jesperancinha/wild-life-safety-monitor.git You’ll be prompted for a username and password which should be your github account. The easy way: > make b > make run The manual way: > gradle build > ./gradlew run Project Location
  • 26. Resources: ● https://kodekloud.com/blog/grpc/ ● https://docs.konghq.com/hub/kong-inc/grpc-gateway/ ● https://grpc-ecosystem.github.io/grpc-gateway/ ● https://github.com/protocolbuffers/protobuf ● https://konghq.com/blog/engineering/manage-grpc-services-kong ● https://grpc.io/docs/languages/kotlin/quickstart/ ● https://docs.gradle.org/current/userguide/platforms.html#sub:version-catalog ● https://docs.konghq.com/hub/kong-inc/grpc-web/ ● https://github.com/grpc/grpc-web/tree/master/net/grpc/gateway/examples/helloworld