Rick

Rick
Rick

Tuesday, May 12, 2015

Vertx 3 looks amazing, nice reactive microservices framework/lib

It looks like Vertx 3 is a very significant release. It fills many gaps and fixes direction with Vertx 2 (which was already very compelling). Vertx 3 seems even more targeted at the reactive microservice space. It adds support for pluggable messaging, it has more than one cluster manager, it has async MySQL support, as well as async support for Redis, and PostgreSQL support, and MongoDB. (We are not using any of those but at least there are patterns in play for Cassandra). 

A web style framework to make dealing with Vertx core HTTP a little smoother, etc.

Anyway.. I used Vertx 2 quite a bit, and am very interested in Vertx 3. 

QBit is mostly based on Vertx2. Many ideas for QBit came straight out of working with Vertx2. I am a big fan.

I plan on porting QBit to Vertx3 very soon.

Also most of the examples are using Vertx2 more like a lib than using Vertx as described in the docs. I want to start to change that and have more examples of working with QBit inside of Vertx.

I really like direction of having a pluggable cluster manager in vertx3. It was pluggable before but only one plugin. I can see someone plugging in ZooKeeper, or Consul or what have you. I tend to use Consul personally because service clients are often written in non-JVM environments (that I work with anyway) and Consul has clients for most non-JVM clients. 

Apex looks like a nice way to organize the needed gaps between traditional web frameworks and something like Vertx. I like that it is separate (at least in the docs), and well documented. I could have really used that level of support with my first Vertx project (I think some of the feature were there but certainly not so clear cut).

The integration with Dropwizard Metrics looks spot on (Microservices Metrics, Stats and monitoring are essential for microservices). I hope to see some future integration with StatsD/Graphite. Not sure how easy/hard that would be. 

Messaging and Integration supports seems really nice. QBit does a lot of messaging. Early versions (non released) of QBit could plug into the Vertx pub/sub or use its own for same JVM. QBIt then just used it own (with the goal of one day working with Vertx again) and a remote one based on Vertx Websocket support. I was planning on porting QBit to work over Kafka. Now I am more likely to make it work with Vertx again, and then write a Vertx messaging plugin for Kafka.

Currently, I am using Consul (it is in theory pluggable) in QBit to find peer nodes and broadcast events to other peers using WebSocket support via Vertx 2. When I port QBit to Vertx 3, I will try to use the Vertx clustering support to find peers, etc. Not sure if that exists, but it would be something that I would be interested in working on. This way Vertx 3 handles the plumbing. 


QBit has this type of support that works with Vertx 2.

@RequestMapping("/todo-service")
public class TodoService {

    @RequestMapping("/todo/count")
    public int size() {...

    @RequestMapping("/todo/")
    public List<TodoItem> list() {...



 Then it would add REST support (JSON only) for that object. 

It implements the full REST style URL mapping...

Adder Service using URI params

    @RequestMapping("/adder-service")
    public class AdderService {

        @RequestMapping("/add/{0}/{1}")
        public int add(@PathVariable int a, @PathVariable int b) {...
    }

REST is really about links in the docs and less about the URLs but most Java folks (that I have worked with) are more concerned about the URL style. (Usually not me per se.)

Using a microservice remotely with WebSocket

       /* Start QBit client for WebSocket calls. */
        final Client client = clientBuilder()
                   .setPort(7000).setRequestBatchSize(1).build();


       /* Create a proxy to the service. */
        final AdderServiceClientInterface adderService =
                client.createProxy(AdderServiceClientInterface.class, 
                "adder-service");

        client.start();



       /* Call the service */
        adderService.add(System.out::println, 1, 2);

It works with Vertx2 now. There is also a strongly typed message bus that works remotely (https://github.com/advantageous/qbit/wiki/%5BDetailed-Tutorial%5D-Using-event-channels-and-strongly-typed-event-bus-with-QBit-(The-employee-example)). The strongly typed message bus is using Consul to find remote nodes.


It needs this method from "clustering" / "service discovery" piece.

public interface ServiceDiscovery extends Startable, Stoppable {
...

    default List<ServiceDefinition> loadServices(final String serviceName) {

        return Collections.emptyList();
    }
 

...


public class ServiceDefinition {

    private final HealthStatus healthStatus;
    private final String id;
    private final String name;
    private final String host;
    private final int port;
    private final long timeToLive;


If I had a magic genie... and I could make three Vertx 3 wishes.


1) A service discovery pluggable thing on top of clustering support  (which may or may not already exist) 
3) Integration with StatsD as a metrics stats collection framework (http://rick-hightower.blogspot.com/2015/05/working-with-statsd-and-java.html)


No comments:

Post a Comment

Kafka and Cassandra support, training for AWS EC2 Cassandra 3.0 Training