Giter Site home page Giter Site logo

chakra-coder / spring-boot-2-webflux Goto Github PK

View Code? Open in Web Editor NEW

This project forked from optis/spring-boot-2-webflux

0.0 1.0 0.0 55 KB

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

License: MIT License

Java 100.00%

spring-boot-2-webflux's Introduction

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);

spring-boot-2-webflux's People

Contributors

g00glen00b avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.