From 960fe29443c6f55df14b7a60be7b2663e371f0f6 Mon Sep 17 00:00:00 2001 From: ToOnlyGaurav Date: Fri, 4 Jun 2021 17:46:01 +0530 Subject: [PATCH] Upgrading grpc version, gradle version. Removing dependency on grpc-java example --- build.gradle | 141 +++++++++--------- examples/build.gradle | 114 +++++++++----- .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../helloworld/guice/HelloWorldModule.java | 10 +- .../helloworld/service/GreeterService.java | 2 +- examples/src/main/proto/helloworld.proto | 37 +++++ 6 files changed, 196 insertions(+), 110 deletions(-) create mode 100644 examples/src/main/proto/helloworld.proto diff --git a/build.gradle b/build.gradle index 109a0843..e610617a 100644 --- a/build.gradle +++ b/build.gradle @@ -1,84 +1,91 @@ -apply plugin: 'java' -apply plugin: 'maven-publish' +plugins { + id 'java' + // Generate IntelliJ IDEA's .idea & .iml project files + id 'idea' + id 'maven-publish' +} ext { - clojarsusername=project.properties['clojarsusername'] ?: "" - clojarspassword=project.properties['clojarspassword'] ?: "" + clojarsusername = project.properties['clojarsusername'] ?: "" + clojarspassword = project.properties['clojarspassword'] ?: "" } - allprojects { repositories { - mavenLocal() - mavenCentral() - jcenter() + maven { // The google mirror is less flaky than mavenCentral() + url "https://maven-central.storage-download.googleapis.com/maven2/" + } + mavenCentral() + mavenLocal() + jcenter() } } publishing { - publications { - maven(MavenPublication) { - groupId = 'com.flipkart' - artifactId = 'grpc-jexpress' - version = '1.36-SNAPSHOT' - from components.java - } - } - repositories { - maven { - url "https://repo.clojars.org" - credentials { - username = rootProject.ext.clojarsusername - password = rootProject.ext.clojarspassword - } - } - } + publications { + maven(MavenPublication) { + groupId = 'com.flipkart' + artifactId = 'grpc-jexpress' + version = '1.36-SNAPSHOT' + from components.java + } + } + repositories { + maven { + url "https://repo.clojars.org" + credentials { + username = rootProject.ext.clojarsusername + password = rootProject.ext.clojarspassword + } + } + } } -def grpcVersion = '1.20.0' + +def grpcVersion = '1.38.0' def jacksonVersion = '2.9.7' def guiceVersion = '4.2.2' subprojects { - apply plugin: 'maven' - group = 'com.flipkart.grpc-jexpress' - version = '1.36-SNAPSHOT' - - jar { - manifest.attributes provider: 'gradle' - } - ext { - libraries = [ - slf4j_api: "org.slf4j:slf4j-api:1.7.12", - log4j_api: "org.apache.logging.log4j:log4j-api:2.5", - log4j: "org.apache.logging.log4j:log4j-core:2.5", - log4j_slf4j: "org.apache.logging.log4j:log4j-slf4j-impl:2.5", - commons_configuration: "commons-configuration:commons-configuration:1.10", - guice: "com.google.inject:guice:${guiceVersion}", - yammer_metrics: "com.palominolabs.metrics:metrics-guice:4.0.0", - yammer_healthchecks:"io.dropwizard.metrics:metrics-healthchecks:4.0.2", - grpc_netty: "io.grpc:grpc-netty:${grpcVersion}", - grpc_protobuf: "io.grpc:grpc-protobuf:${grpcVersion}", - jersey: 'org.glassfish.jersey.containers:jersey-container-servlet:2.6', - jersey_freemarker: 'org.glassfish.jersey.ext:jersey-mvc-freemarker:2.6', - servlet: 'javax.servlet:javax.servlet-api:3.1.0', - jackson: "com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:${jacksonVersion}", - jetty_metrics: 'com.codahale.metrics:metrics-jetty9:3.0.2', - guice_validator: 'ru.vyarus:guice-validator:1.2.0', - hibernate_validator: 'org.hibernate:hibernate-validator:5.4.1.Final', - javax_el: 'org.glassfish:javax.el:3.0.1-b08', - opentracing: 'io.opentracing:opentracing-api:0.31.0', - lombok: 'org.projectlombok:lombok:1.18.2', - grpc_stub :"io.grpc:grpc-stub:${grpcVersion}", - hystrix_core: "com.netflix.hystrix:hystrix-core:1.5.12", - hystrix_metrics_stream: "com.netflix.hystrix:hystrix-metrics-event-stream:1.5.12", - rxjava2: "io.reactivex.rxjava2:rxjava:2.2.0", - javax_validation: 'javax.validation:validation-api:1.1.0.Final', - commons_io: 'commons-io:commons-io:2.6', - junit4: 'junit:junit:4.12', - assertj: 'org.assertj:assertj-core:3.12.1', - object_mapper: "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}", - jackson_data_format: "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${jacksonVersion}", - ] - } + apply plugin: 'maven' + group = 'com.flipkart.grpc-jexpress' + version = '1.37-SNAPSHOT' + + jar { + manifest.attributes provider: 'gradle' + } + ext { + libraries = [ + slf4j_api : "org.slf4j:slf4j-api:1.7.12", + log4j_api : "org.apache.logging.log4j:log4j-api:2.5", + log4j : "org.apache.logging.log4j:log4j-core:2.5", + log4j_slf4j : "org.apache.logging.log4j:log4j-slf4j-impl:2.5", + commons_configuration : "commons-configuration:commons-configuration:1.10", + guice : "com.google.inject:guice:${guiceVersion}", + yammer_metrics : "com.palominolabs.metrics:metrics-guice:4.0.0", + yammer_healthchecks : "io.dropwizard.metrics:metrics-healthchecks:4.0.2", + grpc_netty : "io.grpc:grpc-netty:${grpcVersion}", + grpc_protobuf : "io.grpc:grpc-protobuf:${grpcVersion}", + jersey : 'org.glassfish.jersey.containers:jersey-container-servlet:2.6', + jersey_freemarker : 'org.glassfish.jersey.ext:jersey-mvc-freemarker:2.6', + servlet : 'javax.servlet:javax.servlet-api:3.1.0', + jackson : "com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:${jacksonVersion}", + jetty_metrics : 'com.codahale.metrics:metrics-jetty9:3.0.2', + guice_validator : 'ru.vyarus:guice-validator:1.2.0', + hibernate_validator : 'org.hibernate:hibernate-validator:5.4.1.Final', + javax_el : 'org.glassfish:javax.el:3.0.1-b08', + opentracing : 'io.opentracing:opentracing-api:0.31.0', + lombok : 'org.projectlombok:lombok:1.18.2', + grpc_stub : "io.grpc:grpc-stub:${grpcVersion}", + hystrix_core : "com.netflix.hystrix:hystrix-core:1.5.12", + hystrix_metrics_stream: "com.netflix.hystrix:hystrix-metrics-event-stream:1.5.12", + rxjava2 : "io.reactivex.rxjava2:rxjava:2.2.0", + javax_validation : 'javax.validation:validation-api:1.1.0.Final', + commons_io : 'commons-io:commons-io:2.6', + junit4 : 'junit:junit:4.12', + assertj : 'org.assertj:assertj-core:3.12.1', + object_mapper : "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}", + jackson_data_format : "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${jacksonVersion}", + ] + } } diff --git a/examples/build.gradle b/examples/build.gradle index 460ca7a8..4478b2f0 100644 --- a/examples/build.gradle +++ b/examples/build.gradle @@ -1,55 +1,91 @@ -apply plugin: 'java' +plugins { + // Provide convenience executables for trying out the examples. + id 'application' + // ASSUMES GRADLE 5.6 OR HIGHER. Use plugin version 0.8.10 with earlier gradle versions + id 'com.google.protobuf' version '0.8.15' + // Generate IntelliJ IDEA's .idea & .iml project files + id 'idea' +} + +group = 'com.flipkart.grpc-jexpress.example' +version = '1.0-SNAPSHOT' repositories { - mavenLocal() - mavenCentral() - jcenter() + maven { // The google mirror is less flaky than mavenCentral() + url "https://maven-central.storage-download.googleapis.com/maven2/" + } + mavenCentral() + mavenLocal() + jcenter() } +def jexpressVersion = '1.37-SNAPSHOT' +def grpcVersion = '1.38.0' +def protobufVersion = '3.12.0' +def protocVersion = protobufVersion + dependencies { - compile "com.flipkart.grpc-jexpress:core:1.3-SNAPSHOT" - compile "com.flipkart.grpc-jexpress:runtime:1.3-SNAPSHOT" - compile "com.flipkart.grpc-jexpress:guice:1.3-SNAPSHOT" - compile "io.grpc:examples:1.+" - compile "io.dropwizard.metrics:metrics-healthchecks:4.0.2" - compile "com.palominolabs.metrics:metrics-guice:4.0.0" - compile 'ru.vyarus:guice-validator:1.2.0' - compile 'org.hibernate:hibernate-validator:5.4.1.Final' - compile 'org.glassfish:javax.el:3.0.1-b08' - compile 'io.reactivex.rxjava2:rxjava:2.2.0' - compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.8' - compile 'org.projectlombok:lombok:1.18.6' - compile 'org.glassfish.jersey.containers:jersey-container-servlet:2.6' - compile 'com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.9.7' -} - -apply plugin: 'application' + implementation "com.flipkart.grpc-jexpress:core:${jexpressVersion}" + implementation "com.flipkart.grpc-jexpress:runtime:${jexpressVersion}" + implementation "com.flipkart.grpc-jexpress:guice:${jexpressVersion}" + implementation "io.grpc:grpc-netty-shaded:${grpcVersion}" + implementation "io.grpc:grpc-protobuf:${grpcVersion}" + implementation "io.grpc:grpc-stub:${grpcVersion}" + implementation "io.dropwizard.metrics:metrics-healthchecks:4.0.2" + implementation "com.palominolabs.metrics:metrics-guice:4.0.0" + implementation 'ru.vyarus:guice-validator:1.2.0' + implementation 'org.hibernate:hibernate-validator:5.4.1.Final' + implementation 'org.glassfish:javax.el:3.0.1-b08' + implementation 'io.reactivex.rxjava2:rxjava:2.2.0' + implementation 'com.fasterxml.jackson.core:jackson-annotations:2.9.8' + implementation 'org.projectlombok:lombok:1.18.6' + implementation 'org.glassfish.jersey.containers:jersey-container-servlet:2.6' + implementation 'com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.9.7' +} + +protobuf { + protoc { artifact = "com.google.protobuf:protoc:${protocVersion}" } + plugins { + grpc { artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}" } + } + generateProtoTasks { + all()*.plugins { grpc {} } + } +} + +test { + useJUnitPlatform() +} + +// Inform IDEs like IntelliJ IDEA, Eclipse or NetBeans about the generated code. +sourceSets { + main { + java { + srcDirs 'build/generated/source/proto/main/grpc' + srcDirs 'build/generated/source/proto/main/java' + } + } +} startScripts.enabled = false task helloWorldServer(type: CreateStartScripts) { - mainClassName = 'com.flipkart.gjex.examples.helloworld.HelloWorldApplication' - applicationName = 'hello-world-server' - outputDir = new File(project.buildDir, 'tmp') - classpath = jar.outputs.files + project.configurations.runtime + mainClassName = 'com.flipkart.gjex.examples.helloworld.HelloWorldApplication' + applicationName = 'hello-world-server' + outputDir = new File(project.buildDir, 'tmp') + classpath = startScripts.classpath } + task helloWorldClient(type: CreateStartScripts) { - mainClassName = 'com.flipkart.gjex.examples.helloworld.client.HelloWorldClient' - applicationName = 'hello-world-client' - outputDir = new File(project.buildDir, 'tmp') - classpath = jar.outputs.files + project.configurations.runtime + mainClassName = 'com.flipkart.gjex.examples.helloworld.client.HelloWorldClient' + applicationName = 'hello-world-client' + outputDir = new File(project.buildDir, 'tmp') + classpath = startScripts.classpath } applicationDistribution.into('bin') { - from(helloWorldServer) - from(helloWorldClient) - fileMode = 0755 + from(helloWorldServer) + from(helloWorldClient) + fileMode = 0755 } -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' - from sourceSets.main.allSource -} -artifacts { - archives sourcesJar -} diff --git a/examples/gradle/wrapper/gradle-wrapper.properties b/examples/gradle/wrapper/gradle-wrapper.properties index 115e6ac0..0f80bbf5 100644 --- a/examples/gradle/wrapper/gradle-wrapper.properties +++ b/examples/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/guice/HelloWorldModule.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/guice/HelloWorldModule.java index 38bac55e..b0ee349d 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/guice/HelloWorldModule.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/guice/HelloWorldModule.java @@ -15,6 +15,9 @@ */ package com.flipkart.gjex.examples.helloworld.guice; +import io.grpc.Channel; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; import org.glassfish.jersey.server.ResourceConfig; import com.codahale.metrics.health.HealthCheck; @@ -47,8 +50,11 @@ public HelloWorldModule() {} @Override protected void configure() { - install(new ClientModule(GreeterGrpc.GreeterBlockingStub.class,new ChannelConfig("localhost",9999))); - + ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost",50051) + .usePlaintext() + .build(); +// install(new ClientModule(GreeterGrpc.GreeterBlockingStub.class,new ChannelConfig("localhost",9999))); + bind(GreeterGrpc.GreeterBlockingStub.class).toInstance(GreeterGrpc.newBlockingStub(channel)); bind(BindableService.class).annotatedWith(Names.named("GreeterService")).to(GreeterService.class); bind(Filter.class).annotatedWith(Names.named("LoggingFilter")).to(LoggingFilter.class); bind(Filter.class).annotatedWith(Names.named("AuthFilter")).to(AuthFilter.class); diff --git a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/service/GreeterService.java b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/service/GreeterService.java index 93bea598..a932957d 100644 --- a/examples/src/main/java/com/flipkart/gjex/examples/helloworld/service/GreeterService.java +++ b/examples/src/main/java/com/flipkart/gjex/examples/helloworld/service/GreeterService.java @@ -89,7 +89,7 @@ public void sayHello(HelloRequest req, StreamObserver responseObserv HelloReply reply = HelloReply.newBuilder().setMessage(this.greeting + req.getName()).build(); // invoke external gRPC call - this.invokeGrpcCall(req, reply); + //this.invokeGrpcCall(req, reply); responseObserver.onNext(reply); responseObserver.onCompleted(); diff --git a/examples/src/main/proto/helloworld.proto b/examples/src/main/proto/helloworld.proto new file mode 100644 index 00000000..549882db --- /dev/null +++ b/examples/src/main/proto/helloworld.proto @@ -0,0 +1,37 @@ +// Copyright 2015 The gRPC Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "io.grpc.examples.helloworld"; +option java_outer_classname = "HelloWorldProto"; +option objc_class_prefix = "HLW"; + +package helloworld; + +// The greeting service definition. +service Greeter { + // Sends a greeting + rpc SayHello (HelloRequest) returns (HelloReply) {} +} + +// The request message containing the user's name. +message HelloRequest { + string name = 1; +} + +// The response message containing the greetings +message HelloReply { + string message = 1; +} \ No newline at end of file