Regarding my earlier posts on something Spring Boot like for Vert.x and after my evaluation of Vert.x Zero Up there is one idea that I still would like to try out, basically combining JSR 311 Resources with RxJava 2 directly on the resource level.

Usually resource code would look like this:

@GET
@Path("example")
@Produces(MediaType.TEXT_PLAIN)
public void getExample(@Suspended final AsyncResponse asyncResponse) {
    Single.just("Hello World").subscribe(asyncResponse::resume, asyncResponse::resume);
}

There are two boilerplaty things in here that I really would like to get rid of, the start of the Rx flow and the actual response subscription.

From my point of view it would make sense to abstract that away and enable rx flows directly:

@GET
@Path("example")
@Produces(MediaType.TEXT_PLAIN)
public Single<String> getExample() {
    return Single.just("Hello World");
}

@POST
@Path("examplePost")
@Produces(MediaType.TEXT_PLAIN)
public Single<String> postExample(Single<ExampleBody> request) {
    return request.map(service::doSomething).map(mapper::mapResponse);
}

Let’s see if there is way to generate the boilerplate around that and use rxified resources.

One thought on “JSR 311 and RxJava 2 in “Vert.x Boot”

Comments are closed.