Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin implementation #16

Open
mfickett opened this issue Oct 2, 2020 · 0 comments
Open

Kotlin implementation #16

mfickett opened this issue Oct 2, 2020 · 0 comments

Comments

@mfickett
Copy link

mfickett commented Oct 2, 2020

Kotlin gRPC exposes a different server endpoint API from Java. It would be useful to have an example of throwing a StatusException, if that's what the Kotlin generated code expects users to do.

With this in build.gradle:

plugins {
    id "com.google.protobuf" version "0.8.12"
}
protobuf {
    protoc { artifact = "com.google.protobuf:protoc:3.12.2" }
    plugins {
        grpc { artifact = "io.grpc:protoc-gen-grpc-java:1.29.0" }
        grpckt { artifact = "io.grpc:protoc-gen-grpc-kotlin:0.1.2" }
    }
    generateProtoTasks {
        all()*.plugins {
            grpc {}
            grpckt {}
        }
    }
}

The generated RPC functions to override are like this:

/**                                                                                                  
 * Holder for Kotlin coroutine-based client and server APIs for                                      
 * my_pkg.MyService.                                               
 */                                                                                                  
object MyServiceGrpcKt {
    ...

    /**
     * Returns the response to an RPC for valohealth_monocle.model_search.ModelSearchService.Search.
     *
     * If this method fails with a [StatusException], the RPC will fail with the corresponding      
     * [io.grpc.Status].  If this method fails with a [java.util.concurrent.CancellationException], 
     * the RPC will fail
     * with status `Status.CANCELLED`.  If this method fails for any other reason, the RPC will     
     * fail with `Status.UNKNOWN` with the exception as a cause.
     *
     * @param request The request from the client.
     */
    open suspend fun search(request: ModelSearchRequest): ModelSearchResponse = throw
        StatusException(UNIMPLEMENTED.withDescription("Method my_pkg.MyService.Search is unimplemented"))
}

So unlike Java, there's no observer to tag errors onto, but the default implementation here seems to give an example of throwing an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant