All-new SDN-RX: Reactive Spring Data Neo4j Spring Data Neo4j / - - PowerPoint PPT Presentation

all new sdn rx reactive spring data neo4j
SMART_READER_LITE
LIVE PREVIEW

All-new SDN-RX: Reactive Spring Data Neo4j Spring Data Neo4j / - - PowerPoint PPT Presentation

All-new SDN-RX: Reactive Spring Data Neo4j Spring Data Neo4j / Neo4j-OGM Team Michael Simons Gerrit Meier @rotnroll666 @meistermeier 2 Reactive 3 Reactive Reactive in general does not boost the performance ...but gives you the control


slide-1
SLIDE 1

All-new SDN-RX: Reactive Spring Data Neo4j

Spring Data Neo4j / Neo4j-OGM Team

slide-2
SLIDE 2

2

Michael Simons @rotnroll666 Gerrit Meier @meistermeier

slide-3
SLIDE 3

Reactive

3

slide-4
SLIDE 4

Reactive in general does not boost the performance ...but

  • gives you the control over the data flow
  • e.g. back pressure
  • allows you to do more with less resources

4

Reactive

slide-5
SLIDE 5
  • (defacto) Standard API for stream processing
  • asynchronous
  • non-blocking
  • back pressure
  • Interfaces define a contract
  • most important for a client/consumer: Publisher
  • Exposed by the Neo4j Java Driver
  • Implementations: Akka, Vert.x, RxJava, Project Reactor...

5

Reactive streams

slide-6
SLIDE 6
  • Developed by Pivotal
  • Excellent integration in the Spring ecosystem
  • Publisher implementations
  • Mono: 0 or 1 element
  • Flux: 0 or n elements

6

Project Reactor

slide-7
SLIDE 7

7

Working with reactive streams

Flux.range(0, 10) .skip(3) .map(value -> value * 2) .filter(value -> value % 6 == 0) .take(Duration. ofMillis(10)) .doOnEach(value -> System. out.println("Hello")); Output: Process finished

slide-8
SLIDE 8

8

Working with reactive streams

Flux.range(0, 10) .skip(3) .map(value -> value * 2) .filter(value -> value % 6 == 0) .take(Duration. ofMillis(10)) .doOnEach(value -> System. out.println("Hello")) .subscribe(System. out::println); Output: Hello 6 Hello 12 Hello 18 Hello Process finished

slide-9
SLIDE 9

Spring Data

9

slide-10
SLIDE 10
  • Consistent programming model
  • Abstraction of data access
  • Repositories as the main entrance to the data (DDD)
  • Seamless integration in the Spring ecosystem

10

Spring Data

slide-11
SLIDE 11

11

slide-12
SLIDE 12

12

Neo4j Object Graph Mapper (Neo4j-OGM) Bolt Java Driver Embedded HTTP

slide-13
SLIDE 13

13

Neo4j Object Graph Mapper (Neo4j-OGM)

Bolt Java Driver Embedded HTTP

Spring Data Neo4j (SDN)

slide-14
SLIDE 14

14

Neo4j Object Graph Mapper (Neo4j-OGM) Spring Data Neo4j (SDN)

Chosen library by Users

slide-15
SLIDE 15

15

slide-16
SLIDE 16

Spring Data Neo4j RX

16

slide-17
SLIDE 17
  • OGM has a lot of custom class scanning/analysing

○ Spring Data Commons has superb support for this

  • OGM’s mapping logic has a lot of caching that prevents

(reactive) data streaming

17

Why SDN/RX

slide-18
SLIDE 18

18

Neo4j Object Graph Mapper (Neo4j-OGM)

Dataflow

slide-19
SLIDE 19

19

Neo4j Object Graph Mapper (Neo4j-OGM)

Dataflow

slide-20
SLIDE 20

20

Neo4j Object Graph Mapper (Neo4j-OGM)

Dataflow

Application code

slide-21
SLIDE 21
  • Combination of SDN and OGM in the Spring ecosystem
  • No “OGM-Drivers”

○ All communication with Neo4j through the Java-Driver using the Bolt-protocol

  • Key focus

○ Reactive support ○ Immutability of objects

21

What is SDN/RX

slide-22
SLIDE 22

22

Modular design

Neo4j Driver Neo4j Client Spring Data Repositories SDN/RX Integration with Spring Transactions from here on java-driver-spring-boot-starter sdn-rx-spring-boot-starter “uses” Neo4j Template

slide-23
SLIDE 23
  • Node modelling
  • Relationships between nodes
  • Full support for all Spring Data built-in repository functions
  • Derived finder methods
  • Custom Cypher annotated methods
  • Conversion and Neo4j type support
  • Projections
  • Uses the new Spring 5.2 ReactiveTransactionManager

