Skip to content
Ob1k - The RPC Framework
Java Scala Shell
Failed to load latest commit information.
ob1k-cache [maven-release-plugin] prepare for next development iteration May 31, 2016
ob1k-concurrent [maven-release-plugin] prepare for next development iteration May 31, 2016
ob1k-consul [maven-release-plugin] prepare for next development iteration May 31, 2016
ob1k-core [maven-release-plugin] prepare for next development iteration May 31, 2016
ob1k-cql [maven-release-plugin] prepare for next development iteration May 31, 2016
ob1k-db [maven-release-plugin] prepare for next development iteration May 31, 2016
ob1k-example [maven-release-plugin] prepare for next development iteration May 31, 2016
ob1k-http [maven-release-plugin] prepare for next development iteration May 31, 2016
ob1k-jetty [maven-release-plugin] prepare for next development iteration May 31, 2016
ob1k-security [maven-release-plugin] prepare for next development iteration May 31, 2016
ob1k-spring [maven-release-plugin] prepare for next development iteration May 31, 2016
ob1k-swagger [maven-release-plugin] prepare for next development iteration May 31, 2016
util-config [maven-release-plugin] prepare for next development iteration May 31, 2016
util-metrics [maven-release-plugin] prepare for next development iteration May 31, 2016
.gitignore making it independant of OB code - WIP Jun 29, 2014
.travis.yml use only java8 Mar 18, 2015
LICENSE adding license information Oct 5, 2015
README.md updated README.md with latest changes i.e new builder and swagger Dec 14, 2015
findbugs-exclude.xml Add find bugs plugin to ob1k compilation Feb 29, 2016
pom.xml [maven-release-plugin] prepare for next development iteration May 31, 2016

README.md

Ob1k - A modern RPC Framework

Build Status Download

Overview and Motivation

Ob1k is an asynchronous light-weight RPC framework for rapid development of async, high performance micro services. You can start an Ob1k embedded server from your code and once started it will serve HTTP requests based on the endpoints you have configured. Unlike traditional servlet containers, Ob1k is based on Netty asynchronous event-driven model, and uses a fixed thread-per-core pool for serving. The coordination of an asynchronous request is performed by using composable futures which enable you to easily compose and combine asynchonous operations.

Anatomy

Ob1k project consists of the following sub libraries:

  • ob1k-concurrent - Introduces composable futures, an alternative implementation of futures in Java.
  • ob1k-core - RPC framework client and server infrastructure.
  • ob1k-http - Ob1k's asynchronous http client
  • ob1k-db - A composable futures based asynchronous MySQL client.
  • ob1k-cache - A composable futures based asynchronous Memcached client, and guava cache wrapper.
  • ob1k-cql - A composable futures based asynchronous Cassandra client.
  • ob1k-security - Authentication and authorization for Ob1k.
  • ob1k-consul - Ob1k based Consul API which simplifies registration and discovery for Ob1k services.
  • ob1k-swagger - Ob1k swagger plugin that will generate the Swagger APi protocol and also provide the Swagger UI.

Getting started

Micro services architecture consists of a group of different services which communicate with each other. Ob1k supplies the infrastructure to build such microservices and the means for them to communicate. The communication between services is based on a RPC protocol, (HTTP with JSON or MessagePack payload), using a user provided, strongly typed interface. That said, the Ob1k server is actually an HTTP server, and you can use your favorite HTTP client to talk to your service, though we recommend you use ours ;)

Ob1k Server

Let's start with creating an Ob1k server. Create a new maven project and add dependency to ob1k-core in your pom:

<dependency>
  <groupId>com.outbrain.ob1k</groupId>
  <artifactId>ob1k-core</artifactId>
  <version>x.y</version>
</dependency>

The next step will be to create a service endpoint. A service endpoint is an interface and an implementation. Each method in the implementation will be mapped to a URL which clients as well as a simple web browsers can invoke. In the next example we are create a service with an endpoint named helloWorld which gets no arguments and returns a string.

public interface IHelloService extends Service {
   ComposableFuture<String> helloWorld();
}

The method implementation just returns a "Hello world" string which will be returned by the Ob1k framework to the client:

public class HelloService implements IHelloService {
   @Override
   public ComposableFuture<String> helloWorld() {
     return fromValue("Hello World!");
   }
}

Now that you have the service endpoint we can build the Ob1k server. For that, we will need to set the port to use and the base URL which is called context. In addition we need to bind our services to a URL under the context. After setting some more properties (e.g. requestTimeout) we call the build method and this creates a server.

Server server = ServerBuilder.newBuilder().
  contextPath("/services").
  configure(builder -> builder.usePort(8080).requestTimeout(50, TimeUnit.MILLISECONDS)).
  service(builder -> builder.register(new HelloService(), "/hello")).
  build();

To start the server:

server.start(); 

Now you can access the service endpoint just go to http://localhost:8080/services/hello/helloWorld

Ob1k Client

Now we are going to create an Ob1k client. Most of the times Ob1k clients are going to be executed inside an Ob1k service, but for simplicity we will show just the client code for now. We use the ClientBuilder to build the client by specifying a target URL, the interface of the service we're invoking, content type (which is controlled by the client) and can be either JSON or MessagePack, timeouts, etc.

final String target = "http://localhost:8080/services/hello";
final IHelloService helloService = new ClientBuilder<>(IHelloService.class).
            setProtocol(ContentType.JSON).
            setRequestTimeout(-1).
            setTargetProvider(new SimpleTargetProvider(target)).
            build();

Now that we have helloService we can invoke methods on it which will be directed automatically to the server.

final ComposableFuture<String> helloWorld = helloService.helloWorld();
System.out.println(helloWorld.get());

And that's it :)

Examples

More examples can be found here ob1k-example

Links

Ob1k Presentation Slides

License

Ob1k is released under version 2.0 of the Apache License.

Something went wrong with that request. Please try again.