I'm experimenting with Akka streams and twitter4j-stream. Having a stream of tweets it works fine until the moment when it fails with NPE
, which doesn't make sense to me.
Initially i'm creating a client
:
val client: TwitterStream = {
using(TwitterClient.clientFactory.getInstance()) { inst =>
inst.setOAuthConsumer(auth.consumerKey, auth.consumerSecret)
inst.setOAuthAccessToken(new AccessToken(auth.accessTokenKey, auth.accessTokenSecret))
}
}
In the end i want to get something with the following signature: val stream: Source[TwitterEvent, ShutdownHandler]
so i'm creating a ReactiveStreams Publisher
which would feed the Source
using the that comes out of the client:
val pub = new Publisher[TwitterEvent] {
override def subscribe(s: Subscriber[_ >: TwitterEvent]): Unit = {
client.addListener(new TwitterListener(s))
client.filter(filter)
}
}
val stream: Source[TwitterEvent, ShutdownHandler] = {
Source.fromPublisher(pub).mapMaterializedValue { nu =>
new TwitterClient.ShutdownHandler(() => client.shutdown())
}
}
So the .filter()
bootstrap this thing and i'm receiving some amout of tweets and then it fails with this:
[ERROR] [04/08/2016 15:18:19.301] [System-akka.actor.default-dispatcher-4] [akka://System/user/StreamSupervisor-0/flow-0-0-foreachSink-foreachSink-map] It is illegal to throw exceptions from request(), rule 3.16
akka.stream.impl.ReactiveStreamsCompliance$SignalThrewException: It is illegal to throw exceptions from request(), rule 3.16
at akka.stream.impl.ReactiveStreamsCompliance$.tryRequest(ReactiveStreamsCompliance.scala:111)
...
Caused by: java.lang.NullPointerException
at akka.stream.impl.ReactiveStreamsCompliance$.tryRequest(ReactiveStreamsCompliance.scala:110)
In case it's important my TwitterListener
:
final class TwitterListener(s: Subscriber[_ >: TwitterEvent]) extends StatusAdapter {
override def onStatus(status: Status): Unit = {
if (status != null) {
val message = new TwitterEvent(status)
s.onNext(message)
}
}
override def onException(ex: Exception): Unit = {
s.onError(ex)
}
}