Where to implement service file when using grpc

37 views
Skip to first unread message

Passenger

unread,
Oct 30, 2018, 6:04:11 AM10/30/18
to grpc.io
Using Java 

I created a protobuffer . I generated all the classes . The classes were generated in project/target directory .Now my java project folder looks like this

1) src
2) target
3) pom.xml

Proto file -

syntax="proto3";

option java_multiple_files = true;
option java_package="com.grpc.project1";

package com.grpc.project1;

message Person{
string first_name=1;
string last_name=2;

}

message Greeting{
string message=1;
}

service HelloWorldService{

rpc sayHello(Person) returns (Greeting);
}






Now src also has sub folder main/java
and target also has two sub folder -
1) /generated-sources/protobuf/grpc-java 
2)/generated-sources/protobuf/java



No i want to implement my HelloWorldService class where should I define the class ??
Inside src/main/java
or inside 
1) /generated-sources/protobuf/grpc-java 
2)/generated-sources/protobuf/java

If I create class inside src/main/java i am unable to extend HelloWorldServiceGrpc.HelloWorldServiceImpl niether i am able to import target folderbut it is present inside  /generated-sources/protobuf/grpc-java/com/grpc/project1 

Kun Zhang

unread,
Oct 31, 2018, 2:20:08 PM10/31/18
to grpc.io
Assuming you are using protobuf-maven-plugin, it doesn't matter that the generated files are under /generated-sources. The generated classes should be added automatically to your build path by the plugin. Just import them with the proper package names and your source should compile.
If it still doesn't work, you may want to share your whole project source so that other people can diagnose for you.
Message has been deleted

aadarsh...@paytm.com

unread,
Oct 31, 2018, 2:32:26 PM10/31/18
to grpc.io
proto file 



syntax="proto3";

package com.project.grpc.roleservice;

message UserRequest {
    string userName=1;
}

message RoleReply {
    string userRole=1;
}

service UserRoleFromServer{
    rpc getRoleUser(stream UserRequest) returns (stream RoleReply);
}
Message has been deleted

aadarsh...@paytm.com

unread,
Oct 31, 2018, 2:34:37 PM10/31/18
to grpc.io
gradle build buildscript {
ext {
    springBootVersion = '2.0.4.RELEASE'
}
repositories {
    mavenCentral()
}
dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    classpath("com.google.protobuf:protobuf-gradle-plugin:0.8.5")
    }
}


plugins {
id 'java'
}


apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.google.protobuf'

group 'com.project.grpc.roleservice'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

protobuf {
protoc {
    artifact = "com.google.protobuf:protoc:3.5.1-1"
}
plugins {
    grpc {
        artifact = 'io.grpc:protoc-gen-grpc-java:1.16.1'
    }
}
generateProtoTasks {
    all()*.plugins {
        grpc {}
    }
}
}

repositories {
    mavenCentral()
}

dependencies {

compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-web')
compile( 'io.grpc:grpc-netty-shaded:1.16.1')
compile('io.grpc:grpc-protobuf:1.16.1')
compile('io.grpc:grpc-stub:1.16.1')
compile 'io.github.lognet:grpc-spring-boot-starter:3.0.0'
runtime('org.springframework.boot:spring-boot-devtools')
runtime('mysql:mysql-connector-java')
testCompile (group: 'junit', name: 'junit', version: '4.12')
}
Reply all
Reply to author
Forward
0 new messages