[Quick Start] Using QBit microservice lib's REST support with URI Params

fadihub edited this page Jun 8, 2015 · 8 revisions


QBit supports JSON, HTTP, REST and WebSocket. With QBit you can access a service via an HTTP client API, a high-speed WebSocket proxy and curl. As part of its REST support, it supports arguments to service methods which are URI params. You can also use request params.

You can invoke QBit services via a WebSocket proxy. The advantage of a WebSocket proxy is it allows you execute 1M RPC+ a second (1 million remote calls every second).

QBit uses the same style annotations as Spring MVC. We figure these are the ones that most people are familiar with. Since QBit focuses just on Microservices, it just supports JSON.

Using QBit microservice lib's REST support with URI Params

This wiki will walk you through a simple example to demonstrate to you how you can use a microservice remotely with WebSocket and how you can make a Rest call with URI params with QBit.

What you will build

You will build a simple Rest server, call an AdderService remotely via WebSocket, and call the AdderService via URI params. when you run this example you will get the following:

Calling the adderService async via a WebSocket proxy interface = 3

Calling the adderService via the URI parameters = 4

also with your favorite browser you can visit http://localhost:7000/services/adder-service/add/3/987 to call the AdderService and add the last two params, in this case you will get:


How to complete this guide

In order to complete this example successfully you will need the following installed on your machine:

Now that your machine is all ready let's get started:


Once this is done you can test the service, let's first explain the process:

The process will be explained in more detail under [[Detailed Tutorial] Using QBit microservice lib's REST support with URI Params ] (https://github.com/advantageous/qbit/wiki/%5BDetailed-Tutorial%5D-Using-QBit-microservice-lib's-REST-support-with-URI-Params)

EmployeeEventExampleUsingChannelsToSendEvents.java Listing


 * Copyright (c) 2015. Rick Hightower, Geoff Chandler
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *  		http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * QBit - The Microservice lib for Java : JSON, WebSocket, REST. Be The Web!

package io.advantageous.qbit.example;

import io.advantageous.boon.core.Sys;
import io.advantageous.qbit.annotation.PathVariable;
import io.advantageous.qbit.annotation.RequestMapping;
import io.advantageous.qbit.client.Client;
import io.advantageous.qbit.http.client.HttpClient;
import io.advantageous.qbit.server.ServiceEndpointServer
import io.advantageous.qbit.reactive.Callback;
import io.advantageous.qbit.system.QBitSystemManager;

import static io.advantageous.qbit.client.ClientBuilder.clientBuilder;
import static io.advantageous.qbit.http.client.HttpClientBuilder.httpClientBuilder;
import static io.advantageous.qbit.server.EndpointServerBuilder.endpointServerBuilder;

 * @author rhightower
 *         on 2/17/15.
public class SimpleRestServerWithURIParamsMain {

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

        QBitSystemManager systemManager = new QBitSystemManager();

       /* Start Service server. */
        final ServiceEndpointServer
ServiceEndpointServer server = endpointServerBuilder()

        server.initServices(new AdderService());

       /* Start QBit client for WebSocket calls. */
        final Client client = clientBuilder().setPort(7000).setRequestBatchSize(1).build();

       /* Create a proxy to the service. */
        final AdderServiceClientInterface adderService =
                client.createProxy(AdderServiceClientInterface.class, "adder-service");


       /* Call the service */
        System.out.print("Calling the adderService async via a WebSocket proxy interface = ");
        adderService.add(System.out::print, 1, 2);

        HttpClient httpClient = httpClientBuilder()

        String results = httpClient
        System.out.print("Calling the adderService via the URI parameters = ");

//        HttpResponse httpResponse = httpClient.get("/services/adder-service/foo/randomcrap/2");
//        //System.out.println(httpResponse);
//        httpResponse = httpClient.get("/services/adder-bs/foo/randomcrap/2");
//        //System.out.println(httpResponse);




    interface AdderServiceClientInterface {

        void add(Callback<Integer> callback, int a, int b);

    public static class AdderService {

        public int add(@PathVariable int a, @PathVariable int b) {

            return a + b;




Test The Service

With your terminal cd simple-rest-server-with-uri-params

then gradle clean build then gradle run and you should get the following:

Calling the adderService async via a WebSocket proxy interface = 3

Calling the adderService via the URI parameters = 4

You can also access the adderService when you visit http://localhost:7000/services/adder-service/add/3/987 to add the last two params, in this case you will get:



You have built/tested a simple Rest server, called an AdderService remotely via WebSocket and called an AdderService via URI params using QBit, see you in the next tutorial!




Getting Started




Callbacks and Reactor

Event Bus



QBit case studies

QBit 2 Roadmap

-- Related Projects

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

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.