akka

How to get an actor reference (ActorRef) from ActorFlow?

旧城冷巷雨未停 提交于 2021-02-08 02:18:28
问题 According to the Play documentation on WebSockets the standard way to establish a WebSocket is to use ActorFlow.actorRef , which takes a function returning the Props of my actor. My goal is to get a reference to this underlying ActorRef , for instance in order to send a first message or to pass the ActorRef to another actor's constructor. In terms of the minimal example from the documentation, I'm trying to achieve this: class WebSocketController @Inject() (implicit system: ActorSystem,

How to get object that caused failure in Akka Streams?

回眸只為那壹抹淺笑 提交于 2021-02-08 02:12:39
问题 According to akka streams docs one can handle stream failure by defining a decider that maps a Throwable to a Strategy : val decider: Supervision.Decider = { case _: ArithmeticException => Supervision.Resume case _ => Supervision.Stop } I wonder if there is a way to also get access to the element that caused the error. Of course, the type of this element is unknown, but is there a way to get it even as an instance of Object ? 回答1: The trivial way would be to catch the ArithmeticException near

How to get object that caused failure in Akka Streams?

可紊 提交于 2021-02-08 02:12:22
问题 According to akka streams docs one can handle stream failure by defining a decider that maps a Throwable to a Strategy : val decider: Supervision.Decider = { case _: ArithmeticException => Supervision.Resume case _ => Supervision.Stop } I wonder if there is a way to also get access to the element that caused the error. Of course, the type of this element is unknown, but is there a way to get it even as an instance of Object ? 回答1: The trivial way would be to catch the ArithmeticException near

Akka Stream connect to multiple sinks

微笑、不失礼 提交于 2021-02-07 18:29:13
问题 I have implemented a custom component in akka stream which takes elements as input, groups and merges them based on a key and sends them out through one of a dozen outlets. You can think of this component as a kind of GroupBy component which does not partition the flow into subflows, but actual flows. In addition to partitioning incoming elements, it merges them into one element, i.e. there is some buffering happening inside the component such that 1 element in does not necessarily mean 1

Update actor state only after all events are persisted

﹥>﹥吖頭↗ 提交于 2021-02-07 08:55:43
问题 In the receive method of a persistent actor, I receive a bunch a events I want to persist, and only after all events are persisted, update again my state. How can I do that? def receive: Receive = { ... case NewEvents(events) => persist(events) { singleEvent => // Update state using this single event } // After every events are persisted, do one more thing } Note that the persist() call is not blocking so I cannot put my code just after that. Update: Why I need this These new events come from

Update actor state only after all events are persisted

爷,独闯天下 提交于 2021-02-07 08:53:46
问题 In the receive method of a persistent actor, I receive a bunch a events I want to persist, and only after all events are persisted, update again my state. How can I do that? def receive: Receive = { ... case NewEvents(events) => persist(events) { singleEvent => // Update state using this single event } // After every events are persisted, do one more thing } Note that the persist() call is not blocking so I cannot put my code just after that. Update: Why I need this These new events come from

Update actor state only after all events are persisted

我们两清 提交于 2021-02-07 08:53:42
问题 In the receive method of a persistent actor, I receive a bunch a events I want to persist, and only after all events are persisted, update again my state. How can I do that? def receive: Receive = { ... case NewEvents(events) => persist(events) { singleEvent => // Update state using this single event } // After every events are persisted, do one more thing } Note that the persist() call is not blocking so I cannot put my code just after that. Update: Why I need this These new events come from

Akka context become recursive function

家住魔仙堡 提交于 2021-02-07 07:28:31
问题 I have an actor in which I mutate the state using context.become: Here is the snippet: def stateMachine(state: State): Receive = { case a => { ... do something context.become(stateMachine(newState)) } case b => { ... do something sender ! state } case c => { ... do something context.become(stateMachine(newState)) } } My IntelliJ says that my stateMachine(...) function is recursive. Is this a problem? Should I be concerned? Is there something fundamentally wrong with my approach in the above

Using future callback inside akka actor

匆匆过客 提交于 2021-02-06 15:31:58
问题 I've found in Akka docs: When using future callbacks, such as onComplete, onSuccess, and onFailure, inside actors you need to carefully avoid closing over the containing actor’s reference, i.e. do not call methods or access mutable state on the enclosing actor from within the callback. So does it mean that i should always use future pipeTo self and then call some functions? Or i can still use callbacks with method, then how should i avoid concurrency bugs? 回答1: It means this: class

Using future callback inside akka actor

試著忘記壹切 提交于 2021-02-06 15:27:25
问题 I've found in Akka docs: When using future callbacks, such as onComplete, onSuccess, and onFailure, inside actors you need to carefully avoid closing over the containing actor’s reference, i.e. do not call methods or access mutable state on the enclosing actor from within the callback. So does it mean that i should always use future pipeTo self and then call some functions? Or i can still use callbacks with method, then how should i avoid concurrency bugs? 回答1: It means this: class