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

Micronaut GRPC Setup Documentation Incorrect #964

Open
lukemauldinks opened this issue Oct 14, 2024 · 0 comments
Open

Micronaut GRPC Setup Documentation Incorrect #964

lukemauldinks opened this issue Oct 14, 2024 · 0 comments

Comments

@lukemauldinks
Copy link

Expected Behavior

Following the guide https://micronaut-projects.github.io/micronaut-grpc/latest/guide/index.html should have resulted in a working GRPC cofiguration.

Actual Behaviour

The documentation did not provide correct information for the build.gradle file. For reference, this is the build.gradle file that worked.

plugins {
    id("com.github.johnrengelman.shadow") version "8.1.1"
    id("io.micronaut.application") version "4.4.2"
    id("com.google.protobuf") version "0.9.2"
}

version = "0.1"
group = "com.play"

repositories {
    mavenCentral()
}

dependencies {
    annotationProcessor("io.micronaut.serde:micronaut-serde-processor")
    implementation("io.micronaut:micronaut-discovery-core")
    implementation("io.micronaut.grpc:micronaut-grpc-runtime")
    implementation("io.micronaut.serde:micronaut-serde-jackson")
    implementation("javax.annotation:javax.annotation-api")
    runtimeOnly("ch.qos.logback:logback-classic")
}


application {
    mainClass = "com.play.Application"
}
java {
    sourceCompatibility = JavaVersion.toVersion("21")
    targetCompatibility = JavaVersion.toVersion("21")
}


sourceSets {
    main {
        java {
            srcDirs("build/generated/source/proto/main/grpc")
            srcDirs("build/generated/source/proto/main/java")
        }
    }
}

protobuf {
    protoc { artifact = "com.google.protobuf:protoc:3.25.5" }
    plugins {
        grpc { artifact = "io.grpc:protoc-gen-grpc-java:1.66.0" }
    }
    generateProtoTasks {
        all()*.plugins { grpc {} }
    }
}

micronaut {
    testRuntime("junit5")
    processing {
        incremental(true)
        annotations("com.play.*")
    }
}


tasks.named("dockerfileNative") {
    jdkVersion = "21"
}

Also added the file `ServiceEndpoint.java.

package com.play;

import com.play.MngrpcServiceGrpc.MngrpcServiceImplBase;
import io.grpc.stub.StreamObserver;
import jakarta.inject.Singleton;


@Singleton
public class ServiceEndpoint extends MngrpcServiceImplBase {
    @Override
    public void send(MngrpcRequest request, StreamObserver<MngrpcReply> responseObserver) {
        System.out.println("Received request: " + request.getName());
        responseObserver.onNext(MngrpcReply.newBuilder().setMessage("Hello " + request.getName()).build());
        responseObserver.onCompleted();
    }
}

Reference command to test via grpcurl:
grpcurl -plaintext -import-path src/main/proto -proto mngrpc.proto -d '{"name": "World"}' localhost:50051 com.play.MngrpcService/send

Steps To Reproduce

No response

Environment Information

Operating system: Ubuntu 24.04
JDK: 21

Example Application

No response

Version

4.6.3

@lukemauldinks lukemauldinks changed the title Micronaut GRPC Setup Documentation Incorret Micronaut GRPC Setup Documentation Incorrect Oct 14, 2024
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