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

后端 未结 4 2022
我在风中等你
我在风中等你 2021-02-03 22:53

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 po

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-03 23:18

    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

提交回复
热议问题