This project uses Spring boot 2, Spring WebFlux, Reactive MongoDB, Lombok and Twitter4J.
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.
- Presentation
- Blogpost about getting started with Spring boot 2
- Blogpost containing conference talks about Spring boot 2
// Flux<Integer> extends Publisher<Integer>
Flux.range(0, 1000)
// Operators
.filter(nr -> nr % 2 == 0)
.map(nr -> nr * 3)
// Subscriber
.subscribe(System.out::println);
@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"));
}
}
@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));
}
public interface PersonRepository extends ReactiveCrudRepository<Person, String> {
}
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);