Coder Social home page Coder Social logo

akka-http-circe-streaming-sample's Introduction

akka-http-circe-streaming-sample

Akka HTTP allows Source Streaming, i.e. indefinite, back-pressured streaming over an HTTP hop.

This repository is a sandbox for showing how that can be used, with akka-http-circe (one of the subprojects of akka-http-json) as the marshalling/unmarshalling toolkit.

Problem to solve:

Uni-directional push-based connection of two microservices, with each other.

In addition, re-connecting a connection transparently (up to a provided timeout); allowing e.g. version upgrades of the producing service without breaking the data stream at the client end. This also needs some offset mechanism, to allow consumption to continue from the same spot earlier reached.

Requirements

  • sbt

Getting started

Running tests

$ sbt test

Tests should pass, or be ignored.

Manual testing

You'll need multiple terminal windows. In the first one, let's start a server:

$ sbt run
[2] sandbox.TestRunSource
...
... Service running at http://localhost:8083

Open http://localhost:8083/data and there should be a 1.. stream of JSON objects.

You can also see the server logging the data it has pushed.

Now, let's open a client (in another terminal):

$ sbt run 
 [1] sandbox.TestRunSink
...
Data(1)
Data(2)
Data(3)
Data(4)
Data(5)
Data(6)
Data(7)
Data(8)
Data(9)
Data(10)
... 

You can open multiple clients in different terminals.

Back pressure

Have a look at the server side to see how the back pressure works.

First, stop any consumption by ctrl-s.

If the client has shown e.g. 50 values, the server still goes on creating more (up to ~ 6000..7000), but stops there (buffers full, no back pressure).

Press ctrl-q on the client, to let it cause demand. The server should start creating more values, again, always trying to keep ahead of the consumption (with me, the second stop happened at 12899).

References

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.