cescoffier / vertx-kubernetes-workshop

A workshop showing how to develop reactive microservices with Vert.x and deploy them with Kubernetes
Apache License 2.0
44 stars 28 forks source link

Compilation error in exercise 4.2 #18

Closed tvolkov closed 5 years ago

tvolkov commented 5 years ago

Hi,

I'm trying to accomplish exercise 4.2 (class Exercise2Verticle in microservices-exercises module) and I get the compilation error in this piece:

        discovery.rxGetRecord(svc -> svc.getName().equals("greetings"))
                .map(discovery::getReference)
                .map(serviceReference -> serviceReference.getAs(WebClient.class))
                .flatMap(webClient -> webClient.get("/greetings/vert.x-low-level-api").rxSend())
                .map(HttpResponse::bodyAsString)
                .subscribe(res -> System.out.println("result from the greeting service: " + res));

Intellij idea complains about the lambda passed to flatMap saying

no instance(s) of type variable(s) R exist so that Single<HttpResponse<Buffer>> conforms to MaybeSource<? extends R>

Running mvn package from within microservices-exercises module produces somewhat different error:

/Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home/bin/java -Dmaven.multiModuleProjectDirectory=/Users/timofeivolkov/IdeaProjects/vertx-kubernetes-workshop/microservices-exercises "-Dmaven.home=/Applications/IntelliJ IDEA CE.app/Contents/plugins/maven/lib/maven3" "-Dclassworlds.conf=/Applications/IntelliJ IDEA CE.app/Contents/plugins/maven/lib/maven3/bin/m2.conf" "-javaagent:/Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar=53358:/Applications/IntelliJ IDEA CE.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Applications/IntelliJ IDEA CE.app/Contents/plugins/maven/lib/maven3/boot/plexus-classworlds-2.5.2.jar" org.codehaus.classworlds.Launcher -Didea.version=2018.3.4 clean package
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building microservices-exercises 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ microservices-exercises ---
[INFO] Deleting /Users/timofeivolkov/IdeaProjects/vertx-kubernetes-workshop/microservices-exercises/target
[INFO] 
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ microservices-exercises ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/timofeivolkov/IdeaProjects/vertx-kubernetes-workshop/microservices-exercises/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ microservices-exercises ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 4 source files to /Users/timofeivolkov/IdeaProjects/vertx-kubernetes-workshop/microservices-exercises/target/classes
[INFO] /Users/timofeivolkov/IdeaProjects/vertx-kubernetes-workshop/microservices-exercises/src/main/java/io/vertx/workshop/exercise/microservice/Exercise1Verticle.java: /Users/timofeivolkov/IdeaProjects/vertx-kubernetes-workshop/microservices-exercises/src/main/java/io/vertx/workshop/exercise/microservice/Exercise1Verticle.java uses or overrides a deprecated API.
[INFO] /Users/timofeivolkov/IdeaProjects/vertx-kubernetes-workshop/microservices-exercises/src/main/java/io/vertx/workshop/exercise/microservice/Exercise1Verticle.java: Recompile with -Xlint:deprecation for details.
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /Users/timofeivolkov/IdeaProjects/vertx-kubernetes-workshop/microservices-exercises/src/main/java/io/vertx/workshop/exercise/microservice/Exercise2Verticle.java:[32,25] incompatible types: cannot infer type-variable(s) R
    (argument mismatch; bad return type in lambda expression
      io.reactivex.Single<io.vertx.reactivex.ext.web.client.HttpResponse<io.vertx.reactivex.core.buffer.Buffer>> cannot be converted to io.reactivex.MaybeSource<? extends R>)
[ERROR] /Users/timofeivolkov/IdeaProjects/vertx-kubernetes-workshop/microservices-exercises/src/main/java/io/vertx/workshop/exercise/microservice/Exercise2Verticle.java:[33,22] invalid method reference
  non-static method bodyAsString() cannot be referenced from a static context
[INFO] 2 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.636 s
[INFO] Finished at: 2019-03-13T10:54:13+01:00
[INFO] Final Memory: 22M/308M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project microservices-exercises: Compilation failure: Compilation failure:
[ERROR] /Users/timofeivolkov/IdeaProjects/vertx-kubernetes-workshop/microservices-exercises/src/main/java/io/vertx/workshop/exercise/microservice/Exercise2Verticle.java:[32,25] incompatible types: cannot infer type-variable(s) R
[ERROR] (argument mismatch; bad return type in lambda expression
[ERROR] io.reactivex.Single<io.vertx.reactivex.ext.web.client.HttpResponse<io.vertx.reactivex.core.buffer.Buffer>> cannot be converted to io.reactivex.MaybeSource<? extends R>)
[ERROR] /Users/timofeivolkov/IdeaProjects/vertx-kubernetes-workshop/microservices-exercises/src/main/java/io/vertx/workshop/exercise/microservice/Exercise2Verticle.java:[33,22] invalid method reference
[ERROR] non-static method bodyAsString() cannot be referenced from a static context
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Process finished with exit code 1

Thanks!

cescoffier commented 5 years ago

rxGetRecord returns a Maybe (before it was returning a Single. So you need a flatMapSingle.

        discovery.rxGetRecord(svc -> svc.getName().equals("greetings"))
                .map(discovery::getReference)
                .map(serviceReference -> serviceReference.getAs(WebClient.class))
                .flatMapSingle(webClient -> webClient.get("/greetings/vert.x-low-level-api").rxSend())
                .map(HttpResponse::bodyAsString)
                .subscribe(res -> System.out.println("result from the greeting service: " + res));
tvolkov commented 5 years ago

Thanks!