Scala 阿克卡休息投票
我正在尝试将一个大型Scala+Akka+PlayMini应用程序与一个外部restapi接口。其思想是定期轮询(基本上每1到10分钟一次)根URL,然后在子级别URL中爬行以提取数据,然后将数据发送到消息队列 我想出了两种方法: 第一路 创建参与者层次结构以匹配API的资源路径结构。在Google Latitude的案例中,这意味着Scala 阿克卡休息投票,scala,rest,akka,polling,play2-mini,Scala,Rest,Akka,Polling,Play2 Mini,我正在尝试将一个大型Scala+Akka+PlayMini应用程序与一个外部restapi接口。其思想是定期轮询(基本上每1到10分钟一次)根URL,然后在子级别URL中爬行以提取数据,然后将数据发送到消息队列 我想出了两种方法: 第一路 创建参与者层次结构以匹配API的资源路径结构。在Google Latitude的案例中,这意味着 参与者“纬度/v1/currentLocation”轮询 参与者“纬度/v1/位置”轮询 参与者“纬度/v1/location/1”轮询 参与者“纬度/v1/l
- 参与者“纬度/v1/currentLocation”轮询
- 参与者“纬度/v1/位置”轮询
- 参与者“纬度/v1/location/1”轮询
- 参与者“纬度/v1/location/2”轮询
- 演员“纬度/v1/location/3”投票
- 等等
谢谢 为什么不创建一个主轮询器,然后将异步资源请求踢到时间表上 我不是使用Akka的专家,但我尝试过: 遍历要获取的资源列表的轮询器对象:
import akka.util.duration._
import akka.actor._
import play.api.Play.current
import play.api.libs.concurrent.Akka
object Poller {
val poller = Akka.system.actorOf(Props(new Actor {
def receive = {
case x: String => Akka.system.actorOf(Props[ActingSpider], name=x.filter(_.isLetterOrDigit)) ! x
}
}))
def start(l: List[String]): List[Cancellable] =
l.map(Akka.system.scheduler.schedule(3 seconds, 3 seconds, poller, _))
def stop(c: Cancellable) {c.cancel()}
}
异步读取资源并触发更多异步读取的参与者。您可以将消息调度安排在一个时间表上,而不是立即呼叫(如果它更友好):
import akka.actor.{Props, Actor}
import java.io.File
class ActingSpider extends Actor {
import context._
def receive = {
case name: String => {
println("reading " + name)
new File(name) match {
case f if f.exists() => spider(f)
case _ => println("File not found")
}
context.stop(self)
}
}
def spider(file: File) {
io.Source.fromFile(file).getLines().foreach(l => {
val k = actorOf(Props[ActingSpider], name=l.filter(_.isLetterOrDigit))
k ! l
})
}
}
我会更担心错误路径。如果特定中间路径出现瞬时故障,会发生什么情况;是否重试?任何给定子参与者的失败是否也会导致父参与者的失败?在足够大的范围内,你几乎肯定会有孩子们的短暂失败。