Skip to content
This repository has been archived by the owner on Mar 11, 2023. It is now read-only.

Not possible to get callback on stream completion #144

Open
nilsga opened this issue Oct 16, 2017 · 5 comments
Open

Not possible to get callback on stream completion #144

nilsga opened this issue Oct 16, 2017 · 5 comments

Comments

@nilsga
Copy link

nilsga commented Oct 16, 2017

In the event of an error that causes the stream to close, it does not seem to be a way to be notified about this, e.g. to shut the application down. The actual Future of the stream is "hidden" inside the Future[TwitterStream] that the streaming client exposes, so the only completion one is notified about is if the initial connect succeeds or fails. Neither does it seem to be any control messages to listen to in this case.

@nilsga
Copy link
Author

nilsga commented Oct 16, 2017

What I would like to do is something like:

val streamFuture = client.filterStatuses(tracks = trackTerms)(processTweet)
streamFuture.onComplete(_ => {
  println("Done")
  System.exit(0)
})

But this does not work, since the future that is returned is the connection future, and not the stream future.

@DanielaSfregola
Copy link
Owner

Hi @nilsga,
according to the specification of the Twitter Streaming API, once the streaming connection is open, it will never be closed unless requested from the consumer of the API: the stream is potentially infinite.

What you can do is closing or replacing an existing stream on demand: have a look at this section of the documentation that shows how to do that.

If this doesn't help you achieve what you are trying to do, please let us know!

Cheers,
D.

@nilsga
Copy link
Author

nilsga commented Oct 16, 2017

That's true, but there are cases where the stream can fail, not related to the twitter api. For instance if the connection times out from the akka stream end, or there are errors processing the tweet itself. In these cases, it would be nice to be able to just shut down, instead of running with a halted flow.

@DanielaSfregola
Copy link
Owner

DanielaSfregola commented Oct 16, 2017

Interesting: I didn't think of that! At present, you cannot do it.

What about having the opportunity of specifying an "ErrorHandler" to specify what the stream should behave depending on the exception thrown?

@nilsga
Copy link
Author

nilsga commented Oct 16, 2017

Maybe. The reason I added this in addition to #142 was that I had a very low volume stream, and akka streams reached an idle timeout. Not sure how these low level "protocol" exceptions would propagate to the client.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants