Skip to content

Building a reactive service using Spring WebFlux that uses Spring Data Reactive Repository for reading/writing data from/to mongoDB.

Notifications You must be signed in to change notification settings

bilalwahla/reactive-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status codecov

Building a Reactive Microservice

What you'll build

You’ll build a reactive tweet service using Spring WebFlux that uses Spring Data Reactive Repository for reading and writing the tweets to mongoDB.

Service will accept GET & POST requests at

http://localhost:8080/tweets

and GET, PUT and DELETE requests at

http://localhost:8080/tweets/{id}

where 'id' is the identifier for the tweet to perform the action on.

Service also accepts GET requests at

http://localhost:8080/stream/tweets

producing (responding with) text/event-stream.

What you'll need

Build with Maven

In order to write this service I have used Spring Boot making it super simple to include all the required dependecies wihout having to manage each and every one. For this service following are the only Spring Boot dependencies we need to define for it to fetch all (transitively) for us:

  • spring-boot-starter-webflux
  • spring-boot-starter-data-mongodb-reactive

Rest of the dependencies defined in the script are scoped only for testing.

The Spring Boot Maven plugin provides many convenient features

  • It collects all the jars on the classpath and builds a single, runnable "über-jar", which makes it more convenient to execute and transport your service.
  • It searches for the public static void main() method to flag as a runnable class.
  • It provides a built-in dependency resolver that sets the version number to match Spring Boot dependencies. You can override any version you wish, but it will default to Boot’s chosen set of versions.

To build the service run

./mvnw clean build

and to run (by default on port 8080) of course you need to first have mongoDB installed and up and running (by default on port 27017). Then you can simply run the following command and give the service a go

./mvnw spring-boot:run

About

Building a reactive service using Spring WebFlux that uses Spring Data Reactive Repository for reading/writing data from/to mongoDB.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published