I have been playing with the distributed worker pattern and I'm running into an issue pushing work from a web request.
The example project has a frontend:
val mediator = DistributedPubSubExtension(context.system).mediator
def receive = {
case work =>
log.info("Frontend received: " + work.toString())
implicit val timeout = Timeout(5.seconds)
(mediator ? Send("/user/master/active", work, localAffinity = false)) map {
case Master.Ack(_) => Ok
} recover { case _ => NotOk } pipeTo sender
}
And a WorkProducer:
override def preStart(): Unit =
scheduler.scheduleOnce(5.seconds, self, Tick)
def receive = {
case Tick =>
n += 1
log.info("Produced work: {}", n)
val work = Work(nextWorkId(), n)
frontend ! work
context.become(waitAccepted(work), discardOld = false)
}
This all works just fine, when I send directly to the frontend from my Play Framework controller:
def multiply(num: Long) = Action {
implicit request =>
implicit val timeout = Timeout(5.seconds)
val frontend = core.Main.frontend
frontend ! num
Ok
}
The message seems to get lost. The frontend receives the message but it seems the actors down stream do not.
I have modified the play config to use a ClusterActorRefProvider
play {
akka {
extensions = ["akka.contrib.pattern.ClusterReceptionistExtension"]
actor.provider = "akka.cluster.ClusterActorRefProvider"
remote.netty.tcp.port=0
}
}
But to no avail.