Reactive Spring Data

Since Reactor can be used with Spring Data, we can take full advantage of the reactive programming model at this stage. This means that you can persist data represented as Flux or Mono objects. Let's review the following example, implemented with MongoDB:

@Test
public void findAllShouldFindTheTotalAmountOfRecordsInserted()
{
int quantityOfEntitiesToPersistAsFlux = 100;
// Saving a Flux with 100 items
repository.saveAll
(
Flux.just(generateArrayWithElements
(quantityOfEntitiesToPersistAsFlux))

)
.then()
.block();
// Saving a Mono
repository.saveAll(Mono.just(new Customer("Rene")))
.then()
.block();
List<String> customerIds = repository.findAll()
.map(customer -> customer.getId())
.collectList()
.block();
int totalAmountOfInserts = quantityOfEntitiesTo
PersistAsFlux + 1;
Assert.assertEquals(totalAmountOfInserts, customerIds.size());
}

Note that the provided information is represented as Flux and Mono objects, and the queried data is obtained as a Flux object, which is manipulated using the map operator to recover only the IDs as List<String> to verify the number of entities created.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.42.128