Skip to content

๐Ÿž It is not bread-utils, just the toaster

Notifications You must be signed in to change notification settings

hotire/reactor-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Reactor Utils

toaster

This is not bread-utils, just the toaster

Installation

Maven

<repository>
  <id>hotire</id>
  <url>http://dl.bintray.com/hotire/utils</url>
</repository>

<dependency>
    <groupId>com.github.hotire</groupId>
    <artifactId>reactor-utils</artifactId>
    <version>0.0.8.0</version>
</dependency>

BindingUtils

commons-beanutils-based, springframework-core-convert-based

ServerRequest

  • queryParams

  • pathVariables

bind to instance of class type

Custom Convert

  • commons-beanutils

    • LocalDateTime.class
    • LocalDate.class
    • Year.class
    • Month.class
  • springframework-core-convert-based

    • Long.class
    • Boolean.class

bind

 public Mono<ServerResponse> handle(ServerRequest request) {
   Data data = bind(request, Data.class)
   ....
 }   

: All values of ServerRequest(queryParams, pathVariables) into ValueObject

bindToMono

  public Mono<ServerResponse> handle(ServerRequest request) {
    return bindToMono(request, Data.class)
      .filter(data -> {...})
      .map(data -> {...})
      .doOnError(error -> {...})
  }   

: All values of ServerRequest(queryParams, pathVariables) into Mono<ValueObject>

bindOne

  public Mono<ServerResponse> handle(ServerRequest request) {
    final String userId = bindOne(request, String.class).orElse(DEFAULT);
    ....
    ....
  }  

: One value of ServerRequest(queryParam, pathVariable) into Optional<ValueObject>

bindOneToMono

  public Mono<ServerResponse> handle(ServerRequest request) {
    return bindOneToMono(request, String.class)
      .map(userId -> userId.orElseThrow() -> {...})         
      .filter(userId -> {...})
      .map(userId -> {...})
      .doOnError(userId -> {...})
  }   

: One value of ServerRequest(queryParam, pathVariable) into Mono<Optional<ValueObject>>

MonoBackPressureSubscriber

MonoBackPressureSubscriber request to publisher and consume Mono then pull Mono from publisher

blog : https://blog.naver.com/gngh0101

reference : https://projectreactor.io/docs/core/release/reference/

MDC

Thread-local based MDC is difficult when you switch thread in Webflux.

If you want to maintain MDC, similarly the thread, MDC must also switch.

How to use

class Configuration {
  static {
    Schedulers.addExecutorServiceDecorator(MDCScheduledExecutorServiceDecorator.class.getName(),
          (scheduler, scheduledExecutorService) -> new MDCScheduledExecutorServiceDecorator(scheduledExecutorService));
  }
}

Codec

Provide decorator of HttpMessageReader / HttpMessageWriter.

Utf8HttpMessageWriterDecorator using HttpMessageWriter is also provided

public class Utf8HttpMessageWriterDecorator<T> extends HttpMessageWriterDecorator<T>{
    //...
    //...
}

About

๐Ÿž It is not bread-utils, just the toaster

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages