简体   繁体   English

Java Akka 演员和流

[英]Java Akka Actor and Streams

I started learning akka from https://doc.akka.io/docs/akka/current/index.html我从https://doc.akka.io/docs/akka/current/index.html 开始学习 akka

I have ActorSystem with child actors and all child actors created in the hierarchy with parent actor.我有带有子演员的 ActorSystem 以及在父演员的层次结构中创建的所有子演员。 For an example: DeviceManager is my parent actor and device is child actor.例如:DeviceManager 是我的父 actor,device 是子 actor。

I would like to understand where akka stream flow kick off in actor lifecycle.我想了解 akka stream 流程在演员生命周期中的起点。 When we create parent actor or when stream process will start?当我们创建父 actor 或者 stream 进程什么时候开始?

How Akka stream is correlated with Actor lifecycle? Akka stream 与Actor生命周期有什么关联?

How Akka stream is correlated with Actor lifecycle? Akka stream 与Actor生命周期有什么关联?

Akka Streams and the Typed Actor API are essentially two separate APIs that can interoperate and share some implementation details. Akka Streams 和 Typed Actor API 本质上是两个独立的 API,它们可以互操作并共享一些实现细节。 The lifecycle of any actors you create with the Actor API are completely independent of any streams you are running.您使用 Actor API 创建的任何 actor 的生命周期完全独立于您正在运行的任何流。 (And vice versa.) (反之亦然。)

I would like to understand where akka stream flow kick off in actor lifecycle, when we create parent actor when stream process will start?我想了解 akka stream 流程在 actor 生命周期中从哪里开始,当我们创建父 actor 时 stream 进程将启动?

As mentioned above, streams are independent.如上所述,流是独立的。 A stream (represented as a RunnableGraph ) is going to "kick off" when you run it. stream(表示为RunnableGraph )将在您run时“启动”。 (Not that there are several convenience methods to do the same thing such as Source.runWith , Source.runForeach , and many more. Any streams method with "run" is likely to "kick off" a stream.) This "kicking off" is called materialization, wherein your graph (composed of sources, flows, and sinks), which is just a blueprint for a stream, is brought into being. (并不是说有几种方便的方法可以做同样的事情,例如Source.runWithSource.runForeach等等。任何带有“run”的流方法都可能“启动”stream。)这个“启动”被称为物化,其中你的图(由源、流和汇组成),它只是 stream 的蓝图,被生成。

A good place to start learning is the streams quickstart .开始学习的好地方是streams quickstart

I have ActorSystem with child actors and all child actors created in the hierarchy with parent actor.我有带有子演员的 ActorSystem 以及在父演员的层次结构中创建的所有子演员。 DeviceManager is my parent actor and device is child actor. DeviceManager 是我的父 actor,device 是子 actor。

If you want to have the two interoperate, take a look at theActor Interop section of the Akka Streams documentation.如果您想让两者互操作,请查看 Akka Streams 文档的Actor Interop部分。 But as an example, if you have a stream of IoT data that you are processing in an Akka Stream, and at the end of the stream you want to send the elements of that stream to your DeviceManager actor, you could do that with an ActorSink.actorRefWithBackpressure .但作为一个例子,如果你有一个 stream 的物联网数据,你正在 Akka Stream 中处理,并且在 stream 的末尾你想将 stream 的元素发送到你的 DeviceManager actor,你可以使用ActorSink.actorRefWithBackpressure You just use that Sink at the end of your stream and then your actor will receive normal actor messages.您只需在 stream 的末尾使用该 Sink,然后您的 actor 就会收到正常的 actor 消息。 (If you don't need the backpressure, you can just use ActorSink.actorRef , but if you are using Streams you should use backpressure.) (如果您不需要背压,您可以只使用ActorSink.actorRef ,但如果您使用的是 Streams,则应该使用背压。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM