All Projects → calvinlfer → akka-http-streaming-response-examples

calvinlfer / akka-http-streaming-response-examples

Licence: other
A list of examples that involve streaming with Akka Streams and used together with Akka HTTP

Programming Languages

scala
5932 projects
groovy
2714 projects

Projects that are alternatives of or similar to akka-http-streaming-response-examples

typebus
Framework for building distributed microserviceies in scala with akka-streams and kafka
Stars: ✭ 14 (-80.82%)
Mutual labels:  akka-http, akka-streams
Squbs
Akka Streams & Akka HTTP for Large-Scale Production Deployments
Stars: ✭ 1,365 (+1769.86%)
Mutual labels:  akka-http, akka-streams
Es Cqrs Shopping Cart
A resilient and scalable shopping cart system designed using Event Sourcing (ES) and Command Query Responsibility Segregation (CQRS)
Stars: ✭ 19 (-73.97%)
Mutual labels:  akka-http, akka-streams
reactive-streams-for-java-developers
No description or website provided.
Stars: ✭ 16 (-78.08%)
Mutual labels:  akka-http, akka-streams
Quark
Quark is a streaming-first Api Gateway using Akka
Stars: ✭ 13 (-82.19%)
Mutual labels:  akka-http, akka-streams
Scale
Another example of a REST API with Akka HTTP
Stars: ✭ 23 (-68.49%)
Mutual labels:  akka-http, akka-streams
akka-http-circe-json-template
Akka HTTP REST API Project Template using Akka HTTP 10.0.4 with Circe 0.7.0 targeting Scala 2.12.x
Stars: ✭ 21 (-71.23%)
Mutual labels:  akka-http, akka-streams
Otoroshi
Lightweight api management on top of a modern http reverse proxy
Stars: ✭ 177 (+142.47%)
Mutual labels:  akka-http, akka-streams
akka-cqrs-activator
Issue tracker PoC application written in Scala (Akka) and JavaScript (React) that demonstrates event sourcing and CQRS
Stars: ✭ 33 (-54.79%)
Mutual labels:  actors, akka-http
fdp-modelserver
An umbrella project for multiple implementations of model serving
Stars: ✭ 47 (-35.62%)
Mutual labels:  akka-http, akka-streams
slicebox
Microservice for safe sharing and easy access to medical images
Stars: ✭ 18 (-75.34%)
Mutual labels:  akka-http, akka-streams
akka-cookbook
提供清晰、实用的Akka应用指导
Stars: ✭ 30 (-58.9%)
Mutual labels:  akka-http, akka-streams
khermes
A distributed fake data generator based in Akka.
Stars: ✭ 94 (+28.77%)
Mutual labels:  akka-http, akka-streams
chat-here
A responsive chat room based on Laravel5.4 and GatewayWorker3.0. (基于 Laravel 5.4 和 GatewayWorker 3.0 的响应式聊天室。)
Stars: ✭ 24 (-67.12%)
Mutual labels:  chat-room
The-chat-room
Python 版的多人聊天室, 图形界面版
Stars: ✭ 100 (+36.99%)
Mutual labels:  chat-room
MuezzinAPI
A web server application for Islamic prayer times
Stars: ✭ 33 (-54.79%)
Mutual labels:  actors
otp
📫 Fault tolerant multicore programs with actors
Stars: ✭ 169 (+131.51%)
Mutual labels:  actors
jwt-akka-http
An example how to implement a very simple authentication and authorization with Akka HTTP. Related to https://blog.codecentric.de/en/2017/09/jwt-authentication-akka-http
Stars: ✭ 23 (-68.49%)
Mutual labels:  akka-http
comicchat
Web client and node.js server based off Microsoft Comic Chat.
Stars: ✭ 109 (+49.32%)
Mutual labels:  chat-room
Fibrous
Concurrency library for .Net
Stars: ✭ 47 (-35.62%)
Mutual labels:  actors

Examples using Akka HTTP with Streaming

A list of examples that involve streaming with Akka Streams and used together with Akka HTTP. The Akka-HTTP specific details are isolated into the following traits:

The initialization logic to start the Akka HTTP server is kept in ServerMain.

Focusing on HTTP Chunked Streaming Routes:

  • streaming-text - This uses predefined Sources and throttling in order to give the user a chunked response in a controlled manner
  • actor-text - This is more involved, we define an Actor that respects Akka Streams backpressure and then create a Source from this. The Akka Scheduler constantly tells the Actor to emit messages into the Stream that the user sees. This logic is placed within the Actor. If you use a web browser and stop the streaming response then you will cancel the stream and shut down the actor. Feel free to open this up on multiple browsers since we allocate an actor per request
  • alt-actor-text - This is similar to actor-text except it uses mapMaterializedValue to access the materialized ActorRef and schedules messages to be sent constantly (in addition to the scheduler sending messages inside the Actor)
  • live-actor-text - This is slightly different from the other actor endpoints. It creates a live actor and places it into a Publisher and creates a Source from this. We publish messages in the same way as the previous examples
  • streaming-json - This is an example of a JSON streaming route. We define a JSON Marshaller for a case class here and we add a few imports for streaming support in order to have streaming JSON. You can customize the separators as well.
  • consuming-streaming-json - This is an example of an endpoint that consumes a Streaming JSON request. This also relies on having JSON Streaming support.
  • streaming-sse-json - This is an example of Streaming JSON using Server Sent Events with the help of Heiko Seeberger's Akka-SSE library. SSEs have better integration with modern day browsers.

Focusing on the WebSocket Routes:

  • ws-simple - This can be accessed via ws://localhost:9000/ws-simple, it uses a stateless Akka Streams Flow in order to echo back the message. The input to the Flow represents the WebSocket messages coming from the WebSocket Client and the output to the Flow represents the messages that are being sent to the WebSocket Client
  • ws-chat - This is an implementation of an online chat-room, it shows how to integrate Actors with Streams in order to create it. All credits go to Johan Andrén for his excellent work and explanations on setting this up. This example involves creating a Flow from a Source and a Sink. I have provided my explanation and a diagram to help you understand how this works. Essentially a Flow can be modelled as a Sink and a Source underneath the hood as illustrated by the diagram. If you choose to go about thinking in this manner then you have full control over the Flow (as in what the Flow accepts and what the Flow emits). We use Actors underneath the hood to perform the coordination between the accepting and emitting of Flow controlling messages to and from WebSocket clients.

Chat Room Flow construction Overview

WebSocket Clients connect to the Chat-Room via ws://localhost:9000/ws-chat and a Flow is created. Let's take a look at the inner workings of this Flow:

  • First an intermediate Actor is created (per WebSocket Client connection) that is meant to act as the bridge between the WebSocket Actor (more on this below) and the Chat Room Actor
  • The Flow is composed from a Sink and a Source. Take a look at the diagram before coming back here.
    • The Sink (inside the Flow) represents messages coming in from WebSocket clients, we use Sink.actorRef(intermediate Actor) so that the intermediate Actor will now receive messages whenever the WebSocket Source sends us messages
    • The Source (inside the Flow) represents messages sent to the WebSocket clients, we use Source.actorRef along with mapMaterializedValue to get access to the materialized ActorRef that we use to send messages to, in order for messages to be sent to the WebSocket client
  • We create a Flow from the Sink and the Source which now represents each WebSocket connection between our server and the WebSocket clients

Note: Websocket clients can be found here: Online WebSocket Tester, Dark WebSocket Client, etc.

Contributions and PRs

Please feel free to send in PRs and contributions and we can review them together and see whether they are small and cohesive enough to fit into the project

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].