๐ŸŒˆ [Section4] 7. [Spring WebFlux] ๋ฆฌ์•กํ‹ฐ๋ธŒ ํ”„๋กœ๊ทธ๋ž˜๋ฐ

ํ˜„์ฃผยท2022๋…„ 11์›” 29์ผ
0

bootcamp

๋ชฉ๋ก ๋ณด๊ธฐ
61/71

๐Ÿ“• ์˜ค๋Š˜ ๋ฐฐ์šด ๋‚ด์šฉ!

  • ๋ฆฌ์•กํ‹ฐ๋ธŒ ์‹œ์Šคํ…œ
  • ๋ฆฌ์•กํ‹ฐ๋ธŒ ํ”„๋กœ๊ทธ๋ž˜๋ฐ
  • ๋ฆฌ์•กํ‹ฐ๋ธŒ ์ŠคํŠธ๋ฆผ์ฆˆ

โœ๏ธ ๋ฆฌ์•กํ‹ฐ๋ธŒ ์‹œ์Šคํ…œ (Reactive System)

  • ๋ฐ˜์‘์„ ์ž˜ํ•˜๋Š” ์‹œ์Šคํ…œ
    โžœ ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์— ๋ฐ˜์‘์„ ์ž˜ํ•˜๋Š” ์‹œ์Šคํ…œ

โžœ ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์— ๋Œ€ํ•œ ์‘๋‹ต ๋Œ€๊ธฐ ์‹œ๊ฐ„์„ ์ตœ์†Œํ™” ํ•  ์ˆ˜ ์žˆ๋„๋ก
์š”์ฒญ ์“ฐ๋ ˆ๋“œ๊ฐ€ ์ฐจ๋‹จ๋˜์ง€ ์•Š๊ฒŒ ํ•จ์œผ๋กœ์จ(Non-Blocking) ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ์ฆ‰๊ฐ์ ์œผ๋กœ ๋ฐ˜์‘ํ•˜๋„๋ก ๊ตฌ์„ฑ๋œ ์‹œ์Šคํ…œ

โœ” ๋ฆฌ์•กํ‹ฐ๋ธŒ ์‹œ์Šคํ…œ์˜ ์„ค๊ณ„ ์›์น™

  • MEANS
    โžœ ๋ฆฌ์•กํ‹ฐ๋ธŒ ์‹œ์Šคํ…œ์—์„œ ์‚ฌ์šฉํ•˜๋Š” ์ปค๋ฎค๋‹ˆ์ผ€์ด์…˜ ์ˆ˜๋‹จ

    • Message Driven
      โžœ ๋ฉ”์‹œ์ง€ ๊ธฐ๋ฐ˜ ํ†ต์‹ ์„ ํ†ตํ•ด ์—ฌ๋Ÿฌ ์‹œ์Šคํ…œ ๊ฐ„์˜ ๋Š์Šจํ•œ ๊ฒฐํ•ฉ ์œ ์ง€
  • FORM
    โžœ ๋ฉ”์‹œ์ง€ ๊ธฐ๋ฐ˜ ํ†ต์‹ ์„ ํ†ตํ•ด ๋ฆฌ์•กํ‹ฐ๋ธŒ ์‹œ์Šคํ…œ์ด ์–ด๋–ค ํŠน์„ฑ์„ ๊ฐ€์ง€๋Š” ๊ตฌ์กฐ๋กœ ํ˜•์„ฑ๋˜๋Š”์ง€

    • Elastic
      โžœ ์‹œ์Šคํ…œ์œผ๋กœ ๋“ค์–ด์˜ค๋Š” ์š”์ฒญ๋Ÿ‰์ด ์ ๊ฑฐ๋‚˜ ๋งŽ๊ฑฐ๋‚˜์— ์ƒ๊ด€์—†์ด ์ผ์ •ํ•œ ์‘๋‹ต์„ฑ์„ ์œ ์ง€ํ•˜๋Š” ๊ฒƒ ์˜๋ฏธ

    • Resillient
      โžœ ์‹œ์Šคํ…œ์˜ ์ผ๋ถ€๋ถ„์— ์žฅ์• ๊ฐ€ ๋ฐœ์ƒํ•˜๋”๋ผ๋„ ์‘๋‹ต์„ฑ์„ ์œ ์ง€ํ•˜๋Š” ๊ฒƒ ์˜๋ฏธ

  • VALUE
    โžœ ๋ฆฌ์•กํ‹ฐ๋ธŒ ์‹œ์Šคํ…œ์˜ ํ•ต์‹ฌ ๊ฐ€์น˜๊ฐ€ ๋ฌด์—‡์ธ์ง€๋ฅผ ํ‘œํ˜„ํ•˜๋Š” ์˜์—ญ

    • Responsive
      โžœ ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์— ์ฆ‰๊ฐ์ ์œผ๋กœ ์‘๋‹ตํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•จ์„ ์˜๋ฏธ

    • Maintainable
      โžœ ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์— ๋Œ€ํ•œ ์ฆ‰๊ฐ์ ์ธ ์‘๋‹ต์ด ์ง€์†๊ฐ€๋Šฅํ•ด์•ผ ํ•จ์„ ์˜๋ฏธ

    • Extensible
      โžœ ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์— ๋Œ€ํ•œ ์ฒ˜๋ฆฌ๋Ÿ‰์„ ์ž๋™์œผ๋กœ ํ™•์žฅํ•˜๊ณ  ์ถ•์†Œํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•จ์„ ์˜๋ฏธ

[์ฐธ๊ณ ] https://www.reactivemanifesto.org/


โœ๏ธ ๋ฆฌ์•กํ‹ฐ๋ธŒ ํ”„๋กœ๊ทธ๋ž˜๋ฐ (Reactive Programming)

  • ๋ฆฌ์•กํ‹ฐ๋ธŒ ์‹œ์Šคํ…œ์—์„œ ์‚ฌ์šฉ๋˜๋Š” ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋ชจ๋ธ

  • Non-Blocking ํ†ต์‹ ์„ ์œ„ํ•œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋ชจ๋ธ

๐Ÿ’ก ์œ„ํ‚คํ”ผ๋””์•„์— ๋‚˜์™€ ์žˆ๋Š” ๋ฆฌ์•กํ‹ฐ๋ธŒ ํ”„๋กœ๊ทธ๋ž˜๋ฐ
In computing, reactive programming is a declarative programming paradigm concerned with data streams and the propagation of change. With this paradigm, it's possible to express static (e.g., arrays) or dynamic (e.g., event emitters) data streams with ease, and also communicate that an inferred dependency within the associated execution model exists, which facilitates the automatic propagation of the changed data flow.
[์ฐธ๊ณ ] https://en.wikipedia.org/wiki/Reactive_programming

โœ” ๋ฆฌ์•กํ‹ฐ๋ธŒ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์˜ ํŠน์ง•

  • declarative programming paradigm

    • ์„ ์–ธํ˜• ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•˜๋Š” ๋Œ€ํ‘œ์ ์ธ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋ชจ๋ธ
  • data streams and the propagation of change

    • ์ง€์†์ ์œผ๋กœ ๋ฐ์ดํ„ฐ๊ฐ€ ์ž…๋ ฅ์œผ๋กœ ๋“ค์–ด์˜ฌ ์ˆ˜ ์žˆ์Œ์„ ์˜๋ฏธ
      ( ๋ฆฌ์•กํ‹ฐ๋ธŒ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์—์„œ๋Š” ๋ฐ์ดํ„ฐ๊ฐ€ ์ง€์†์ ์œผ๋กœ ๋ฐœ์ƒํ•˜๋Š” ๊ฒƒ ์ž์ฒด๋ฅผ ๋ฐ์ดํ„ฐ์— ์–ด๋–ค ๋ณ€๊ฒฝ์ด ๋ฐœ์ƒํ•จ์„ ์˜๋ฏธํ•จ )

    • ์ด ๋ณ€๊ฒฝ ์ž์ฒด๋ฅผ ์ด๋ฒคํŠธ๋กœ ๊ฐ„์ฃผํ•˜๊ณ , ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•  ๋•Œ ๋งˆ๋‹ค ๋ฐ์ดํ„ฐ๋ฅผ ๊ณ„์†ํ•ด์„œ ์ „๋‹ฌ

  • automatic propagation of the changed data flow

    • ์•ž์˜ data streams and the propagation of change์™€ ๊ฐ™์€ ์˜๋ฏธ

    • ์ง€์†์ ์œผ๋กœ ๋ฐœ์ƒํ•˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ํ•˜๋‚˜์˜ ๋ฐ์ดํ„ฐ ํ”Œ๋กœ์šฐ๋กœ ๋ณด๊ณ  ๋ฐ์ดํ„ฐ๋ฅผ ์ž๋™์œผ๋กœ ์ „๋‹ฌ

๐Ÿ’ก ๋ช…๋ นํ˜• ํ”„๋กœ๊ทธ๋ž˜๋ฐ vs ์„ ์–ธํ˜• ํ”„๋กœ๊ทธ๋ž˜๋ฐ
โ €
โœ”๏ธ ๋ช…๋ นํ˜• ํ”„๋กœ๊ทธ๋ž˜๋ฐ

  • ์–ด๋–ค ์ผ์„ ์–ด๋–ป๊ฒŒ ํ•  ๊ฒƒ์ธ๊ฐ€์— ๊ด€ํ•œ ๊ฒƒ
  • ์ฝ”๋“œ๊ฐ€ ์–ด๋–ค์‹์œผ๋กœ ์‹คํ–‰๋˜์–ด์•ผ ํ•˜๋Š”์ง€์— ๋Œ€ํ•œ ๊ตฌ์ฒด์ ์ธ ๋กœ์ง๋“ค์ด ์ฝ”๋“œ ์•ˆ์— ๊ทธ๋Œ€๋กœ ๋“ค์–ด์žˆ์Œ
    โ €
    Ex. for๋ฌธ / if๋ฌธ
    ( ์•ˆ์˜ ์ฝ”๋“œ๋“ค์ด ์œ„์—์„œ ์•„๋ž˜๋กœ ์ˆœ์ฐจ์ ์œผ๋กœ ์‹คํ–‰๋จ )

โœ”๏ธ ์„ ์–ธํ˜• ํ”„๋กœ๊ทธ๋ž˜๋ฐ

  • ๋ฌด์—‡์„ ํ•  ๊ฒƒ์ธ๊ฐ€์— ๊ด€ํ•œ ๊ฒƒ
  • ์ ˆ์ฐจ์  ๊ตฌํ˜„์„ ์ถ”์ƒํ™”ํ•จ์œผ๋กœ์จ ์ด๋ฃจ์–ด์ง
    โ €
    Ex. stream
    โžœ ๋‚ด๋ถ€ ๋ฐ˜๋ณต์ž๊ฐ€ ๋ช…๋ นํ˜• ํ”„๋กœ๊ทธ๋žจ ๋ฐฉ์‹์˜ for๋ฌธ ์—ญํ• 
    โžœ filter() ๋ฉ”์„œ๋“œ๊ฐ€ ๋ช…๋ นํ˜• ํ”„๋กœ๊ทธ๋žจ ๋ฐฉ์‹์˜ if๋ฌธ ์—ญํ• 
    ( ํ•ด๋‹น ์ฝ”๋“œ๊ฐ€ ์ตœ์ข… ์—ฐ์‚ฐ์ด ํ˜ธ์ถœ๋  ๋•Œ ํ•œ๋ฒˆ์— ์™„๋ฃŒ๋จ )
    โ €โžœ ์ตœ์ข… ์—ฐ์‚ฐ์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜์ง€ ์•Š์œผ๋ฉด ์•ž์— ์ž‘์„ฑํ•œ ๋ฉ”์„œ๋“œ ์ฒด์ธ๋“ค์ด ์‹คํ–‰๋˜์ง€ ์•Š์Œ
    [์„ ์–ธํ˜• ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ฐธ๊ณ ]
    https://www.techtarget.com/searchitoperations/definition/declarative-programming
    https://en.wikipedia.org/wiki/Declarative_programming
    โ €
    [์ฐธ๊ณ ] https://iborymagic.tistory.com/73

