티스토리 뷰

Kotlin

Ktor Pipeline, PipelinePhase

nodeal 2023. 8. 26. 18:21
반응형

Pipeline을 갖는 component는 Engine, Application, Routing, Route가 있다.

각 component의 기본 phase는 다음이 있다:

Engine EnginePipeline before
    call
    after
  ApplicationReceivePipeline Before
    Transform
    After
  ApplicationSendPipeline Before
    Transform
    Render
    ContentEncoding
    TransferEncoding
    After
    Engine
Application ApplicationCallPipeline Setup
    Monitoring
    Plugins
    Call
    Fallback
  ApplicationReceivePipeline Before
    Transform
    AfterTransform
    After
  ApplicationSendPipeline Before
    Transform
    Render
    BodyTransformationCheckPostRender
    ContentEncoding
    TransferEncoding
    After
    Engine
Routing ApplicationCallPipeline Setup
    Monitoring
    Plugins
    Call
    Fallback
  ApplicationReceivePipeline Before
    Transform
    After
  ApplicationSendPipeline Before
    Transform
    Render
    ContentEncoding
    TransferEncoding
    After
    Engine
Route ApplicationCallPipeline Setup
    Monitoring
    Plugins
    Call
    Fallback
  ApplicationReceivePipeline Before
    Transform
    After
  ApplicationSendPipeline Before
    Transform
    Render
    ContentEncoding
    TransferEncoding
    After
    Engine

요청이 들어왔을 때 실행 순서는 다음과 같다:

before: Engine
Setup: Application
Monitoring: Application
Plugins: Application
Call: Application
Setup: Routing > Route
Monitoring: Routing > Route
Plugins: Routing > Route
Call: Routing > Route
// Route body 시작

Route body에서 receive를 호출하면 ApplicationReceivePipeline이 실행된다.

Before: Engine > Application > Routing > Route
Transform: Engine > (DefaultTransform) > Application > (ContentNegotiation) > Routing > Route
AfterTransform: Application
After: Engine > Application > Routing > Route
// receive 끝

respond를 호출하면 ApplicationSendPipeline이 실행된다.

Before: Engine > Application > Routing > Route
Transform: Engine > Application > Routing > Route
Render: Engine > Application > Routing > Route
BodyTransformationCheckPostRender: Application
ContentEncoding: Engine > Application > Routing > Route
TransferEncoding: Engine > Application > Routing > Route
After: Engine > Application > Routing > Route
Engine: Engine > Application > Routing > Route

- ApplicationSendPipeline은 finish를 호출하거나 respond없이 route body가 종료될 때에도 호출된다.

 

Route body가 종료되면 ApplicationCallPipeline.Fallback이 실행된다.

Fallback: Routing > Route > Application

한 요청 처리가 모두 완료될 때 EnginePipeline의 나머지 phase가 실행된다.

Engine: call > After
// 요청 끝

 

반응형

'Kotlin' 카테고리의 다른 글

Nullable value class: Long? long?  (1) 2023.05.07
Kotlin/JVM Vector, ArrayList, Mutex 수행 시간  (0) 2023.02.11
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
글 보관함