Getting underway with a reactive data store

Since this book is aimed at the cutting edge of Spring Boot 2.0 and its Reactive Streams support, we have to pick something a little more up to date than JPA. The JPA spec doesn't cover reactive programming. Hence, its APIs are not reactive. However, MongoDB has reactive drivers, and will be perfect.

To get going, we need to install the latest version of MongoDB 3.4 (for reactive support).

If you're using macOS X, installing MongoDB is as simple as this:

$ brew install mongodb
==> Installing mongodb
==> Downloading https://homebrew.bintray.com/bottles/mongodb-
3.4.6.el_capitan.bottle.tar.gz
########################################################## 100.0% ==> Pouring mongodb-3.4.6.el_capitan.bottle.tar.gz ==> Summary /usr/local/Cellar/mongodb/3.4.6: 18 files, 267.5MB

With MongoDB installed, we can launch it as a service, like this:

$ brew services start mongodb
==> Successfully started `mongodb` (label: homebrew.mxcl.mongodb)
For other operating systems, check out the download links at https://www.mongodb.com/download-center. For more details about installing MongoDB, visit https://docs.mongodb.com/manual/installation/.

Assuming that we have MongoDB installed and running, we can now delve into writing a little code.

To write any MongoDB code, we need to add Spring Data MongoDB to our classpath. We can do so by updating our build file with the following:

    compile('org.springframework.boot:spring-boot-starter-
data-mongodb-reactive')

The preceding, new compile-time dependency pulls in the following:

  • Spring Data MongoDB
  • MongoDB's core components + Reactive Stream drivers
It's important to point out that both spring-boot-starter-webflux and spring-boot-starter-data-mongodb-reactive transitively bring in Project Reactor. Spring Boot's dependency-management plugin is responsible for ensuring they both pull in the same version.

With all these things on the classpath, Spring Boot will get busy configuring things for us. But first, what is the problem we are trying to solve?

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

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