[Akka streams] Connect a sink to a source

Apologies for reposting - the google group seems to be deprecated.

I’m trying to get a new source from an existing sink so I can use the source to stream over grpc. I found this example (https://github.com/akka/akka/issues/24853):

/**
  * Materializes into a sink connected to a source, i.e. the sink pushes into the source:
  *
  * +----------+       +----------+
  * >   Sink   |------>|  Source  >
  * +----------+       +----------+
  *
  * Should be provided by Akka Streams, see https://github.com/akka/akka/issues/24853.
  */
val connection: RunnableGraph[(Sink[String, NotUsed], Source[String, NotUsed])] =
  Source
    .asSubscriber[String]
    .toMat(Sink.asPublisher[String](fanout = false))(Keep.both)
    .mapMaterializedValue {
      case (sub, pub) => (Sink.fromSubscriber(sub), Source.fromPublisher(pub))
    }

The example would generate a source and a sink, so that the sink feeds into the source, which is cool, however what I’m trying to do is to take an existing sink that already has a source connected to it, and create a new source to which the sink is feeding.

It seems like a legitimate use case but I can’t find any way to do it.

Help would be much appreciated.

Thanks,
Z

Hi,

if you have a sink that is already connected to a source, then you have a RunnableGraph, right? The API does not really allow to disassemble RunnableGraph.

Or do you have something else?