-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a variant of Source.actorRef
that uses simple acking for backpressure
#17610
Comments
/cc @fommil |
This is actually similar to mapAsync but reversed. It would be interesting to see if this can be implemented in a more generic way making it a Flow instead (which then can be used to create the desired Source in turn) using the new AsyncStage. |
The point is to expose an |
a It would be good if the actual ack message could be defined, as it is in akka-io, as a function. e.g. some people will have a wrapper class for the Ack, containing markup about the message that was received. For A simple "error" message to close the stream should also be supported. Advanced error behaviour should probably require a custom implementation. |
btw, I don't care about the buffer here. If the underlying actor sends a message without having received an |
It could only work if there is a separate registration message, true. |
@jrudolph are you going to scaladays? Give me a ping if you are (I'll be talking about ENSIME, sadly at the same time as sirthius)... I'll owe you a few beers if you're working on this 😄 |
I'm not sure to understand why you need a ack parameter, but it would be definitely great to be able to get an ActorRef from a Source, without writing one manually. |
The As @drewhk says, there's already |
@drewhk @jrudolph Sorry my comment was not clear at all :) The problem I see with Source.actorRef, but I must be misunderstanding how it works, is that when you define a source like this :
Then to get the ref, you need to do something like this to get the actor ref :
You can replace So I think it would be handful to be able to get a "default" ActorPublisher like this one, to be able to elements into a source : http://stackoverflow.com/a/29077212/591922 Did I miss something? |
You can only get the ActorRef after materialization. Before that, the Source is not running, there is no actor to get the reference of. Therefore, if you want to reuse that Source in various settings, you need to handle its materialized value via the xMat methods, and propagate it to the use site. |
@loicdescotte the topic of materialization is conceptually separate from the topic of how to implement a source / publisher. Materialization allows you to reuse a So, either you go with reusability and, as @drewhk said, feed the result of materialization back to where it's needed, or if you don't care for reusability you can use this trick to create a one-time Source and instantly get to the val (ref, publisher) = Flow[Item].toMat(Sink.publisher)((a, b) => (a, b) /* or `Keep.both` */).runWith(source)
val source = Source(publisher) |
Maybe reverse it (no need for Flow):
Btw, it might make sense to expose this pattern as a built-in method
|
(Of course, I just stupidly copied the code from above) |
Added ticket for built-in support: #17769 |
I still recommend propagating the materialized value explicitly though. |
Sorry, I hope I'm not polluting the issue...
In fact , if I use a custom actor like in this exemple, I can use the source to merge it with another and it's working very well. I can consume a merged stream in the end with data from several sources.
I need to go deeper in the API to udnerstand how to do this. Thanks a lot for your help. |
The example uses |
@jrudolph What does reusable mean for a source ? |
A See this document for more information: http://doc.akka.io/docs/akka-stream-and-http-experimental/1.0-RC3/stream-design.html |
Thanks for the link and sorry again for spamming in the issue :) |
The Sink.actorRefWithAck has been implemented, the Source should be added as a matter of symmetry. |
It seems that at some point the topic changed to the materialization problem and the ACK problem was forgotten. Did I miss something? It would be great to have a Source.actorRefWithAck (and something similar with typed actors) |
I quickly implemented a version with back-pressure based upon the new graph stage implementation (see #26054) |
* Implements actorRef source variant with backpressure #17610 * Small improvements to documentation and source #17610 * Small improvements to test #17610 * Small improvements to implementation and tests #17610 * Adds API for akka-typed #17610 * Adds ack sender and java api for typed #17610 (cherry picked from commit f37f415)
…triknw actorRef source variant with backpressure #17610
This would allow a simpler migration path for systems which have used an application-level Ack-based model in the past and would like to update parts of the processing pipeline to streams without having to convert everything at one go or having to implement
ActorPublisher
manually.One possibility would be to introduce another overload
which responds to a message with an
ack
as long as (or as soon as) buffer space is available.See also http://stackoverflow.com/questions/30479777/integrating-an-ack-based-actor-with-akka-stream?noredirect=1#comment49124723_30479777
The text was updated successfully, but these errors were encountered: