This document discusses using Akka actors and Redis for building a scalable chat server architecture. Key points include:
1) Using Akka actors for the chat room, user, and supervisor actors to handle chat logic and failures in a distributed, asynchronous manner.
2) Storing chat room membership and messages in Redis for real-time updates between actors using pub/sub.
3) The Lettuce client is used to handle connections to the Redis cluster for features like master/slave failover and periodic topology refreshes.
26. Supervisor Strategy -
● One-for-One strategy
● crash actor
● All-for-One strategy
● actor
● actor actor
actor
27. Supervisor Strategy - Directives
● Restart - actor
mailbox
● Crash actor actor restart
●
● preRestart hook
→
● Resume - mailbox
●
28. Supervisor Strategy - Directives
● Stop - actor
●
● actor
● Escalate - Supervisor Actor
● Supervisor Strategy
Child Actor → Parent Actor → Grandparent Actor
41. ●
● Restart
1 public static Props props(final AggregatedChannel channel,
2 final ChatRoom chatRoom,
3 final ChatRoomMembers chatRoomMembers) {
4 // Returns a property to construct ChatRoomActor
5 // NOTE: Those objects passed to actor's constructor are inherited on restart
6 // such as ChatRoomMembers that caches belonging UserActors
7 return Props.create(ChatRoomActor.class,
8 () -> new ChatRoomActor(channel,
9 chatRoom,
10 chatRoomMembers));
11 }
56. Lettuce
1 /*
2 To get rid of stale connection and establish new connection when crush/failover occurs,
3 refresh its topologyView periodically.
4 */
5 ClusterTopologyRefreshOptions topologyRefreshOptions =
6 ClusterTopologyRefreshOptions.builder()
7 .enablePeriodicRefresh(30, TimeUnit.SECONDS)
8 .enableAllAdaptiveRefreshTriggers()
9 .build();
10 /*
11 Basically we use the default settings, but to avoid connection error caused by newly added
server,
12 override the validateClusterNodeMembership and skip validation for new server.
13 */
14 ClusterClientOptions clusterClientOptions =
15 ClusterClientOptions.builder()
16 .validateClusterNodeMembership(false)
17 .topologyRefreshOptions(topologyRefreshOptions)
18 .build();
57. ● WebSocket
● Server - Client
● akka Actor Model
●
● Actor Actor
● Blocking API
● Redis Cluster
●
●
58. ● LINE LIVE
●
● https://engineering.linecorp.com/ja/blog/detail/85
● Yet another Akka introduction for dummies
●
● http://blog.oklahome.net/2016/01/akka-introduction-for-dummies.html
● How to cook lettuce @Java casual
● Lettuce
● https://www.slideshare.net/Oklahomer/how-to-cook-lettuce-java-
casual