Rick

Rick
Rick

Sunday, August 30, 2015

Getting started with QBit Microservice Lib Part 1

QBit is a reactive programming lib for building microservices - JSON, HTTP, WebSocket, and REST. QBit uses reactive programming to build elastic REST, and WebSockets based cloud friendly, web services. QBit is SOA evolved for mobile and cloud computing. QBit is a small lightweight lib that provides support for ServiceDiscovery, Health, reactive StatService, typed events, and Java idiomatic reactive programming for Microservices.

If you are new to QBit. It might make more sense to skim the overview. We suggest reading the landing page of the QBit Microservices Lib's wiki for a background on QBit. This will let you see the forrest while the tutorials are inspecting the trees. There is also a lot of documents linked to off of the wiki landing page as well as in the footer section of the tutorials.

Getting started with QBit Microservice Lib Part 1

Mammatus Tech
QBit is a reactive programming lib for building microservices - JSON, HTTP, WebSocket, and REST. QBit uses reactive programming to build elastic REST, and WebSockets based cloud friendly, web services. QBit is SOA evolved for mobile and cloud computing. QBit is a small lightweight lib that provides support for ServiceDiscovery, Health, reactive StatService, typed events, and Java idiomatic reactive programming for Microservices.
QBit is small and wicked fast.
QBit is wicked fast
Learn gradle.

Setup gradle build file

group 'qbit-ex'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'application'

mainClassName = "com.mammatustech.HelloWorldService"

compileJava {
    sourceCompatibility = 1.8
}

repositories {
    mavenCentral()
    mavenLocal()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
    compile group: 'io.advantageous.qbit', name: 'qbit-admin', 
                                                 version: '0.9.0-M1'
    compile group: 'io.advantageous.qbit', name: 'qbit-vertx', 
                                                 version: '0.9.0-M1'

}

Java code for hello world QBit

package com.mammatustech;

import io.advantageous.qbit.admin.ManagedServiceBuilder;
import io.advantageous.qbit.annotation.RequestMapping;

@RequestMapping("/hello")
public class HelloWorldService {

    @RequestMapping("/hello")
    public String hello() {
        return "hello " + System.currentTimeMillis();
    }

    public static void main(final String... args) {
        final ManagedServiceBuilder managedServiceBuilder =
                ManagedServiceBuilder.managedServiceBuilder()
                                     .setRootURI("/root");

        /* Start the service. */
        managedServiceBuilder.addEndpointService(new HelloWorldService())
                .getEndpointServerBuilder()
                .build().startServer();

    }
}
Run the app.

Run the app

$ gradle run

Hit the app with curl

$ curl http://localhost:8080/root/hello/hello
"hello 1440742489358"

Hit the app a lot with wrk

$ wrk -d 5s -t 2 -c 1000 http://localhost:8080/root/hello/hello
Running 5s test @ http://localhost:8080/root/hello/hello
  2 threads and 1000 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    17.65ms   22.96ms 427.36ms   97.57%
    Req/Sec    33.33k     7.75k   43.10k    75.00%
  319154 requests in 5.06s, 28.00MB read
Requests/sec:  63083.97
Transfer/sec:      5.53MB

Conclusion

You can find more information reading the tutorials and looking at the wiki. If you are new to QBit, please take some time to skim the overview to QBit Microservices. After you skim the overview, look into QBit batteries included microservice lib to get a feel for how QBit supports the full ethos of Microservices Architecture (as it supports monitoring, health checks, service discovery, api gateways, etc.). Check out the introduction to QBit reactive programming model to get a feel for the depth of QBit and how QBit supports coordinating async callbacks. To get a real feel for what it means to be an idiomatic Java lib for microservices read about the Event Bus and Type event bus. Keep in mind that QBit is pluggable and you can plug in additional event busses (KafkaAeron, etc.) as well as plugin different protocol parsers (Thrift, Message Pack) or JSON parsers (Jackon, GSON), etc.), but still keep the same idiomatic Java programming model. This is just the start of your QBit journey. There is much to explore.
Kafka and Cassandra support, training for AWS EC2 Cassandra 3.0 Training