-
Notifications
You must be signed in to change notification settings - Fork 45
Effects
Bartosz Sypytkowski edited this page Dec 17, 2015
·
7 revisions
One of the major differences between Akkling and core Akka.FSharp APIs is concept of Effects. Effect a special descriptor, which may be returned from actor loop, that will cause it to perform some specific action. Currently Akkling core library defines following set of effects:
-
Unhandled
will cause message received in current recursive iteration to be marked as unhandled. By default unhandled messages will be send to dead letters event stream. -
Stop
will cause current actor to immediately stop. It will sendTerminated
message to all monitoring actors. All messages waiting in actor mailbox or stash will be lost. -
Ignore
it's an equivalent of empty action.
Effects can be combined using @
operator. In such case they will be applied in order, they were defined.
Additionally effects can be heavily used by plugin libraries, such as Akkling.Persistence, which defines some additional effects:
-
Persist
,PersistAll
- those effects take an event or sequence of events and orders them to be stored inside event journal. -
PersistAsync
,PersistAllAsync
work similar to their synchronous cousins, however they can optimize event persisting mechanism by additional batching at cost of periodical actor's state inconsistency. -
Defer
will schedule another actor's loop hoop, once batch of asynchronously persisted messages will be stored.
Example:
let helloRef = spawn system "hello-actor" <| fun m ->
let rec loop () = actor {
let! msg = m.Receive ()
match msg with
| "stop" -> return Stop
| "unhandle" -> return Unhandled
| x ->
printfn "%s" x
return! loop ()
}
loop ()
- Introduction
- Bootstrapping actor system
- Creating an actor
- Static type safety
- Effects
- Managing actor's lifecycle
- Supervision strategies
- Event bus
- Logging
- Socket I/O
- Persistence
- Cluster sharding