GithubHelp home page GithubHelp logo

test-mass-forker-org-1 / reactivelab Goto Github PK

View Code? Open in Web Editor NEW

This project forked from netflix/reactivelab

0.0 0.0 0.0 581 KB

Experiments and prototypes with reactive application design.

License: Apache License 2.0

JavaScript 13.66% Python 1.14% Java 68.23% CSS 6.82% HTML 10.14%

reactivelab's Introduction

ReactiveLab

Experiments and prototypes with reactive application design using service-oriented architecture concepts.

Start discovery server using StartEurekaServer.java

./gradlew startDiscovery

Start gateway server using StartGatewayServer.java or Gradle:

./gradlew startGateway

Simulation of middle-tier RPC/RESTful services exposing endpoints over HTTP.

Start several services on different ports using StartMiddleTierServices.java or Gradle:

./gradlew startServices

Server

See how Netty and RxJava are used as an HTTP server in GatewayServer

Basics are:

        RxNetty.createHttpServer(8080, (request, response) -> {
            System.out.println("Server => Request: " + request.getPath());
            ... handle requests here ...
        }).startAndWait();

Client

Clients using Netty and RxJava can be seen in the clients package.

Basic example:

        return RxNetty.createHttpClient("localhost", 9100)
                .submit(HttpClientRequest.createGet("/mock.json?id=" + id));

Hystrix

Here is a batch request using SSE inside a HystrixObservableCommand for fault-tolerance: BookmarksCommand.

A HystrixObservableCollapser can be put in front of that command to allow automated batching: BookmarkCommand.

Composition

Nested, parallel execution of network requests can be composed using RxJava and Hystrix as demonstrated in RouteForDeviceHome which is the example running at the /device/home endpoint.

Here is a portion of the code to show the composition:

        return new UserCommand(userId).observe().flatMap(user -> {
            Observable<Map<String, Object>> catalog = new PersonalizedCatalogCommand(user).observe()
                    .flatMap(catalogList -> {
                        return catalogList.videos().<Map<String, Object>> flatMap(video -> {
                            Observable<Bookmark> bookmark = new BookmarkCommand(video).observe();
                            Observable<Rating> rating = new RatingsCommand(video).observe();
                            Observable<VideoMetadata> metadata = new VideoMetadataCommand(video).observe();
                            return Observable.zip(bookmark, rating, metadata, (b, r, m) -> {
                                return combineVideoData(video, b, r, m);
                            });
                        });
                    });

            Observable<Map<String, Object>> social = new SocialCommand(user).observe().map(s -> {
                return s.getDataAsMap();
            });

            return Observable.merge(catalog, social);
        }).flatMap(data -> {
            return response.writeAndFlush(new ServerSentEvent("", "data", SimpleJson.mapToJson(data)), EdgeServer.SSE_TRANSFORMER);
        });

This results in 7 network calls being made, and multiple bookmark requests are automatically collapsed into 1 network call. Here is the HystrixRequestLog that results from the code above being executed:

Server => Hystrix Log [/device/home] => UserCommand[SUCCESS][191ms], PersonalizedCatalogCommand[SUCCESS][50ms], SocialCommand[SUCCESS][53ms], RatingsCommand[SUCCESS][65ms]x6, VideoMetadataCommand[SUCCESS][73ms]x6, BookmarksCommand[SUCCESS, COLLAPSED][25ms], BookmarksCommand[SUCCESS, COLLAPSED][24ms]

reactivelab's People

Contributors

benjchristensen avatar mattrjacobs avatar amit-git avatar qiangdavidliu avatar hza avatar randgalt avatar quidryan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.