Escolar Documentos
Profissional Documentos
Cultura Documentos
Reactive
Semantically overloaded term
2
Reactive as
Reactive as Responsive
Quickly prompt to user actions
No Blocking operation
No Synchronization
No Resource hogging
Actor
TL;DR
The actor model in computer science is a mathematical model of
concurrent computation that treats "actors" as the universal primitives of
concurrent computation.
In response to a message that it receives, an actor can: make local
decisions, create more actors, send more messages, and determine how to
respond to the next message received. Actors may modify private state, but
can only affect each other through messages (avoiding the need for any
locks).
[Wikipedia]
Actor model for dummies
A different way to concurrency
Actors, !Threads
Actor Mailbox
Actor
Actor model
Actor is lightweight
o Little overhead over creating an object
o May be used to hold request context
Per-request Actors: a common pattern
Supervision
Collaborating Actors
Dependency Injection
o Akka: Actor Refs (location/lifecycle transparent) object refs
Supervision hierarchy
Failure handling
Implementing Reactive principles
Micro
Plain Java
o CompletableFuture
o Non-blocking Servlets
o Low level NIO (!)
Akka
o Actors REACT to messages: never blocks waiting.
o Have to use some discipline not to block
e.g. waiting for a response from a synchronous resource
Timeouts handlings
Handle timeouts,
for resiliency
Micro
Plain Java
o Not easy to handle timeouts consistently ...unhandled or use default
Akka
o Everything has an explicit timeout impossible to forget
o Actor message receiving timeout handler
Handling Failure, Asynchronously
Plain Java/Spring
o Write your own Event Sourcing Concursus
at Micro
Simpler, more testable concurrent code
Requires less discipline then plain Java 8
A new programming model to learn
Does Akka help?
at Macro
Still requires discipline at architectural level
Akka forces to reinvent a lot of wheels on integration
Akka doesnt integrate with Spring
Akka and Services
Akka/Actor model
Services:
NOT mutually exclusive
Akka project
https://github.com/akka/akka
Thanks!
Questions?