quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.53k stars 2.61k forks source link

Support grpc-kotlin #24505

Open debop opened 2 years ago

debop commented 2 years ago

Description

quarkus-grpc support java and mutiny

Can support grpc-kotlin for Kotlin Coroutines ?

link: https://github.com/grpc/grpc-kotlin

Implementation ideas

No response

quarkus-bot[bot] commented 2 years ago

/cc @cescoffier, @evanchooly, @michalszynkiewicz

wfrank2509 commented 2 years ago

Hi ... If I could write something like

@GrpcService
class HelloServiceGrpc(private val service: HelloService) : CoroutineGreeterBase {
    override suspend fun sayHello(request: HelloRequest?): HelloReply {
        return service.say(request!!)
    }
    override suspend fun streamHello(request: HelloRequest?): Flow<HelloReply> {
        return service.streamHello(request!!)
    }
}

CoroutineGreeterBase being the generated Skeleton.

it would be really nice.

andreas-eberle commented 2 years ago

Hi everyone,

here is an example, how it looks like when you do GRPC with Kotlin in Spring Boot. It would be awesome if we could get the same experience in Quarkus with Kotlin and Coroutines (as I really don't want to use Spring Boot :D ). Maybe it would be an idea to have seperate quarkus-grpc-kotlin extension?

the proto file:

syntax = "proto3";

package com.example.grpcdemo.service;

import "google/protobuf/wrappers.proto";
import "google/protobuf/timestamp.proto";

service UserService {
  rpc getUserById (google.protobuf.Int64Value) returns (User);
  rpc streamBack(google.protobuf.Int64Value) returns (stream User);
  rpc twoWayStream(stream User) returns (stream User);
}

message User {
  int64 id = 1;
  string name = 2;
}

My service with coroutines

@GrpcService
class UserService : UserServiceGrpcKt.UserServiceCoroutineImplBase() {

    override suspend fun getUserById(request: Int64Value): Demo.User {
        return user {
            id = request.value
            name = "ddd"
        }
    }

    override fun streamBack(request: Int64Value): Flow<Demo.User> = flow {
        (1..request.value).forEach {
            val user = user {
                id = it
                name = "$it name"
            }
            emit(user)
            delay(500)
        }
    }

    override fun twoWayStream(requests: Flow<Demo.User>): Flow<Demo.User> {
        return requests.map {
            user {
                id = it.id + 1000
                name = "new ${it.name}"
            }
        }
    }
}
rgonciarz commented 1 year ago

Hi Guys, what's the current status for having Quarkus support for coroutine's gRPC stubs?

evanchooly commented 1 year ago

I actually started poking at it this week but set it aside when I realized it'd take a chuck of time. I'm trying to clean up some longer standing bugs before deep diving in to something else.

hennihaus commented 1 year ago

Coroutine support for GRPC would be a really nice feature.

mschorsch commented 1 year ago

Coroutine support for GRPC would be a really nice feature.

I would say it's a must have 😁

wfrank2509 commented 1 year ago

Completely agree that it is a must have. But I would already be happy with a generally deeper integrated Kotlin support for grpc not using the java code generation as intermediate.

mihaipoenaru commented 1 year ago

Also thinking of using gRPC with my project, but I'm not sure if I should use it as it is now, only to replace it later when it's done. @evanchooly , any idea on a time range, depending on your workload? Weeks? Months? Not looking for a formal commitment or anything, just need to know if I can realistically wait for this or I should just start with what is present in Quarkus right now.

dustin-graham commented 1 year ago

I don't know if its exactly what you're all looking for, but I found this video of a solution to get Kotlin Coroutines and gRPC with Quarkus: https://www.youtube.com/watch?v=CXapiybZIJk&ab_channel=arconsis

elgabbouch commented 11 months ago

+1

ghatdev commented 2 months ago

👍🏼