How to handle backpressure in SourceQueueWithComplete instance

I am using Source.queue with backpressure as the overflow strategy to create a SourceQueueWithComplete object

I am processing an input csv file , doing some aggregations on it and then offering the rows to the SourceQueueWithComplete.

The offer method of SourceQueueWithComplete returns Future[QueueOfferResult] and because i am producing elements faster than they are consumed at some point you’ll get back QueueOfferResult.Failure

Right now i am doing something akin to

      Await.result(queue.offer(group), Duration.Inf) match {
        case QueueOfferResult.Enqueued => // ok great
        case _ =>
          retry here..

But this strikes me as particularly un-elegant , is there a nicer way to handle offer failures ?

In this specific situation, you could keep all of the processing in the stream, including reading the file and parsing the CSV. Then, back pressure will be handled automatically and you won’t need to use a queue at all.

Have a look at the CSV parsing flows documented here: