Skip to content

Getting started with QBit Microservice Lib

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

Mammatus Tech

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.

Clone this wiki locally