Source.actorRefWithBackpressure vs Source.queue

Hi everyone, i have a question here I want to publish incoming data dynamically into my stream and i found these two ways to do that and as far i can tell these two approaches can resolve my problem but what are the drawback in which one ? I really can’t say

Here some thins that i have notice:

Source.queue

  • Have buffer configuration and OverflowStrategy

Soure.actorRefWithBackpressure

  • Have a nice approach to handle acks and error on stream
  • Only ends stream after receive a message to end

You can also imperatively complete the queue, using complete() (or fail it using fail(ex)).

The big difference is in how backpressure is applied:

With the queue, you must keep track of the returned Future[QueueOfferResult]s to know if there is any idea trying to offer another element. You can observe if the stream failed or cancelled through watchCompletion().

The Source.actorRefWithBackpressure you can only interact with if the pushing logic itself is an actor since you need to wait for an ack for each element before you are allowed to send the next. You can observe if the stream stops running by watching it but you cannot determine if it cancelled or failed.

If possible it is often better to pull data into the stream instead of pushing though, for example using unfold, unfoldAsync, unfoldResource and friends.

1 Like

@johanandren
Pretty much thank you for the explanation I ill take a look at unfold, unfoldAsync, unfoldResource and friends. Now I understand the differences between these two =D