23

What is in there (yet)

slide-24
SLIDE 24

24

Example

@Node("Movie") public class MovieEntity { @Id private final String title; @Relationship (type = "ACTED_IN", direction = INCOMING) private Set<PersonEntity> actors; public MovieEntity(String title) { this.title = title; this.description = description; } } @Node("Person") public class PersonEntity { @Id private final String name; private final Long born; public PersonEntity(Long born, String name) { this.born = born; this.name = name; } }

:Person :Movie ACTED_IN

slide-25
SLIDE 25

25

Example

public interface MovieRepository extends ReactiveNeo4jRepository<MovieEntity, String> { Mono<MovieEntity> findOneByTitle(String title); }

MATCH (n:Movie) WHERE n.title=$title return n;

slide-26
SLIDE 26

26

Example

@Test void findOneMovieByTitle() { movieRepository.findOneByTitle( "The Matrix").subscribe(movie -> { assertThat(movie.getTitle()).isEqualTo( "The Matrix"); assertThat(movie.getDescription()).isEqualTo( "..."); assertThat(movie.getDirectors()).hasSize( 2); assertThat(movie.getActors()).hasSize( 5); }); }

slide-27
SLIDE 27

27

Example

@Test void findOneMovieByTitle() { movieRepository.findOneByTitle( "The Matrix").subscribe(movie -> { assertThat(movie.getTitle()).isEqualTo( "The Matrix"); assertThat(movie.getDescription()).isEqualTo( "..."); assertThat(movie.getDirectors()).hasSize( 2); assertThat(movie.getActors()).hasSize( 5); fail("You won’t get to me"); }); }

✅ ❌

slide-28
SLIDE 28

28

Example

@Test void findOneMovieByTitle() {

  • StepVerifier. create(movieRepository.findOneByTitle( "The Matrix"))

.assertNext(movie -> { assertThat(movie.getTitle()).isEqualTo( "The Matrix"); assertThat(movie.getDescription()).isEqualTo( "..."); assertThat(movie.getDirectors()).hasSize( 2); assertThat(movie.getActors()).hasSize( 5); }) .verifyComplete(); }

slide-29
SLIDE 29

29

@RestController public class DisplayMoviesController { private final MovieRepository movieRepository; public DisplayMoviesController(MovieRepository movieRepository) { this.movieRepository = movieRepository; } @GetMapping(path = "/movies", produces = MediaType. TEXT_EVENT_STREAM_VALUE) public Flux<MovieEntity> getMovies() { return movieRepository.findAll(); } }

Example

slide-30
SLIDE 30

Spring Boot starters

30

slide-31
SLIDE 31
  • neo4j-java-driver-spring-boot-starter (1.7.x/4.0.x)
  • Creates a Java driver bean
  • Driver’s configuration properties in application.properties
  • Spring Boot health endpoint support
  • Spring Boot micrometer support (4.0.x)

31

Java Driver Users

slide-32
SLIDE 32
  • spring-data-neo4j-rx-spring-boot-starter
  • Depends on the Java driver Spring Boot starter
  • Creates

○ Neo4jClient and Neo4jTemplate beans ○ reactive variants thereof

  • Instantiates all user-defined repositories

32

Spring Data Users

slide-33
SLIDE 33

Future plans

33

slide-34
SLIDE 34
  • estimated “1.0” early 2020
  • needed for a GA from our point of view

○ Relationships with properties ○ Finalize Neo4jTemplate ○ Documentation

34

Future plans

slide-35
SLIDE 35

Getting started today

35

slide-36
SLIDE 36
  • SDN/RX

https://github.com/neo4j/sdn-rx

  • Introduction post

https://medium.com/neo4j/welcome-sdn-rx-22c8fe6cd955

  • Introduction video

https://youtu.be/Nfk4782Da0E

  • Information on the current state of Neo4j-OGM

https://medium.com/neo4j/neo4j-ogm-3-2-released-cdbaf1be1400

  • Developer guides for Java Driver, SDN/RX, Spring Boot Starters

https://neo4j.com/developer/java/

36

Getting started

slide-37
SLIDE 37

Thanks

37

slide-38
SLIDE 38

38

Hunger Games Questions for "All-new SDN-RX: Reactive Spring Data Neo4j"

1. Easy: What should be the general approach to access data in Spring Data?

a. Driver b. Repository c. Controller

2. Medium: What is the key focus when developing Spring Data Neo4j RX?

a. Reactive data access with immutable objects b. Heavy memory usage c. Cypher-Free

3. Hard: How are user-defined methods in a repository called, that do not force you to write any Cypher query? Answer here: r.neo4j.com/hunger-games