简体   繁体   English

Akka 中 Typed 和 UnTyped Actor 有什么区别? 什么时候用什么?

[英]What is the difference between Typed and UnTyped Actors in Akka? When to use what?

I have tried to read the Akka documentation to find out the exact difference between Typed and Untyped actors.我试图阅读 Akka 文档以找出 Typed 和 Untyped actor 之间的确切区别。 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?有人可以向我指出相关的内容或在这里提供这个问题的答案吗?

UntypedActor is simply the name for Actor but as the Java API. UntypedActor 只是 Actor 的名称,但作为 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.不同之处在于 TypedActors 有一个静态接口,该接口上方法的调用被转换为消息发送。 UntypedActors can receive any message. UntypedActors 可以接收任何消息。

Hope that helps.希望有帮助。

Cheers, √干杯,√

Actors (Untyped)

For actors (Scala) to receive messages, they must mixin the Consumer trait.为了让演员(Scala)接收消息,他们必须混合消费者特征。 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.例如,以下actor 类(Consumer1)实现了在Consumer trait 中声明的endpointUri 方法,以便从file:data/input/actor Camel 端点接收消息。 Untyped actors (Java) need to extend the abstract UntypedConsumerActor class and implement the getEndpointUri() and onReceive(Object) methods. Untyped actor (Java) 需要扩展抽象的 UntypedConsumerActor 类并实现 getEndpointUri() 和 onReceive(Object) 方法。

Actors (Typed)

Typed actors can also receive messages from Camel endpoints.类型化的 actor 也可以从 Camel 端点接收消息。 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.与仅实现单个接收或 onReceive 方法的(无类型)actor 相比,有类型的actor 可以定义多个(消息处理)方法,每个方法都可以从不同的 Camel 端点接收消息。 For a typed actor method to be exposed as Camel endpoint it must be annotated with the @consume annotation.对于要作为 Camel 端点公开的类型化 actor 方法,它必须使用 @consume 批注进行批注。 For example, the following typed consumer actor defines two methods, foo and bar.例如,以下类型化的消费者 actor 定义了两个方法,foo 和 bar。

Reference 参考

Untyped actors respond to messages sent, while typed actors respond to method calls(the parameter values are the messages).无类型actor 响应发送的消息,而有类型actor 响应方法调用(参数值是消息)。

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]在 Java 的说法中,类型化参与者在面向对象的世界中提供了 Java 接口。 [1]

[1] Akka Essentials [1] 阿卡精华

Akka untyped actors "do not compose" and "are not usefully typed". Akka 无类型演员“不创作”和“没有有用的类型”。

This defeats the very reason we use Scala: it's functional programming power.这违背了我们使用 Scala 的真正原因:它是函数式编程的力量。 See http://noelwelsh.com/programming/2013/03/04/why-i-dont-like-akka-actors/ for in depth on this mindset.请参阅http://noelwelsh.com/programming/2013/03/04/why-i-dont-like-akka-actors/以深入了解这种心态。

Also, see attempts to improve this in Scala to match the Haskell way.另外,请参阅尝试在 Scala 中对此进行改进以匹配 Haskell 方式。

http://letitcrash.com/post/40198993865/makkros-first-step-towards-typed-channels http://letitcrash.com/post/45188487245/the-second-step-akka-typed-channels 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.似乎在 Akka 中仍然处于实验阶段,甚至被放弃了 - 不清楚。

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/ Akka Typed 似乎是一个更安全的编程模型的伟大进化: https : //opencredo.com/akka-typed/

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

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