Slide 28
Slide 28 text
Spring Data - Reactive Repository
28 Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
interface PersonRepository extends ReactiveCrudRepository {
}
Flux.interval(Duration.ofSeconds(1))
.zipWith(starks)
.map(Tuple2!::getT2)
.flatMap(repository!::save)
.subscribe();
String[] names = { "Eddard", "Catelyn", "Jon", "Rob", "Sansa", "Aria", "Bran", "Rickon" };
Flux starks = Flux
.fromStream(Stream.generate(() !->
names[ramdom.nextInt(names.length-1)])
.map(Person!::new));
> cstrobl $ ./bin/mongo --port 52291
> use test
switched to db test
{ "_id" : ObjectId("591009c5ed68a820fb9956a5"), "name" : "Sansa",
"_class" : "com.example.DemoApplication$Person" }
{ "_id" : ObjectId("591009c6ed68a820fb9956a6"), "name" : "Rob",
"_class" : "com.example.DemoApplication$Person" }
{ "_id" : ObjectId("591009c7ed68a820fb9956a7"), "name" : "Sansa",
"_class" : "com.example.DemoApplication$Person" }
{ "_id" : ObjectId("591009c8ed68a820fb9956a8"), "name" : "Rob",
"_class" : "com.example.DemoApplication$Person" }
{ "_id" : ObjectId("591009c9ed68a820fb9956a9"), "name" : "Jon",
"_class" : "com.example.DemoApplication$Person" }
{ "_id" : ObjectId("591009caed68a820fb9956aa"), "name" : "Aria",
"_class" : "com.example.DemoApplication$Person" }
{ "_id" : ObjectId("591009cbed68a820fb9956ab"), "name" : "Rob",
"_class" : "com.example.DemoApplication$Person" }
{ "_id" : ObjectId("591009cced68a820fb9956ac"), "name" : "Jon",
"_class" : "com.example.DemoApplication$Person" }
{ "_id" : ObjectId("591009cded68a820fb9956ad"), "name" : "Sansa",
"_class" : "com.example.DemoApplication$Person" }
> db.person.find();