Akka Routing: Wysyłanie odpowiedzi do routera kończy się jako martwe litery
gram z Actor Routing i nie mogę wysłać odpowiedzi z powrotem do routera, aby inny aktor z listy routingu mógł to odebrać, czego tu nie widzę;)
Używam:
sender.tell([Message], context.parent)
odpowiadać na router, zgodnie z dokumentami akka, rozgraniczeni aktorzy ustawiają nadawcę dla siebie, a jego rodzic jest rzeczywistym routerem
podczas odpowiadania wyświetli w konsoli następującą wiadomość:
[INFO] [12/13/2013 11: 19: 43.030] [StarBucks-akka.actor.default-dispatcher-2] [akka: // StarBucks / deadLetters] Wiadomość [net.addictivesoftware.starbucks.MakeCoffee $] od Actora [akka: // StarBucks / user / Melanie # -847662818] do Actora [akka: // StarBucks / deadLetters] nie został dostarczony. [1] napotkane martwe litery.
Główna klasa to:
object Starbucks extends App {
implicit val system = ActorSystem.create("StarBucks")
val employees = List(
system.actorOf(Props[Employee], "Penny"),
system.actorOf(Props[Employee], "Leonard"),
system.actorOf(Props[Employee], "Sheldon")
)
val customers = List(
("Raj", "Tall Latte Machiato"),
("Howard", "Double Tall Cappuccino"),
("Bernadette", "Grande Spicy Pumpkin Latte"),
("Amy", "Dopio Espresso")
)
val starBucks = system.actorOf(
Props.empty.withRouter(SmallestMailboxRouter(routees=employees)))
customers foreach { request =>
println("Customer %s orders a %s".format(request._1, request._2))
starBucks ! CanIHave(request._1, request._2)
}
}
Klasa routowanego aktora to:
class Employee extends Actor {
def receive = {
case CanIHave(coffee, name) => {
println("Employee %s writes '%s' and '%s' on a cup".format(self.path.name, coffee, name) )
sender.tell(MakeCoffee(coffee, name), context.parent)
}
case MakeCoffee(coffee, name) => {
println("Employee %s makes a %s for %s ".format(self.path.name, coffee, name) )
sender.tell(CoffeeReady(coffee, name), context.parent)
}
case CoffeeReady(coffee, name) => {
println("Employee %s shouts: %s for %s is ready!".format(self.path, name, coffee, name))
}
}
}