-
Notifications
You must be signed in to change notification settings - Fork 99
Streaming API modification proposal #242
Comments
Hi @Humblehound! Thank you for the nice words! Yes I totally agree with you: the Streaming API is far from perfect and we need to dedicate some proper love to it (I have other tickets related to this, I will try to link them here later on). I'll try to think of this and come back to you by tomorrow so that we can finalize an API. Ideally we need to come up with an API that looks simple but it is flexible enough to make it configurable. Maybe trying to have some snippets of code on how this could look could help in making a decision? Let's brainstorm! :D |
I'd be happy to! So I've tried implementing the first approach, I don't really like it since a tuple of two futures is not a monad so you can't map over it... I think it would be best to see how this could be implemented and work up towards what the API could look like. To start - I think this fragment is crucial:
As you can see I've modified it slightly already. I've used akka-streams a couple of times, but to date I still think it's the most complex library I've used. The most needed part is extracting the failure information from the stream. Here I've used the existing flag as a placeholder for event parsing information. The complete flow could look like this:
The main problem for me seems to be exposing the killswitch to the user alongside processing result. I'm wondering if we could lift the killswitch up in the hierarchy - there is no need to have it as low. We definitely need to make sure that one killswitch is always bound to one stream. We could modify the control flow - return to the user an object that contains the killswitch without the spawned stream. Then this object could have a method for running the actual stream, while the killswitch would already be available to the user. Example:
|
A few things people have been requested that could be interesting for our discussion:
|
I need to think more about this, but I think we have two essential problems in the current API:
...let me see if tomorrow I can come up with a sort possible look for the new API |
I'll start working on incorporating the first three - abstracting upon stream implementation seems like a much bigger task |
Agreed, we are not going to solve it now as it is a much bigger task - but it is good to keep it in mind to ensure the new API should be independent from any specific streaming library we could be using :) |
I'm not exactly sure how we could achieve that. As far as I'm aware, there is no common "Streaming API". Speaking of streams - By exposing a stream I mean
|
About using the different streaming API, you would have to specify separate modules that allow to use a stream library other than akka-stream (twitter4s-f2, twitter4s-monix or something)! But this is a problem for another day :) Yes, I agree with you about streams: we should allow users that are cool with streams to just use the stream. I also think we should make things easier for those that are not interested in having the full control of the stream. So maybe this suggests having two APIs? [Still brainstorming here, sorry if my answers bring more and more confusion! :D ] |
#243 I've been messing with the code a bit. I've created a duplicate implementation side by side which exposed the stream to the end user. I've also had to simplify lots of implicit stuff just not to have to figure out what parameters are required where etc. at this point. This implementation still misses any of the added-value stuff like retries and message filtering, but it is working. Lots of stuff is patch-worked just to make it compile at this point, but the core flow is there. In short, the top-level functions would return |
Hi,
first of all, thanks for building this library. It's awesome. With that said, I have a number of problems with the streaming API. I'm trying to build a service that is supposed to consume tweets 24/7, and the design of the API makes it really hard to handle any issues.
Twitter describes a pretty large collection of errors and reasons for shutting down a stream. The user of the API has no reasonable way to react to that. Let's say we use the method
filterStatuses
. It returns aFuture[TwitterStream]
that returnsSuccess
as soon as the connection is established. All events are processed within a partial function. Let's say the stream receives aDisconnectMessage
- the application can only respond to that by using side effects. What is more, type of the error received impacts the retry operation that should be performed. Some errors require immediate retry, others should be handled with backoff strategy. I found about all of this after seeing that my stream has been running for days but has not been receiving any new messages.Therefore I would like to propose one of two solutions:
([Future[TwitterStreamHandle], Future[StreamResult]])
. This would allow the end user to manually close the stream, as it is right now, as well react to errors that occur in a functional manner. I would also supply an example with proper retry strategies that would keep the stream working.autoHandleStreamErrors
that would enable the retry mechanism in case of any issues.Please let me know what you think about this, I'm happy to implement either of these solutions.
The text was updated successfully, but these errors were encountered: