gringrape/coding-life

Spring Webflux

Opened this issue · 6 comments

프로젝트 설정: https://start.spring.io/

image

Unzip to particular destination

unzip -d ./ ~/Downloads/greeting.zip

j option

 -j     junk paths.  The archive's directory structure is not recreated;
        all files are deposited in the extraction directory (by default,
        the current one).

가장 상위 경로 정보 제거

unzip -j -d ./ ~/Downloads/greeting.zip

위와 같이 junk path 옵션을 사용 하면 파일의 상대 경로 정보가 모두 소실된다.
다음처럼 목적지 설정후에 이름을 바꿔준다.

unzip -d ./ ~/Downloads/greeting.zip && mv greeting spring-webflux-example

작업 브랜치 생성
image

Mono

하나의 자원에 대한 지연된 자원 개념.
Promise 와 유사함.

Mono create

 Mono.<String>create(sink -> {
     HttpListener listener = event -> {
         if (event.getResponseCode() >= 400) {
             sink.error(new RuntimeException("Failed"));
         } else {
             String body = event.getBody();
             if (body.isEmpty()) {
                 sink.success();
             } else {
                 sink.success(body.toLowerCase());
             }
         }
     };

     client.addListener(listener);

     sink.onDispose(() -> client.removeListener(listener));
 });
 

https://projectreactor.io/docs/core/release/api/reactor/core/publisher/Mono.html#create-java.util.function.Consumer-