Skip to content

Getting started with QBit Microservice Lib

Richard Hightower edited this page Aug 28, 2015 · 27 revisions

Getting started with QBit Microservice Lib Part 1

Mammatus Tech

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.

Home < Part 1 Part 2 > Part 3 >> -- -example code- -qbit docs-

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

If you are new to QBit, we suggest reading the landing page of the QBit Microservices Lib's wiki for a background on QBit.

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'

}

Look for the latest official release here of the QBit Microservice lib.

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

Find out more about wrk.

Find out more about QBit.

Clone this wiki locally