All Projects → nyukhalov → akka-http-actor-per-request

nyukhalov / akka-http-actor-per-request

Licence: MIT license
Example akka application that uses the actor per request model

Programming Languages

scala
5932 projects

Projects that are alternatives of or similar to akka-http-actor-per-request

Otoroshi
Lightweight api management on top of a modern http reverse proxy
Stars: ✭ 177 (+1006.25%)
Mutual labels:  akka, akka-http
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 (+31.25%)
Mutual labels:  akka, akka-http
Akka Management
Akka Management is a suite of tools for operating Akka Clusters.
Stars: ✭ 218 (+1262.5%)
Mutual labels:  akka, akka-http
Akka Http Quickstart Scala.g8
Stars: ✭ 103 (+543.75%)
Mutual labels:  akka, akka-http
akka-cookbook
提供清晰、实用的Akka应用指导
Stars: ✭ 30 (+87.5%)
Mutual labels:  akka, akka-http
Kebs
Scala library to eliminate boilerplate
Stars: ✭ 113 (+606.25%)
Mutual labels:  akka, akka-http
akka-http-quickstart-java.g8
akka.io
Stars: ✭ 17 (+6.25%)
Mutual labels:  akka, akka-http
Akka Http
The Streaming-first HTTP server/module of Akka
Stars: ✭ 1,163 (+7168.75%)
Mutual labels:  akka, akka-http
protoactor-python
Proto Actor - Ultra fast distributed actors
Stars: ✭ 78 (+387.5%)
Mutual labels:  akka, actor-model
Quark
Quark is a streaming-first Api Gateway using Akka
Stars: ✭ 13 (-18.75%)
Mutual labels:  akka, akka-http
Squbs
Akka Streams & Akka HTTP for Large-Scale Production Deployments
Stars: ✭ 1,365 (+8431.25%)
Mutual labels:  akka, akka-http
khermes
A distributed fake data generator based in Akka.
Stars: ✭ 94 (+487.5%)
Mutual labels:  akka, akka-http
Scala Ddd Example
🎯 λ Hexagonal Architecture + DDD + CQRS applied in Scala using Akka HTTP
Stars: ✭ 86 (+437.5%)
Mutual labels:  akka, akka-http
Akka
Build highly concurrent, distributed, and resilient message-driven applications on the JVM
Stars: ✭ 11,938 (+74512.5%)
Mutual labels:  akka, actor-model
Swagger Akka Http Sample
Sample demonstrating use of swagger-akka-http
Stars: ✭ 79 (+393.75%)
Mutual labels:  akka, akka-http
akka-react-cloudant
A Soccer Dashboard created by scraping EPL website using Akka backend and ReactJS frontend and IBM Cloudant for object storage. IBM Cloud Foundry is used to host both frontend and backend app.
Stars: ✭ 21 (+31.25%)
Mutual labels:  akka, akka-http
Nact
nact ⇒ node.js + actors ⇒ your services have never been so µ
Stars: ✭ 848 (+5200%)
Mutual labels:  akka, actor-model
Spark As Service Using Embedded Server
This application comes as Spark2.1-as-Service-Provider using an embedded, Reactive-Streams-based, fully asynchronous HTTP server
Stars: ✭ 46 (+187.5%)
Mutual labels:  akka, akka-http
akka-cqrs-activator
Issue tracker PoC application written in Scala (Akka) and JavaScript (React) that demonstrates event sourcing and CQRS
Stars: ✭ 33 (+106.25%)
Mutual labels:  akka, akka-http
slicebox
Microservice for safe sharing and easy access to medical images
Stars: ✭ 18 (+12.5%)
Mutual labels:  akka, akka-http

Akka HTTP Actor Per Request

This project provides an example akka application that uses the Actor per request model. The project is based on NET-A-PORTER spray-actor-per-request repository.

Why would you want to spin up an Actor for each HTTP request?

  • Easily manage a tree of request scoped Actors in the application core
  • The per request actor can clean them up in the event of a timeouts and failures
  • Leverage the actor supervision hierarchy to propogate failures up to the RequestContext, so you can return useful error responses
  • Promote Tell, Don't Ask
  • Using request scoped Actors in the application core can make it easier to use tell (!) over ask (?)

Resources:

  • Scala Exchange Presentation (video)
  • Mathias describes the actor per request approach against others. (mailing list)

Example App

Overview

This example application provides an API to get a list of pets with their owners. There are already two actors that provide a list of pets and a list of animals and the responsibility of this application is to simply aggregate these two together.

Our application is made up of three modules:

  • Application Core - The core module contains the business logic for our application. In this example this is how we aggregate pets with their owners.
  • Routing - The routing module contains our akka routing which describes our RESTful endpoints. It also contains our PerRequest actor which bridges the gap between the routing and the core modules and contains the piece of code this example project aims to demonstrate.
  • Clients - Our code to consume two existing actors that provide us with a list of pets and a list of owners. These actors could use databases, RESTful APIs, etc. It doesn't really matter for the purposes of this example.

Ideally modules these would be in separate sub-projects to prevent unnecessary compile time dependencies, however for simplicity purposes they are just kept in separate packages in this example.

Running

sbt run

Successful request

If we request the pet Lassie:

GET http://localhost:38080/pets?names=Lassie

We get a successful response:

{
  "pets": [
    {
      "name": "Lassie",
      "owner": {
        "name": "Jeff Morrow"
      }
    }
  ]
}

In this scenario, any request scoped actors in the application core are stopped by the PerRequest actor.

Request Timeouts

Tortoises are slow. If we request a tortoise the PetClient will not reply to our application core quick enough. The timeout of 2 seconds in our PerRequest actor will happen first.

GET http://localhost:38080/pets?names=Tortoise

{
  "message": "Request timeout"
}

In this scenario, any request scoped actors in the application core are stopped by the PerRequest actor.

Validation

You shouldn't keep a Lion as a pet. Quite frankly they are too dangerous.

GET http://localhost:38080/pets?names=Lion

{
  "message": "Lions are too dangerous!"
}

In this scenario, our application core returns a generic Validation message to our PerRequest actor to complete. Any request scoped actors in the application core are stopped by the PerRequest actor.

Failures

What about unexpected failures? There is a "bug" in our application core that throws a PetOverflowException if we request too many pets:

GET http://localhost:38080/pets?names=Lassie,Tweety,Tom

{
  "message": "PetOverflowException: OMG. Pets. Everywhere."
}

Any failures that not handled by the application core can be escalated up to the supervision strategy in our PerRequest actor. The PerRequest actor is too generic to recover from any business logic failures, so it will simply handle all failures by completing the request with an error response. Any request scoped actors in the application core are stopped by the PerRequest actor.

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].