我正在运行一个涉及带有 cassandra 的 akka 演员的应用程序。这个应用程序将扫描推文放在一个标签上,将它们写入 cassandra 并从 cassandra 读取它们。三个动作(1)扫描推文(2)阅读推文(3)写推文。是运行时的用户选择。它们被合并到 Main
对象中,如下所示。
Main.scala
package core
import akka.actor.{Props, ActorSystem}
import scala.annotation.tailrec
import core.TweetReaderActor.{CountAll, FindAll}
object Main extends App with ConfigCassandraCluster {
import Commands._
import akka.actor.ActorDSL._
def twitterSearchProxy(query: String) = s"http://twitter-search-proxy.herokuapp.com/search/tweets?q=$query"
implicit lazy val system = ActorSystem()
val write = system.actorOf(Props(new TweetWriterActor(cluster)))
val read = system.actorOf(Props(new TweetReaderActor(cluster)))
val scan = system.actorOf(Props(new TweetScannerActor(write, twitterSearchProxy)))
// we don't want to bother with the ``ask`` pattern, so
// we set up sender that only prints out the responses to
// be implicitly available for ``tell`` to pick up.
implicit val _ = actor(new Act {
become {
case x => println(">>> " + x)
}
})
@tailrec
private def commandLoop(): Unit = {
Console.readLine() match {
case QuitCommand => return
case ScanCommand(query) => scan ! query.toString
case ListCommand(count) => read ! FindAll(count.toInt)
case CountCommand => read ! CountAll
case _ => return
}
commandLoop()
}
// start processing the commands
commandLoop()
// when done, stop the ActorSystem
system.shutdown()
}
/**
* Various regexes for the ``Shell`` to use
*/
object Commands {
val ListCommand = "list (\\d+)".r
val CountCommand = "count"
val QuitCommand = "quit"
val ScanCommand = "scan (.*)".r
}
但是当我scan(hashtag)
作为命令行 argumnet 运行应用程序时,程序保持空闲状态。
C:\Akka Actors\activator-akka-cassandra-master>sbt run scan(spyder)
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
[warn] Executing in batch mode.
[warn] For better performance, hit [ENTER] to switch to interactive mode, or
[warn] consider launching sbt without any commands, or explicitly passing 'shell'
[info] Loading project definition from C:\Akka Actors\activator-akka-cassandra-master\project
[info] Set current project to activator-akka-cassandra (in build file:/C:/Akka%20Actors/activator-akka-cassandra-master/)
[info] Running core.Main
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
没有行动。没有错误。
下面是tweetscan.scala的一部分,它是一个演员,它"query"
通过对象传递字符串Main
并执行封送处理。
class TweetScannerActor(tweetWrite: ActorRef, queryUrl: String => String) extends Actor with TweetMarshaller {
import context.dispatcher
import akka.pattern.pipe
private val pipeline = sendReceive ~> unmarshal[Tweets]
def receive: Receive = {
case query: String => pipeline(Get(queryUrl(query))) pipeTo tweetWrite
}
}
我在给出命令行参数时遵循的过程中是否有任何问题sbt run
!任何建议都是可观的,哪里出错了。如果需要,我可以提供更多细节。提前致谢。