Skip to content

A simple demonstration of a Spring boot 2 application using reactive MongoDB, WebFlux and the new WebClient.

License

Notifications You must be signed in to change notification settings

optis/spring-boot-2-webflux

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring boot 2

Libraries

This project uses Spring boot 2, Spring WebFlux, Reactive MongoDB, Lombok and Twitter4J.

Configuration

To get this project up and running, you need to configure the following environment variables or application properties:

  • TWITTER_CONSUMER_KEY
  • TWITTER_CONSUMER_SECRET
  • TWITTER_ACCESS_TOKEN
  • TWITTER_ACCESS_TOKEN_SECRET

These details can be generated at Twitter Application Management.

Resources

Snippets from presentation

Key components

// Flux<Integer> extends Publisher<Integer>
Flux.range(0, 1000)
    // Operators
    .filter(nr -> nr % 2 == 0)
    .map(nr -> nr * 3)
    // Subscriber
    .subscribe(System.out::println);

Webflux

@RestController
@RequestMapping("/api/person")
public class PersonController {
    @GetMapping
    public Flux<Person> findAll() { // Returns Flux<Person>
        return Flux.just(
        	new Person("John", "Doe"),
	        new Person("Jane", "Doe"));
    }
}

Router function

@Bean
public RouterFunction<?> routes() {
    return route(GET("/api/person"), request -> ServerResponse
        .ok()
        .body(Flux.just(
        	new Person("John", "Doe"),
        	new Person("Jane", "Doe")), Person.class));
}

Reactive repository

public interface PersonRepository extends ReactiveCrudRepository<Person, String> {
    
}

WebClient

WebClient
	// Base path
	.create("http://localhost:8080/api")
    .get()
    .uri(uriBuilder -> uriBuilder
    	.path("/person")
        .queryParam("offset", 0)
        .queryParam("limit", 10)
        .build())
    .retrieve()
    // Returns Flux<Person>
    .bodyToFlux(Person.class);

About

A simple demonstration of a Spring boot 2 application using reactive MongoDB, WebFlux and the new WebClient.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published