clojure http api 서버 구현을 위한...

36
Clojure HTTP API 서버 구현을 위한 라이브러리 / 김은민

Upload: eunmin-kim

Post on 21-Jan-2017

1.201 views

Category:

Software


10 download

TRANSCRIPT

Page 1: Clojure HTTP API 서버 구현을 위한 라이브러리

Clojure HTTP API 서버 구현을 위한 라이브러리 / 김은민

Page 2: Clojure HTTP API 서버 구현을 위한 라이브러리

HTTP Server Application

• Framework• Application Server• Routing• Database ORM• Database Migration• View Template

Page 3: Clojure HTTP API 서버 구현을 위한 라이브러리

Clojure HTTP API Server Application

• Clojure의 접근 방식• Clojure 언어는 작은 함수들을 조합해 큰 기능을 완성• 라이브러리 역시 작은 라이브러리를 조합해 큰 기능을 완성

• Clojure HTTP API 서버• Application Server• Routing + Servlet abstraction (Java)• Database ORM

• SQL 사용 / 편리하게 사용할 수 있는 라이브러리 필요• Database Migration• View Template• Lifecycle Library• API Documentation Library

Page 4: Clojure HTTP API 서버 구현을 위한 라이브러리

Clojure HTTP API Server Application

1. Application Server Library2. Servlet abstraction Library3. Routing Library4. SQL Library5. Database Connection Pool Library6. Database Migration Library7. Lifecycle Library8. API Documentation Library

Page 5: Clojure HTTP API 서버 구현을 위한 라이브러리

Clojure HTTP API Server Application

• Framework?• Luminus (http://www.luminusweb.net)• Duct (https://github.com/weavejester/duct)

• 왜 사용하지 않았나?• 웹 사이트 개발에 최적화 되어 있어 불필요한 Library 포함• API 서버에 더 적합한 라이브러리

• RESTful URI Routing• API Documentation

• Lumos • API 서버 구성을 위한 lein template• Opensource로 공개예정

Page 6: Clojure HTTP API 서버 구현을 위한 라이브러리

1. Application Server Library - immutant

• immutant/web - jboss undertow wrapper

사진 출처 : https://github.com/ptaoussanis/clojure-web-server-benchmarks

Page 7: Clojure HTTP API 서버 구현을 위한 라이브러리

2. Servlet abstraction Library

• Ring - weavejester (James Reeves)• 가장 많이 사용되고 있는 서블릿 Wrapper 라이브러리• 서블릿 Wrapper 기능에 충실하고 단순• middleware 방식으로 기능 확장• 기본 컨테이너로 jetty 사용• 서블릿 2.5 버전 지원

사진 출처 : https://www.booleanknot.com/

Page 8: Clojure HTTP API 서버 구현을 위한 라이브러리

2. Servlet abstraction Library

• Pedestal• Cognitect에서 지원하고 있음• Servlet wrapper + Routing• interceptor 방식으로 기능 확장 (ring middleware 호환)

• 기본 컨테이너로 jetty / tomcat / immutant 선택 가능• 서블릿 3.1 버전 지원• ring request/response 사용

Page 9: Clojure HTTP API 서버 구현을 위한 라이브러리

3. Routing Library - compojure

• compojure• Ring을 만든 weavejester가 작성• Ring과 함께 가장 많이 사용• Routing 기능만 하는 단순한 라이브러리• Parameter destructuring• URI constraint

Page 10: Clojure HTTP API 서버 구현을 위한 라이브러리

3. Routing Library - compojure

Page 11: Clojure HTTP API 서버 구현을 위한 라이브러리

3. Routing Library - pedestal

• Pedestal• Pedestal 라이브러리에 포함• URI constraint• 트리 형태로 Routing을 표현• RESTful URI를 표현하기 더 좋음

• 하나의 URI resource에 여러 동작을 표현• sub-resource 표현

Page 12: Clojure HTTP API 서버 구현을 위한 라이브러리

3. Routing Library - pedestal

Page 13: Clojure HTTP API 서버 구현을 위한 라이브러리

3. Routing Library - liberator

• Liberator• Restful Routing에 특화된 라이브러리• Compojure와 함께 사용

Page 14: Clojure HTTP API 서버 구현을 위한 라이브러리

3. Routing Library - liberator

Page 15: Clojure HTTP API 서버 구현을 위한 라이브러리

3. Routing Library - etc

• https://github.com/juxt/bidi

사진 출처 : https://github.com/juxt/bidi

Page 16: Clojure HTTP API 서버 구현을 위한 라이브러리

4. SQL Library - sqlkorma

• sqlkorma• SQL에 대응하는 매크로들을 제공• clojure.jdbc 함수들을 직접 호출할 필요가 없음• 관계 정의 기능• 데이터베이스 연결을 defdb를 사용해 Var를 만들기 때문에

connection 관리가 불편함

Page 17: Clojure HTTP API 서버 구현을 위한 라이브러리

4. SQL Library - sqlkorma

Page 18: Clojure HTTP API 서버 구현을 위한 라이브러리

4. SQL Library - honeysql

• honeysql• SQL에 대응하는 매크로로 SQL문을 생성하는 라이브러리• clojure.jdbc를 직접 사용해야 함• 단순히 SQL문을 생성하기 때문에 다른 database 라이브러리와 조화롭게 사용 가능

Page 19: Clojure HTTP API 서버 구현을 위한 라이브러리

5. Database Connection Pool Library

• Apache DBCP• HikariCP• BoneCP• c3p0

사진 출처 : https://github.com/brettwooldridge/HikariCP-benchmark

Page 20: Clojure HTTP API 서버 구현을 위한 라이브러리

5. Database Connection Pool Library - HikariCP

• HikariCP• 가볍고 벤치 마크 결과도 좋고 Clojure Wrapper도 잘 되있음• Weavejester의 component 기반 웹 프레임워크인 duct에서 사용하고 있음

사진 출처 : https://github.com/brettwooldridge/HikariCP-benchmark

Page 21: Clojure HTTP API 서버 구현을 위한 라이브러리

5. Database Connection Pool Library - HikariCP

• duct-hikaricp-component

Page 22: Clojure HTTP API 서버 구현을 위한 라이브러리

6. Database Migration Library

• migratus / ragtime• 두 라이브러리 모두 비슷한 형태와 기능을 하고 있음• Lumius Library는 migratus를 사용• weavejester의 Ragtime 라이브러리를 선택

Page 23: Clojure HTTP API 서버 구현을 위한 라이브러리

6. Database Migration Library - ragtime

Page 24: Clojure HTTP API 서버 구현을 위한 라이브러리

7. Lifecycle Library

• Model-View-Controller• Clojure Var!• Server에서 사용하는 상태 있는 Resource가 많다.• Connection Pool / Server Resource Life Cycle 관리

Page 25: Clojure HTTP API 서버 구현을 위한 라이브러리

7. Lifecycle Library - component

• Stuart Sierra component• Lifecycle 관리를 위한 라이브러리• Lifecycle 프로토콜(start/stop)을 구현• system으로 component의 의존 관계를 정하고 start/stop

• system start를 하면 모든 component에 start 함수가 의존 관계에 따라 순서대로 호출

• Application 전체 구조가 component에 의존적인 단점

Page 26: Clojure HTTP API 서버 구현을 위한 라이브러리

7. Lifecycle Library - component

• Database Component

Page 27: Clojure HTTP API 서버 구현을 위한 라이브러리

7. Lifecycle Library - component

• Server Component

Page 28: Clojure HTTP API 서버 구현을 위한 라이브러리

7. Lifecycle Library - component

• System

Page 29: Clojure HTTP API 서버 구현을 위한 라이브러리

8. API Documentation Library

• Swagger (http://swagger.io)• HTTP API를 정의하는 Spec• Swaager UI / Codegen / Editor등의 많은 툴이 있음

• fnhouse (https://github.com/Prismatic/fnhouse)• 문서 제공 보다는 Request/Response 체크에 중점을 둔 라이브러리

• swagger 변환 라이브러리가 있음

Page 30: Clojure HTTP API 서버 구현을 위한 라이브러리

8. API Documentation Library - swagger

자료 및 사진 출처 : http://petstore.swagger.io

Page 31: Clojure HTTP API 서버 구현을 위한 라이브러리

8. API Documentation Library - pedestal-swagger

• pedestal-swagger• prismatic/schema 기반• pedestal 핸들러와 인터셉터 별로 spec을 지정 할 수 있음• Swagger UI 제공

Page 32: Clojure HTTP API 서버 구현을 위한 라이브러리

Clojure HTTP API Server Application

• immutant2 Application Server Library• pedestal Servlet abstraction Library + Routing

Library• duct-hikaricp-component Database Connection Pool

Library• honeysql SQL Library• ragtime Database Migration Library• component Lifecycle Library• pedestal-swagger API Documentation Library

Page 33: Clojure HTTP API 서버 구현을 위한 라이브러리

Library 선택의 고민

• Contextual vs Composable• Composable

• Pro: 유연 / 유지보수/ 다목적 / 익숙한 사람은 빠름

• Con: 큰 책임이 따른다 / 경험이 적은 사람들에게는 훈련이 필요 / 정해진 규칙이 없음 - 잘 못 사용할 가능성

• Contextual• Pro: 문제가 해결되어 있음 / 사용이 편리함• Con: 다른 문제를 해결 하지 못함 / 유지보수가 필요함

자료 및 사진 출처 : http://javing.blogspot.kr/2014/01/contextual-vs-composable-design.html

Page 34: Clojure HTTP API 서버 구현을 위한 라이브러리

Library 선택의 고민

Contextual Composable

GUI Terminal

Framework Programmatical approach

Wizard copy&paste files into directories

Pedstal Ring / Compojure

liberator Pedestal

sqlkorma honeysql

자료 및 사진 출처 : http://javing.blogspot.kr/2014/01/contextual-vs-composable-design.html

Page 35: Clojure HTTP API 서버 구현을 위한 라이브러리

라이브러리

• pedestal (https://github.com/pedestal/pedestal)

• component (https://github.com/stuartsierra/component)

• pedestal-swagger (https://github.com/frankiesardo/pedestal-swagger)

• duct-hikaricp-component (https://github.com/weavejester/duct-hikaricp-component)

• ragtime (https://github.com/weavejester/ragtime)

• honeysql (https://github.com/jkk/honeysql)

Page 36: Clojure HTTP API 서버 구현을 위한 라이브러리

Thanks

• Lisp을 좋아하는 사람들의 그룹(한국 리스퍼)• https://groups.google.com/forum/#!forum/lisp-

korea• Clojure Korea (facebook group)

• https://www.facebook.com/groups/defnclojure