Akka Stream 中直播资源流程说明

Live resources in Akka Stream flow description

akka-stream docs中有这样一条注释,说明如下:

… a reusable flow description cannot be bound to “live” resources, any connection to or allocation of such resources must be deferred until materialization time. Examples of “live” resources are already existing TCP connections, a multicast Publisher, etc.; …

我有几个关于笔记的问题:

如果我们考虑 web 服务、RMI 连接或任何其他通信协议,这里的问题是一个常见问题。始终建议共享 "primitive" 值然后引用,因为 marshalling/unmarshalling 或 serializing/unserializing 总是令人头疼。还要考虑相互通信的不同类型的环境。分享坚实的价值观是解决沟通的安全方法。

Akka 本身就是 "microservices" 演员相互交流的一个很好的例子。当我阅读 Akka 的文档时,一个好词很好地定义了 Akka actors。 Actor 就像邮箱客户端,您可以认为每个客户端都有一个邮箱。当你传递一个变量时,就好像你收到了一封新邮件。

长话短说,避免共享 "dependent" 对象,这些对象在从其他演员那里读取之前可能会失效。此外,如果您的系统动态命名 actorRefs,请避免通过引用调用它们。

"Materializing" 在 akka-streams 的文档中有解释。

The process of materialization may be parameterized, e.g. instantiating a blueprint for handling a TCP connection’s data with specific information about the connection’s address and port information. Additionally, materialization will often create specific objects that are useful to interact with the processing engine once it is running, for example for shutting it down or for extracting metrics. This means that the materialization function takes a set of parameters from the outside and it produces a set of results. Compositionality demands that these two sets cannot interact, because that would establish a covert channel by which different pieces could communicate, leading to problems of initialization order and inscrutable runtime failures.

所以使用参数而不是传递 "connection" 本身。

推迟直播资源并不是什么大事。这意味着如果您为所有系统使用一个连接,您应该始终保持它处于活动状态。或者当您在 actor-1 中创建一个事务并将其发送给 actor-2 时,您不应该在 actor-2 完成其事务工作之前终止 actor-1 中的事务。

那你怎么理解呢?然后你使用 "Future" 和 "offer()"。

希望我理解你的问题,希望我能表达自己。