vert-x3 / vertx-guide-for-java-devs

Vert.x 3 guide for Java developers
Apache License 2.0
549 stars 185 forks source link

Step 8 - Where are the rx... methods? #19

Open junglie85 opened 7 years ago

junglie85 commented 7 years ago

In Step 8, introducing RxJava the code examples refer to various methods such as rxDeletePage(id), yet there are no methods beginning with rx in the WikiDatabaseService verticle.

The Impl class has rxified the method contents, but then the signatures don't match with what is being called in HttpServerVerticle and I get errors to that extent (namely, complaints at the lack of result handler).

There is also reference to io.vertx.guides.wiki.database.rxjava.WikDatabaseService as the return type of createProxy(), yet this package does not exist in the example.

Have I missed something here? Or could you provide some clarification? Are there any plans to update this to RxJava2?

junglie85 commented 7 years ago

Okay, so it's produced by the code gen plugin. I don't recall that being mentioned in the guide and it's very confusing. Perhaps it would be possible to elaborate, such as how it knows to prefix the methods with rx and what the role of the @VertGen and @GenIgnore annotations are?

vietj commented 7 years ago

this is explained in the rx documentation, the doc should indeed elaborate about it and point to the rx doc

junglie85 commented 7 years ago

The only mention of code generation in the Rx documentation is that the Vert.x rxified API is code generated. It doesn't explain that this is how rx service proxies should be produced, why the createProxy method needs to have rxjava (or reactivex) in its package name, nor what annotations are needed. It also requires picking through the codegen documentation.

This is the sort of thing I personally consider as an essential explanation in a guide, picking up where package documentation leaves off. Up until step-8, it's spot on and very good at explaining what is going on and how different elements of the Vert.x ecosystem interoperates, then it just kind of drops off.

I know all of these things take time, and I'm very grateful for the hard work that has been put into this guide so far.

rsippl commented 5 years ago

Adding <classifier>processor</classifier> to the vertx-service-proxy dependency in pom.xml seems to fix the code generation. Without this, I'm getting this error:

java.lang.Error: Unresolved compilation problems: 
    The import io.vertx.guides.wiki.database.reactivex cannot be resolved
rsippl commented 5 years ago

Actually I was wrong, I'm getting the error above in step 8 regardless of the classifier setting. If I'm running

mvn clean
mvn package

everything seems fine. If I'm running it again, the test phase fails. Basically, it fails every second time I run the above, this happens because mvn clean doesn't work as expected. The first invocation of mvn clean removes just the generated classes, i.e. the .java files in src/main/generated, and the corresponding .class files, plus the jar files from the target dir, leaving the other class files in that same dir. A subsequent build doesn't detect the missing files, presumably because useIncrementalCompilation is set to false, and the tests fail because of missing classes. After that, a mvn clean removes the target dir completely (I don't get why).

There are three fixes:

  1. remove the whole maven-clean-plugin plugin section from pom.xml (but then a mvn clean won't delete the generated .java files anymore)
  2. add ${project.basedir}/target to the maven-clean-plugin section
  3. set useIncrementalCompilation to true

To me, 2. seems best because it leads to the expected behavior on mvn clean: run both the generated classes and the target dir.