Skip to content

Making QBit Friendly with Docker, Mesos, and Heroku

Richard Hightower edited this page Jul 8, 2015 · 1 revision

Here is an example of how to change the root address from /services to something else. And this is also an example of working with the Docker, Mesos, Heroku friendly version of QBit.

package qbit.todo;

import io.advantageous.qbit.admin.ManagedServiceBuilder;

import io.advantageous.qbit.server.ServiceEndpointServer;


public class TodoRestServer {



    public static void main(String... args) {


        final ManagedServiceBuilder managedServiceBuilder = ManagedServiceBuilder.managedServiceBuilder();

        final ServiceEndpointServer serviceServer = managedServiceBuilder.getEndpointServerBuilder().setUri("/mrs")
                .build()
                .initServices(new TodoService()).startServer();

        /* Wait for the service to shutdown. */
        managedServiceBuilder.getSystemManager().waitForShutdown();

    }




}
...
package qbit.todo;

import io.advantageous.qbit.annotation.*;


/**
 * Created by rhightower on 2/10/15.
 */
@RequestMapping("/todoservice")
public class TodoService {


    @RequestMapping("/todoo")
    public Todo list() {
        return new Todo("Hello");
    }

}
...
package qbit.todo;

public class Todo {
    private final String todo;
    private final long time = System.currentTimeMillis();

   public Todo(String todo) {
       this.todo = todo;
   }
}

You can run this curl command.

$  curl http://localhost:9090/mrs/todoservice/todoo
{"todo":"Hello","time":1436378304880}

With the ManagedServiceBuilder you can also get health and stats.

curl  http://localhost:9090/__stats/
{
    "MetricsKV": {},
    "MetricsMS": {},
    "MetricsC": {
        "TodoService": 1,
        "TodoService.startBatchCount": 2,
        "TodoService.receiveCount": 2
    },
    "version": 1
}

curl  http://localhost:9090/__stats_instance
{"MetricsKV":{},"MetricsMS":{},"MetricsC":{"TodoService.startBatchCount":1,"TodoService.receiveCount":1},"version":1}
$ curl  http://localhost:9090/__health
"ok"

There are flags to turn that off. And you also get a CTRL-C to nicely shutdown all of the services. :)

It also reads $WEB_PORT and then $PORT from the enviroment variables. This way is plays nice in Heroku or Docker or Mesos.

You can also get rid of the root URI altogher as follows:

    public static void main(String... args) {


        final ManagedServiceBuilder managedServiceBuilder = ManagedServiceBuilder.managedServiceBuilder();

        final ServiceEndpointServer serviceServer = managedServiceBuilder.getEndpointServerBuilder().setUri("/")
                .build()
                .initServices(new TodoService()).startServer();

        /* Wait for the service to shutdown. */
        managedServiceBuilder.getSystemManager().waitForShutdown();

    }

Then to curl you would do this:

$  curl http://localhost:9090/todoservice/todoo
{"todo":"Hello","time":143637868275}

Tutorials

__

Docs

Getting Started

Basics

Concepts

REST

Callbacks and Reactor

Event Bus

Advanced

Integration

QBit case studies

QBit 2 Roadmap

-- Related Projects

Kafka training, Kafka consulting, Cassandra training, Cassandra consulting, Spark training, Spark consulting

Clone this wiki locally