【发布时间】:2020-02-15 06:50:29
【问题描述】:
我正在使用twitter4s 和play-framework-2.4.3
我正在获取发送给参与者的推文以对其执行一些处理,并且参与者需要将响应发送回控制器动作 这是我的代码
def totalTweetCount = Action.async {
log.debug("in the action tofaltweets")
def getTweet: PartialFunction[StreamingMessage, Unit] = {
case tweet: Tweet =>
future = ask(myActor, TotalNumberOfTweets(tweet)).mapTo[Int]
}
val streaming: Future[TwitterStream] = streamingClient.sampleStatuses(stall_warnings = true)(getTweet)
}
class MyActor extends Actor {
//sends back the response to the calling code
}
现在问题是下面的行连续运行(它的推特流)并连续调用 getTweet 方法并将推文对象发送给演员
val streaming: Future[TwitterStream] = streamingClient.sampleStatuses(stall_warnings = true)(getTweet)
我想获取参与者响应并将其显示在我的操作的 Ok 块中
当我做这样的事情时,我得到了NullPointerException
def totalTweetCount = Action.async {
log.debug("in the action tofaltweets")
def getTweet: PartialFunction[StreamingMessage, Unit] = {
case tweet: Tweet =>
var future: Future[Int] = null
future = ask(myActor, TotalNumberOfTweets(tweet)).mapTo[Int]
}
val streaming: Future[TwitterStream] = streamingClient.sampleStatuses(stall_warnings = true)(getTweet)
future.map {
result =>
Ok("Total number of tweets" + result)
}
}
如果我这样做 def totalTweetCount = Action.async { log.debug("in the action tofaltweets")
def getTweet: PartialFunction[StreamingMessage, Unit] = {
case tweet: Tweet =>
var future: Future[Int] = null
future = ask(actorManager, TotalNumberOfTweets(tweet)).mapTo[Int]
future.map {
result =>
Ok("Total number of tweets" + result)
}
}
val streaming: Future[TwitterStream] = streamingClient.sampleStatuses(stall_warnings = true)(getTweet)
} 它也错了 那么正确的方法应该是什么
【问题讨论】:
标签: scala playframework twitter4j playframework-2.4 twitter4s