โœ” ๋ฆฌ์•กํ‹ฐ๋ธŒ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์˜ ํ™œ์šฉ

  • Spring WebFlux ๊ธฐ๋ฐ˜์˜ Non-Blocking ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ์จ๋จน์„ ์ˆ˜ ์žˆ์Œ

  • Blocking I/O ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—๋„ ๋ณต์žกํ•œ ๋ฐ์ดํ„ฐ ๊ฐ€๊ณต ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•ด ์จ๋จน์„ ์ˆ˜ ์žˆ์Œ

  • MSA(Microservice Architecture)์—์„œ ์ค‘์š”ํ•œ ์—ญํ• ์„ ํ•จ


โœ๏ธ ๋ฆฌ์•กํ‹ฐ๋ธŒ ์ŠคํŠธ๋ฆผ์ฆˆ (Reactive Streams)

  • ๋ฆฌ์•กํ‹ฐ๋ธŒ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์„ ์œ„ํ•œ ํ‘œ์ค€ ์‚ฌ์–‘(๋˜๋Š” ๋ช…์„ธ, Specification)

[์ฐธ๊ณ ] https://github.com/reactive-streams/reactive-streams-jvm

โœ” ๋ฆฌ์•กํ‹ฐ๋ธŒ ์ŠคํŠธ๋ฆผ์ฆˆ ์ปดํฌ๋„ŒํŠธ

โœ”๏ธ Publisher

public interface Publisher< T > {
    public void subscribe(Subscriber< ? super T > s);
}
  • ๋ฐ์ดํ„ฐ ์†Œ์Šค๋กœ ๋ถ€ํ„ฐ ๋ฐ์ดํ„ฐ๋ฅผ ๋‚ด๋ณด๋‚ด๋Š”(emit) ์—ญํ• 
    ( ๋ฐ์ดํ„ฐ๋ฅผ ๋‚ด๋ณด๋‚ด๋Š” ์ฃผ์ฒด )

    ๐Ÿ’ก emitํ•œ๋‹ค = Publisher๊ฐ€ ๋ฐ์ดํ„ฐ๋ฅผ ๋‚ด๋ณด๋‚ด๋Š” ๊ฒƒ

  • subscribe() ์ถ”์ƒ ๋ฉ”์„œ๋“œ๋ฅผ ํฌํ•จ
    โžœ ์ด subscribe()์˜ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ์ „๋‹ฌ๋˜๋Š” Subscriber๊ฐ€ Publisher๋กœ๋ถ€ํ„ฐ ๋‚ด๋ณด๋‚ด์ง„ ๋ฐ์ดํ„ฐ๋ฅผ ์†Œ๋น„ํ•˜๋Š” ์—ญํ• 
    ( subscribe() - Publisher๊ฐ€ ๋‚ด๋ณด๋‚ด๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์ˆ˜์‹ ํ•  ์ง€ ์—ฌ๋ถ€๋ฅผ ๊ฒฐ์ •ํ•˜๋Š” ๊ตฌ๋…์˜ ์˜๋ฏธ )

  • subscribe()๊ฐ€ ํ˜ธ์ถœ๋˜์ง€ ์•Š์œผ๋ฉด Publisher๊ฐ€ ๋ฐ์ดํ„ฐ๋ฅผ ๋‚ด๋ณด๋‚ด๋Š” ํ”„๋กœ์„ธ์Šค๋Š” ์‹œ์ž‘๋˜์ง€ ์•Š์Œ

โœ”๏ธ Subscriber

public interface Subscriber< T > {
    public void onSubscribe(Subscription s);
    public void onNext(T t);
    public void onError(Throwable t);
    public void onComplete();
}
  • Publisher๋กœ๋ถ€ํ„ฐ ๋‚ด๋ณด๋‚ด์ง„ ๋ฐ์ดํ„ฐ๋ฅผ ์†Œ๋น„ํ•˜๋Š” ์—ญํ• 

  • ๋„ค ๊ฐœ์˜ ์ถ”์ƒ ๋ฉ”์„œ๋“œ ํฌํ•จ

    • onSubscribe(Subscription s)

      • ๊ตฌ๋…์ด ์‹œ์ž‘๋˜๋Š” ์‹œ์ ์— ํ˜ธ์ถœ

      • onSubscribe() ๋‚ด์—์„œ Publisher์—๊ฒŒ ์š”์ฒญํ•  ๋ฐ์ดํ„ฐ์˜ ๊ฐœ์ˆ˜๋ฅผ ์ง€์ •ํ•˜๊ฑฐ๋‚˜ ๊ตฌ๋… ํ•ด์ง€ ์ฒ˜๋ฆฌ ๊ฐ€๋Šฅ

    • onSubscribe(Subscription s)

      • Publisher๊ฐ€ ๋ฐ์ดํ„ฐ๋ฅผ emitํ•  ๋•Œ ํ˜ธ์ถœ

      • emit๋œ ๋ฐ์ดํ„ฐ๋ฅผ ์ „๋‹ฌ ๋ฐ›์•„์„œ ์†Œ๋น„ ๊ฐ€๋Šฅ

    • onNext(T t)

      • Publisher๋กœ๋ถ€ํ„ฐ emit๋œ ๋ฐ์ดํ„ฐ๊ฐ€ Subscriber์—๊ฒŒ ์ „๋‹ฌ๋˜๋Š” ๊ณผ์ •์—์„œ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•  ๊ฒฝ์šฐ์— ํ˜ธ์ถœ
    • onComplete()

      • Publisher๊ฐ€ ๋ฐ์ดํ„ฐ๋ฅผ emitํ•˜๋Š” ๊ณผ์ •์ด ์ข…๋ฃŒ๋  ๊ฒฝ์šฐ ํ˜ธ์ถœ

      • ๋ฐ์ดํ„ฐ์˜ emit์ด ์ •์ƒ์ ์œผ๋กœ ์™„๋ฃŒ ๋œ ํ›„, ์ฒ˜๋ฆฌํ•ด์•ผ ๋  ์ž‘์—…์ด ์žˆ๋‹ค๋ฉด onComplete() ๋‚ด์—์„œ ์ˆ˜ํ–‰ ๊ฐ€๋Šฅ

โœ”๏ธ Subscription

public interface Subscription {
    public void request(long n);
    public void cancel();
}
  • Subscriber์˜ ๊ตฌ๋… ์ž์ฒด๋ฅผ ํ‘œํ˜„ํ•œ ์ธํ„ฐํŽ˜์ด์Šค

  • ๋‘๊ฐœ์˜ ๋ฉ”์„œ๋“œ

    • request(long n)

      • Publihser๊ฐ€ emitํ•˜๋Š” ๋ฐ์ดํ„ฐ์˜ ๊ฐœ์ˆ˜ ์š”์ฒญ
    • cancel()

      • ๊ตฌ๋…์„ ํ•ด์ง€ํ•˜๋Š” ์—ญํ• 
        โžœ ๊ตฌ๋… ํ•ด์ง€๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด Publisher๋Š” ๋”์ด์ƒ ๋ฐ์ดํ„ฐ๋ฅผ emitํ•˜์ง€ ์•Š์Œ

โœ”๏ธ Processor

public interface Processor<T, R> extends Subscriber< T >, Publisher< R > {
}
  • Subscriber ์ธํ„ฐํŽ˜์ด์Šค์™€ Publisher ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ƒ์†
    โžœ Publisher์™€ Subscriber์˜ ์—ญํ• ์„ ๋™์‹œ์— ํ•  ์ˆ˜ ์žˆ์Œ

  • ๋ณ„๋„๋กœ ๊ตฌํ˜„ํ•ด์•ผ ๋˜๋Š” ์ถ”์ƒ ๋ฉ”์„œ๋“œ๋Š” ์—†์Œ

โœ” ๋ฆฌ์•กํ‹ฐ๋ธŒ ์ŠคํŠธ๋ฆผ์ฆˆ์˜ ๊ตฌํ˜„์ฒด

โœ”๏ธ Project Reactor
( ์ค„์—ฌ์„œ Reactor )

  • ๋ฆฌ์•กํ‹ฐ๋ธŒ ์ŠคํŠธ๋ฆผ์ฆˆ๋ฅผ ๊ตฌํ˜„ํ•œ ๋Œ€ํ‘œ์ ์ธ ๊ตฌํ˜„์ฒด

  • Spring๊ณผ ๊ถํ•ฉ์ด ๊ฐ€์žฅ ์ž˜ ๋งž๋Š” ๋ฆฌ์•กํ‹ฐ๋ธŒ ์ŠคํŠธ๋ฆผ์ฆˆ ๊ตฌํ˜„์ฒด

  • Spring 5์˜ ๋ฆฌ์•กํ‹ฐ๋ธŒ ์Šคํƒ์— ํฌํ•จ๋˜์–ด ์žˆ๊ณ ,
    Sprig Reactive Application ๊ตฌํ˜„์— ์žˆ์–ด ํ•ต์‹ฌ์ ์ธ ์—ญํ•  ๋‹ด๋‹น

โœ”๏ธ RxJava
( Rx - Reactive Extension์˜ ์ค„์ž„๋ง )

  • ๋Œ€ํ‘œ์ ์ธ ๋ฆฌ์•กํ‹ฐ๋ธŒ ํ™•์žฅ(Reactive Extension) ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

  • .NET ๊ธฐ๋ฐ˜์˜ ๋ฆฌ์•กํ‹ฐ๋ธŒ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๋„ทํ”Œ๋ฆญ์Šค์—์„œ Java ์–ธ์–ด๋กœ ํฌํŒ…ํ•œ JVM ๊ธฐ๋ฐ˜์˜ ๋ฆฌ์•กํ‹ฐ๋ธŒ ํ™•์žฅ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

  • 2.0๋ถ€ํ„ฐ ๋ฆฌ์•กํ‹ฐ๋ธŒ ์ŠคํŠธ๋ฆผ์ฆˆ ํ‘œ์ค€ ์‚ฌ์–‘ ์ค€์ˆ˜
    ( ์ด ์ „ ๋ฒ„์ „์˜ ์ปดํฌ๋„ŒํŠธ์™€ ํ•จ๊ป˜ ํ˜ผ์šฉ๋˜์–ด ์‚ฌ์šฉ์ด ๋˜๊ณ  ์žˆ์Œ )

โœ”๏ธ Java Flow API

  • ๋ฆฌ์•กํ‹ฐ๋ธŒ ์ŠคํŠธ๋ฆผ์ฆˆ ํ‘œ์ค€ ์‚ฌ์–‘์„ Java ์•ˆ์— ํฌํ•จ์„ ์‹œํ‚จ ๊ตฌ์กฐ
    ( Flow API๋Š” ๋ฆฌ์•กํ‹ฐ๋ธŒ ์ŠคํŠธ๋ฆผ์ฆˆ๋ฅผ ๊ตฌํ˜„ํ•œ ๊ตฌํ˜„์ฒด X )
    โžœ ๋ฆฌ์•กํ‹ฐ๋ธŒ ์ŠคํŠธ๋ฆผ์ฆˆ ์‚ฌ์–‘์„ ๊ตฌํ˜„ํ•œ ์—ฌ๋Ÿฌ ๊ตฌํ˜„์ฒด๋“ค์— ๋Œ€ํ•œ SPI ์—ญํ• 

    ๐Ÿ’ก SPI (Service Provider Interface)
    โžœ ํŠน์ •ํ•œ ์—ญํ• ์„ ํ•˜๋Š” ์„œ๋น„์Šค ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉ์ž๊ฐ€ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด ์ฃผ๋Š” ํ™•์žฅ ๋ฉ”์ปค๋‹ˆ์ฆ˜ (extension mechanism)
    ( ์œ„ ๊ตฌํ˜„์ฒด๋“ค์„ ์‚ฌ์šฉ์ž๊ฐ€ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด์ฃผ๋Š” ๊ฒƒ )

โœ”๏ธ ๊ธฐํƒ€ ๋ฆฌ์•กํ‹ฐ๋ธŒ ํ™•์žฅ (Reactive Extension)`

  • ํŠน์ • ์–ธ์–ด์—์„œ ๋ฆฌ์•กํ‹ฐ๋ธŒ ์ŠคํŠธ๋ฆผ์ฆˆ๋ฅผ ๊ตฌํ˜„ํ•œ ๋ณ„๋„์˜ ๊ตฌํ˜„์ฒด๊ฐ€ ์กด์žฌํ•œ๋‹ค๋Š” ์˜๋ฏธ

  • ๋‹ค์–‘ํ•œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์—์„œ ๋ฆฌ์•กํ‹ฐ๋ธŒ ์ŠคํŠธ๋ฆผ์ฆˆ๋ฅผ ๊ตฌํ˜„ํ•œ ๋ฆฌ์•กํ‹ฐ๋ธŒ ํ™•์žฅ(Reactive Extension) ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ œ๊ณต

  • ๋Œ€ํ‘œ์ ์ธ ๋ฆฌ์•กํ‹ฐ๋ธŒ ํ™•์žฅ(Reactive Extension) ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ RxJava๊ฐ€ ์žˆ์Œ
    ( ์ด์™ธ์—๋„ RxJS, RxAndroid, RxKotlin, RxPython, RxScala ๋“ฑ )

[์ฐธ๊ณ ] https://reactivex.io/


โœ๏ธ ๋ฆฌ์•กํ‹ฐ๋ธŒ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์—์„œ ์‚ฌ์šฉ๋˜๋Š” ์šฉ์–ด ์ •๋ฆฌ

( ์œ„์—์„œ ์ •๋ฆฌํ•œ ์šฉ์–ด๋Š” ์„ค๋ช… ์ƒ๋žต )

  • Publisher

  • Emit

  • Subscriber

  • Subscribe

  • Signal
    โžœ Publisher๊ฐ€ ๋ฐœ์ƒ์‹œํ‚ค๋Š” ์ด๋ฒคํŠธ

    Ex. subscribe() ๋ฉ”์„œ๋“œ๊ฐ€ ํ˜ธ์ถœ๋˜๋ฉด Publisher๊ฐ€ ๋ฐ์ดํ„ฐ๋ฅผ ํ•˜๋‚˜ํ•˜๋‚˜ emitํ•จ
    โ €
    โžœ ํ•˜๋‚˜ํ•˜๋‚˜๋ฅผ emit ํ•˜๋Š” ๊ฒƒ == ์ด๋ฒคํŠธ์˜ ๋ฐœ์ƒ
    โ €
    โžœ ์ด ์ด๋ฒคํŠธ๋ฅผ ๋‹ค๋ฅธ ์ปดํฌ๋„ŒํŠธ์—๊ฒŒ ์ „๋‹ฌํ•˜๋Š” ๊ฒƒ == Signal์„ ์ „์†กํ•œ๋‹ค

  • Operator
    โžœ โžœ ๋ฆฌ์•กํ‹ฐ๋ธŒ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์—์„œ ์–ด๋–ค ๋™์ž‘์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๋ฉ”์„œ๋“œ
    Ex. fromIterable(), filter(), reduce() ๋“ฑ ๋ฉ”์„œ๋“œ ํ•˜๋‚˜ ํ•˜๋‚˜

  • Sequence
    โžœ Operator ์ฒด์ธ์œผ๋กœ ํ‘œํ˜„๋˜๋Š” ๋ฐ์ดํ„ฐ์˜ ํ๋ฆ„
    ( Operator ์ฒด์ธ์œผ๋กœ ์ž‘์„ฑ๋œ ์ฝ”๋“œ ์ž์ฒด๊ฐ€ ํ•˜๋‚˜์˜ Sequence )

  • Upstream / Downstream

    • Upstream
      โžœ Sequence ์ƒ์˜ ํŠน์ • Operator๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์œ„์ชฝ์˜ Sequence ์ผ๋ถ€

    • Downstream
      โžœ Sequence ์ƒ์˜ ํŠน์ • Operator๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์•„๋ž˜ ์ชฝ Sequence ์ผ๋ถ€


๐Ÿ˜œ ์‹ค์Šต

  • projects - be-template-reactive
    ( ๊ตฌํ˜„ ์‹ค์Šต๋ณด๋‹จ ์˜ˆ์‹œ์— ๊ฐ€๊นŒ์›€ )

๐ŸŒˆ ๋Š๋‚€์ 

์ผ๋‹จ ์ด ํ•™์Šต์€ '์ด๋Ÿฌํ•œ ๊ธฐ์ˆ ์ด ์žˆ๋‹ค ~'๋ผ๊ณ  ์†Œ๊ฐœํ•œ๋Š ๋Š๋‚Œ์˜ ์ถ”๊ฐ€ํ•™์Šต์ด๋ผ๊ณ  ํ•˜๋‹ˆ
Spring MVC ํ•™์Šต์„ ๋ณต์Šต ํ•ด์•ผ๊ฒ ๋‹ค !

0๊ฐœ์˜ ๋Œ“๊ธ€