Akka 中的类型化和非类型化 Actor 有什么区别?什么时候用什么?

发布于 2024-12-15 11:27:16 字数 103 浏览 3 评论 0原文

我尝试阅读 Akka 文档来找出 Typed 和 Untyped Actor 之间的确切区别。什么时候用什么?我不确定我错过了什么。有人可以向我指出一些相关的内容或在这里提供这个问题的答案吗?

I have tried to read the Akka documentation to find out the exact difference between Typed and Untyped actors. When to use what? I am not sure what I'm missing. Can somebody point me to something relevant or provide an answer to this question here itself?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

甜柠檬 2024-12-22 11:27:16

UntypedActor 只是 Actor 的名称,但它是 Java API。

以下是一些文档链接:

Java:

Scala:

不同之处在于 TypedActors 有一个静态接口,并且对该接口上的方法的调用被转换为消息发送。 UntypedActors 可以接收任何消息。

希望有帮助。

干杯,

UntypedActor is simply the name for Actor but as the Java API.

Here are some links to documentation:

Java:

Scala:

The difference is that TypedActors have a static interface, and the invocations of the methods on that interface is transformed into message sends. UntypedActors can receive any message.

Hope that helps.

Cheers,

忘羡 2024-12-22 11:27:16
Actors (Untyped)

为了让参与者(Scala)接收消息,他们必须混合消费者特征。例如,以下 actor 类 (Consumer1) 实现了在 Consumer 特征中声明的 endpointUri 方法,以便从 file:data/input/actor Camel 端点接收消息。无类型参与者 (Java) 需要扩展抽象 UntypedConsumerActor 类并实现 getEndpointUri() 和 onReceive(Object) 方法。

Actors (Typed)

类型化参与者还可以从 Camel 端点接收消息。与仅实现单个 receive 或 onReceive 方法的(非类型化)actor 相比,类型化 actor 可以定义多个(消息处理)方法,每个方法都可以从不同的 Camel 端点接收消息。对于要作为 Camel 端点公开的类型化 Actor 方法,必须使用 @consume 注释对其进行注释。例如,以下类型化消费者参与者定义了两个方法:foo 和 bar。

参考

Actors (Untyped)

For actors (Scala) to receive messages, they must mixin the Consumer trait. For example, the following actor class (Consumer1) implements the endpointUri method, which is declared in the Consumer trait, in order to receive messages from the file:data/input/actor Camel endpoint. Untyped actors (Java) need to extend the abstract UntypedConsumerActor class and implement the getEndpointUri() and onReceive(Object) methods.

Actors (Typed)

Typed actors can also receive messages from Camel endpoints. In contrast to (untyped) actors, which only implement a single receive or onReceive method, a typed actor may define several (message processing) methods, each of which can receive messages from a different Camel endpoint. For a typed actor method to be exposed as Camel endpoint it must be annotated with the @consume annotation. For example, the following typed consumer actor defines two methods, foo and bar.

Reference

涫野音 2024-12-22 11:27:16

非类型化 Actor 响应发送的消息,而类型化 Actor 响应方法调用(参数值是消息)。

使用类型化参与者模型是为了为只能响应预定义消息集的参与者定义严格的契约。在这种情况下,每条消息不需要封装为一个对象;类型化的参与者允许我们定义单独的方法来接受合约定义的多个输入。用 Java 的话说,类型化参与者提供了面向对象世界中的 Java 接口。[1]

[1] Akka Essentials

Untyped actors respond to messages sent, while typed actors respond to method calls(the parameter values are the messages).

Typed Actor Model is used in order to define strict contracts for actors that can respond to only the predefined set of messages. In this case, every message need not be encapsulated as one object; typed actors allow us to define separate methods that accept multiple inputs as defined by the contract. In Java parlance, typed actors provide the Java interface in the object-oriented world.[1]

[1] Akka Essentials

恬淡成诗 2024-12-22 11:27:16

Akka 无类型演员“不组成”并且“没有有用的类型”。

这违背了我们使用 Scala 的初衷:它的函数式编程能力。
请参阅http://noelwelsh.com/programming /2013/03/04/why-i-dont-like-akka-actors/ 深入探讨这种心态。

另外,请参阅在 Scala 中改进此方法以匹配 Haskell 方式的尝试。

http://letitcrash.com/post/40198993865/makkros-first -迈向类型化渠道
http://letitcrash.com/post/45188487245/the-second -step-akka-typed-channels

似乎在 Akka 中仍处于实验阶段,甚至被放弃 - 不清楚。

这种类型化通道的想法很有意义,因为当人们尝试构建类型检查数据(分析)管道时,会发生类似的问题。

Akka Typed 似乎是向更安全的编程模型的巨大演变:https://opencredo.com/akka-typed/

Akka untyped actors "do not compose" and "are not usefully typed".

This defeats the very reason we use Scala: it's functional programming power.
See http://noelwelsh.com/programming/2013/03/04/why-i-dont-like-akka-actors/ for in depth on this mindset.

Also, see attempts to improve this in Scala to match the Haskell way.

http://letitcrash.com/post/40198993865/makkros-first-step-towards-typed-channels
http://letitcrash.com/post/45188487245/the-second-step-akka-typed-channels

Seems to still be experimental in Akka or even dropped - not clear.

This idea of typed channels makes a lot of sense because similar issues occur when one tries to build type checked data (analytics) pipelines.

Akka Typed seems to be a great evolution to a safer programming model: https://opencredo.com/akka-typed/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文