際際滷

際際滷Share a Scribd company logo
Messaging Patterns with
Akka (Remote) Actors
John Nestor and Dragos Manolescu
Whitepages, Inc.
April 14, 2015
Prelude
 JLine (http://jline.sourceforge.net)
 Command history, tab completion, line editing
 Custom key bindings
 PersistJson (https://github.com/nestorpersist/json)
 Fast Scala JSON parser
 JSON tree/Scala classes
 Pretty/Compact
 Demo code at https://github.com/polymorphic/akka-messaging-
patterns.git
Akka Remote Actors
 Design decisions:
 Symmetric communication
 Symmetric roles
 Remote scenarios:
 Lookup
 Remote creation
Akka Actor Model
Actor
BehaviorMailbox
Parent
Child
Child
M M M
Actor
BehaviorMailbox
Messages
- Con鍖guration
- Thread pools
Actor System
Akka Actor Model w/
Remoting
Actor
BehaviorMailbox
Parent
Child
Child
M M MActor
BehaviorMailbox
Messages
- Con鍖guration
- Thread pools
Actor System
Lookup via ActorSelection
Remote creation via deployment con鍖guration
- Con鍖guration
- Thread pools
Actor System
Actor System Con鍖guration
for Remoting
akka {
actor {
provider = "akka.remote.RemoteActorRefProvider"
}
remote {
enabled-transports = ["akka.remote.netty.tcp"]
netty.tcp {
hostname = "127.0.0.1"
port = 2552
}
}
}
Messaging Pattern:
OneWay
Client Actor
Server Actor
JSON(cmd, id, msg)
(server work)
Messaging Pattern:
Request-Reply
Client Actor
Server Actor
JSON(cmd, id, msg)
(server work)
JSON("done", id, msg)
Messaging Pattern:
Request-Reply with Failure
Client Actor
Server Actor
JSON(cmd, id, msg)
(server work)
JSON("fail", id, msg)
Messaging Pattern:
Request-Reply with Ack
Client Actor
Server Actor
(server work)
JSON("done", id, msg)
JSON(cmd, id, msg)
JSON("ack", id, msg)
Timer
Messaging Pattern:
Request-Reply with Progress
Client Actor
Server Actor
(server work)
JSON("done", id, msg)
JSON(cmd, id, msg)
(server work)
(server work)
(server work)
JSON("progress", id, msg)
JSON("progress", id, msg)
JSON("progress", id, msg)
Messaging Pattern:
Request-Reply with Query
Client Actor
Server Actor
(server work)
JSON(cmd, id, msg)
(user input)
(server work)
JSON("query", id, msg)
JSON
(server work)
JSON("done", id, msg)
Repeat 2x
Messaging Pattern:
Long Polling
Client Actor
Server Actor
(server work)
JSON("StopListen", id, msg)
JSON
JSON("StartListen", id, msg)
Messaging Patterns
 More patterns:
 Sender retries on timeout or failure
 A -> B, B -> C, C responds to A directly
 Routers
 Suggestions for more patterns welcome!
Summary:
Remote Actors or HTTP?
 Remote actors:
 Symmetric; uniform for local/remote
 Rich interaction patterns, very simple protocol
 Problems with NAT and load balancers
 HTTP:
 Asymmetric; remote-only
 Simple interaction patterns, complex protocol
 Ubiquitous
 Originally designed for a very different purpose
For More Information
 Sample code: https://github.com/polymorphic/akka-
messaging-patterns.git
 Akka remoting: http://doc.akka.io/docs/akka/2.3.9/
scala/remoting.html
 JLine http://jline.sourceforge.net
 PersistJson https://github.com/nestorpersist/json
 Effective Akka, Patterns and Best Practices by Jamie
Allen
Thank you

More Related Content

Messaging patterns

  • 1. Messaging Patterns with Akka (Remote) Actors John Nestor and Dragos Manolescu Whitepages, Inc. April 14, 2015
  • 2. Prelude JLine (http://jline.sourceforge.net) Command history, tab completion, line editing Custom key bindings PersistJson (https://github.com/nestorpersist/json) Fast Scala JSON parser JSON tree/Scala classes Pretty/Compact Demo code at https://github.com/polymorphic/akka-messaging- patterns.git
  • 3. Akka Remote Actors Design decisions: Symmetric communication Symmetric roles Remote scenarios: Lookup Remote creation
  • 4. Akka Actor Model Actor BehaviorMailbox Parent Child Child M M M Actor BehaviorMailbox Messages - Con鍖guration - Thread pools Actor System
  • 5. Akka Actor Model w/ Remoting Actor BehaviorMailbox Parent Child Child M M MActor BehaviorMailbox Messages - Con鍖guration - Thread pools Actor System Lookup via ActorSelection Remote creation via deployment con鍖guration - Con鍖guration - Thread pools Actor System
  • 6. Actor System Con鍖guration for Remoting akka { actor { provider = "akka.remote.RemoteActorRefProvider" } remote { enabled-transports = ["akka.remote.netty.tcp"] netty.tcp { hostname = "127.0.0.1" port = 2552 } } }
  • 7. Messaging Pattern: OneWay Client Actor Server Actor JSON(cmd, id, msg) (server work)
  • 8. Messaging Pattern: Request-Reply Client Actor Server Actor JSON(cmd, id, msg) (server work) JSON("done", id, msg)
  • 9. Messaging Pattern: Request-Reply with Failure Client Actor Server Actor JSON(cmd, id, msg) (server work) JSON("fail", id, msg)
  • 10. Messaging Pattern: Request-Reply with Ack Client Actor Server Actor (server work) JSON("done", id, msg) JSON(cmd, id, msg) JSON("ack", id, msg) Timer
  • 11. Messaging Pattern: Request-Reply with Progress Client Actor Server Actor (server work) JSON("done", id, msg) JSON(cmd, id, msg) (server work) (server work) (server work) JSON("progress", id, msg) JSON("progress", id, msg) JSON("progress", id, msg)
  • 12. Messaging Pattern: Request-Reply with Query Client Actor Server Actor (server work) JSON(cmd, id, msg) (user input) (server work) JSON("query", id, msg) JSON (server work) JSON("done", id, msg) Repeat 2x
  • 13. Messaging Pattern: Long Polling Client Actor Server Actor (server work) JSON("StopListen", id, msg) JSON JSON("StartListen", id, msg)
  • 14. Messaging Patterns More patterns: Sender retries on timeout or failure A -> B, B -> C, C responds to A directly Routers Suggestions for more patterns welcome!
  • 15. Summary: Remote Actors or HTTP? Remote actors: Symmetric; uniform for local/remote Rich interaction patterns, very simple protocol Problems with NAT and load balancers HTTP: Asymmetric; remote-only Simple interaction patterns, complex protocol Ubiquitous Originally designed for a very different purpose
  • 16. For More Information Sample code: https://github.com/polymorphic/akka- messaging-patterns.git Akka remoting: http://doc.akka.io/docs/akka/2.3.9/ scala/remoting.html JLine http://jline.sourceforge.net PersistJson https://github.com/nestorpersist/json Effective Akka, Patterns and Best Practices by Jamie Allen