Actor library
libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.5.14"
Akka的核心lib就是akka-actor,actor在akka相关的lib中都有被使用到,他也为我们解决了分布式以及并发程序开发中所遇到的各种问题。从大体来看,acotor为我们将OOP中国封装的概念做到了极致。不同于对象,acotr不仅封装了状态还封装了执行过程。在使用actor的时候我们通过消息而不是方法调用来进行通讯, 虽然这看上去有点微不足道,但是却真正解决了OOP在并发和远程通讯方面的限制。综上所述,我们要铭记于心的便是,Akka从底层提供了解决并发和分布式程序的解决方案。
actor具体能解决的问题有以下:
- How to build and design high-performance, concurrent applications.
- How to handle errors in a multi-threaded environment.
- How to protect my project from the pitfalls of concurrency.
Remoting
libraryDependencies += "com.typesafe.akka" %% "akka-remote" % "2.5.14"
Remoting模块可以让不同机器上的actor无缝的进行消息交换。我们可以通过配置来开启remoting模块,他提供了一些相关的API。感谢actor模型让我们可以像发送本地消息一样去发送远程消息。一般情况下用户不需要直接使用remoting,但是他为cluster 提供了坚实基础。
Remoting解决了以下问题:
- How to address actor systems living on remote hosts.
- How to address individual actors on remote actor systems.
- How to turn messages to bytes on the wire.
- How to manage low-level, network connections (and reconnections) between hosts, detect crashed actor systems and hosts, all transparently.
- How to multiplex communications from an unrelated set of actors on the same network connection, all transparently.
Cluster
libraryDependencies += "com.typesafe.akka" %% "akka-cluster" % "2.5.14"
基于Remoting,来build一个cluster,cluster的特性无需赘言
Challenges the Cluster module solves include the following:
- How to maintain a set of actor systems (a cluster) that can communicate with each other and consider each other as part of the cluster.
- How to introduce a new system safely to the set of already existing members.
- How to reliably detect systems that are temporarily unreachable.
- How to remove failed hosts/systems (or scale down the system) so that all remaining members agree on the remaining subset of the cluster.
- How to distribute computations among the current set of members.
- How to designate members of the cluster to a certain role, in other words, to provide certain services and not others.
Cluster Sharding
libraryDependencies += "com.typesafe.akka" %% "akka-cluster-sharding" % "2.5.14"
Sharding帮我们解决了如何从一个cluster中分散actor子集的问题。sharding经常和persistence一起使用,来将一个很大的persistent集合进行均衡,并且在出现问题时候将他们移动到一些其他的节点上
Sharding解决了以下问题:
- How to model and scale out a large set of stateful entities on a set of systems.
- How to ensure that entities in the cluster are distributed properly so that load is properly balanced across the machines.
- How to ensure migrating entities from a crashed system without losing the state.
- How to ensure that an entity does not exist on multiple systems at the same time and hence keeps consistent.
Cluster Singleton
libraryDependencies += "com.typesafe.akka" %% "akka-cluster-singleton" % "2.5.14"
在分布式系统中有一种很常见的场景就是我们需要一个节点来进行任务管理,剩余的其他节点进行具体的任务处理。虽然这种模式会存在单点障碍问题,但是有的时候不得不使用这种场景。Cluster singleton就为我们实现了这种场景下的集群。
Singleton可以解决如下问题:
- How to ensure that only one instance of a service is running in the whole cluster.
- How to ensure that the service is up even if the system hosting it currently crashes or shuts down during the process of scaling down.
- How to reach this instance from any member of the cluster assuming that it can migrate to other systems over time.
Cluster Publish-Subscribe
libraryDependencies += "com.typesafe.akka" %% "akka-cluster-tools" % "2.5.14"
消息订阅模式,无需赘言
Cluster Publish-Subscribe 解决如下问题:
- How to broadcast messages to an interested set of parties in a cluster.
- How to send a message to a member from an interested set of parties in a cluster.
- How to subscribe and unsubscribe for events of a certain topic in the cluster.
Persistence
libraryDependencies += "com.typesafe.akka" %% "akka-persistence" % "2.5.14"
Persistence可以帮助我们实现持久化的功能,无需赘言
Persistence 解决了以下问题:
- How to restore the state of an entity/actor when system restarts or crashes.
- How to implement a CQRS system.
- How to ensure reliable delivery of messages in face of network errors and system crashes.
- How to introspect domain events that have led an entity to its current state.
- How to leverage Event Sourcing in your application to support long-running processes while the project continues to evolve.
Distributed Data
libraryDependencies += "com.typesafe.akka" %% "akka-distributed-data" % "2.5.14"
如果系统可以接受最终一致性,那么可以使用该特性将数据先写到多个节点再最终合并,该模块为多种使用的数据类型提供了此功能
Distributed Data 解决了如下的挑战:
- How to accept writes even in the face of cluster partitions.
- How to share data while at the same time ensuring low-latency local read and write access.
Streams
libraryDependencies += "com.typesafe.akka" %% "akka-stream" % "2.5.14"
Streams提供了对数据流的处理能力
Streams 所解决的挑战:
- How to handle streams of events or large datasets with high performance, exploiting concurrency and keep resource usage tight.
- How to assemble reusable pieces of event/data processing into flexible pipelines.
- How to connect asynchronous services in a flexible way to each other, and have good performance.
- How to provide or consume Reactive Streams compliant interfaces to interface with a third party library.
HTTP
用于创建和调用http api,特别是在streaming的使用中
HTTP解决的问题:
- How to expose services of a system or cluster to the external world via an HTTP API in a performant way.
- How to stream large datasets in and out of a system using HTTP.
- How to stream live events in and out of a system using HTTP.