Add docs and examples for RS fromPublisher #25468
This commit is contained in:
parent
45636e5af4
commit
dba69dba1d
8 changed files with 155 additions and 31 deletions
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (C) 2020 Lightbend Inc. <https://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.stream.operators.source;
|
||||
|
||||
//#imports
|
||||
import java.util.concurrent.Flow.Subscriber;
|
||||
import java.util.concurrent.Flow.Publisher;
|
||||
|
||||
import akka.NotUsed;
|
||||
import akka.stream.scaladsl.Source;
|
||||
import akka.stream.scaladsl.JavaFlowSupport;
|
||||
|
||||
//#imports
|
||||
|
||||
object FromPublisher {
|
||||
case class Row(name: String)
|
||||
|
||||
class DatabaseClient {
|
||||
def fetchRows(): Publisher[Row] = ???
|
||||
}
|
||||
|
||||
val databaseClient: DatabaseClient = ???
|
||||
|
||||
// #example
|
||||
val names: Source[String, NotUsed] =
|
||||
// A new subscriber will subscribe to the supplied publisher for each
|
||||
// materialization, so depending on whether the database client supports
|
||||
// this the Source can be materialized more than once.
|
||||
JavaFlowSupport.Source.fromPublisher(databaseClient.fetchRows())
|
||||
.map(row => row.name);
|
||||
//#example
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue