Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
外部APIとうまく付き合う
Search
makinoshi
February 17, 2018
Programming
380
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
外部APIとうまく付き合う
Clojureを使って外部APIを使うコードを設計する、書く方法について
makinoshi
February 17, 2018
Other Decks in Programming
See All in Programming
更なる可用性を求めて、5年間運用したKotlinのアプリケーションをGoでリプレイスする話
ken_tunc
0
370
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
180
仕様駆動開発による爆速プロダクト開発 / Bakusoku Spec Driven Development
kobakei
0
140
新卒PdEのリアル
ryu1013
1
520
スマートフォンでモールス信号を送受信する 〜スマートフォンのLEDとカメラで作る光通信の設計と実装〜
atsuki_seo
0
190
Streamlitで実現する自然言語データアプリ開発
ayumu_yamaguchi
1
320
wkhtmltopdfの次どうするか問題2026
willnet
2
1.8k
技術的負債の返済は、AI時代の複利で効く投資 — 経営としての意思決定とその遂行
curekoshimizu
0
1.9k
パズルゲームの作り方 / how to make puzzle games
kaityo256
PRO
2
240
[GoCon2026] When Goroutines Are Not Enough: Runtime Locality in High-Throughput Go
takehaya
6
2.5k
一人だけ、Kiroが静止する日
hideg
0
130
モジュールの視点からSwiftを読み解く #iosdc
s_shimotori
0
200
Featured
See All Featured
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
950
Context Engineering - Making Every Token Count
addyosmani
9
1.2k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.4k
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
Into the Great Unknown - MozCon
thekraken
41
2.7k
Typedesign – Prime Four
hannesfritz
42
3.2k
Unsuck your backbone
ammeep
672
58k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Transcript
֎෦"1*ͱ ͏·͖͘߹͏ 2018-02-11 clj-ebisu #2 @makinoshi
Me • αΠϘζελʔτΞοϓεגࣜձࣾ • Like: C++(11~), PostgreSQL(SQL), Clojure, Emacs(Spacemacs), MS
Sculpt Ergonomic Keyboard • Hobby: ϚϯΨ,͓ञ • ࠷ۙͷΠνΦγ: cljr-create-fn-from-example
ΞδΣϯμ • (֎෦)APIʹΞΫηε͢Δ෦ΛͲ͏࡞Δ͔ • ೖྗ͢ΔσʔλߏΛͲ͏ͭ͘Δ͔ • ΧϓηϧԽ͞Εͨ෦ॲཧΛͭ͘Δ • ݁ՌΛද͢σʔλߏ
ೖྗ͢ΔσʔλߏΛ࡞Δ
ྫ) SendGridͷAPI {:headers {"Authorization" "Bearer ...."} :content-type :json :form-params {:subject
"໊݅" :content [{:type "text/plain" :value "ຊจ"}] :from {:name "MyService" :email "
[email protected]
"} :personalizations [{:to [{:email "
[email protected]
" :name "a͞Μ"} {:email "
[email protected]
" :name "a͞Μ"}] :custom_args {:id "1"}} {:to [{:email "
[email protected]
" :name “b͞Μ"}] :custom_args {:id “2"}}]}} • ͜ͷߏΛҙࣝͨ͠ίʔυॻ͖ͨ͘ͳ͍
Builderύλʔϯ • ֤ϝιουͰҾΛνΣοΫͭͭ͠σʔλཷ ΊࠐΉ • buildϝιουͰ͑ΔɺνΣοΫ͢Δ • ೖग़ྗܗࣜͷมߋΛ෦ͰٵऩͰ͖ΔˠAPIͷ มߋ͏APIࣗମͷมߋ༰қʹͳΔ
࣮ྫ (-> (mail/builder something-component) (mail/with-subject "໊݅") (mail/with-content "ຊจ") (mail/with-recipients [{:email
"
[email protected]
" :to-name "a͞Μ" :id 1 :callback “/app/path/1”} {:email "
[email protected]
" :to-name "b͞Μ" :id 2 :callback “/app/path/2”}]) mail/build) • AWS SDK for Javaͷ࣮͕BuilderύλʔϯΛ ͱ্ͯखʹ͍ͬͯΔͱࢥ͍·͢
෦ॲཧΛΧϓηϧԽ͢Δ
͏ଆʹ࿙Βͨ͘͠ͳ͍ • ͏ϥΠϒϥϦͷڍಈ • ྫ֎͕ൃੜ͢Δঢ়گͷࠩҟɺΓͷࠩҟ(map, promise, etc..) • ࣮ߦ •
rate limit • ಉ࣌ଓ • ϦτϥΠ • ෳͷϦΫΤετ୯ҰϦΫΤετͷγʔέϯεͱͯ͠ѻ͍͍ͨ
diehardͱڞʹ • https://github.com/sunng87/diehard • ઃఆϕʔεͰɺretry/circuit breaker/rate limitterΛ؆୯ʹ࣮Ͱ͖Δ • JavaͷϥΠϒϥϦɺnet.jodah/failsafeͷϥο ύ
࣮ྫ (diehard.core/defratelimiter rl {:rate 100}) ; per sec (clj-http.client/with-connection-pool {:timeout
10 :insecure? false :default-per-route 100} (->> coll (map #(future (diehard.core/with-retry {:retry-if (fn [resp exp] (or (>= (:status resp) 500) (instance? IOException exp))) :max-retries 3 :delay-ms 1000} (diehard.core/with-rate-limiter rl (api/call endpoint %))))) (map deref) doll)) • ΊͪΌͪ͘Ό؆୯ • ͬͱهड़ྔগͳ͘ఆٛ͢Δํ๏υΩϡϝϯτʹ͋Γ·͢
Γͷදݱ
ओͳΤϥʔॲཧ • ѻ͍͍͢Γ • ୯ͳΔσʔλ • Τϥʔ͔Ͳ͏͔ఆ͍͢͠ • Τϥʔʹͳͬͨͱ͖ͷҾΛͦͷ··औΓग़ͤΔ •
ѻ͍ʹ͍͘Γ • ྫ֎͕͛ΒΕͨΓɺ͛ΒΕͳ͔ͬͨΓ • ֎෦ͷϥΠϒϥϦͰఆٛ͞Εͨܕ • promise(ಛʹ֎෦ϥΠϒϥϦͷ) • ඇಉظ͕͍͍͔Ͳ͏͔ݺͼग़͠ଆͷࣄ • => GolangελΠϧ or ಠࣗఆٛͷEitherͷͲͪΒ͔͕Αͦ͞͏
࣮ࡍʹ྆ํͬͯΈͨ݁Ռ • GolangελΠϧͷํ͕ॻ͍ͯͯϛε͕গͳͦ͞͏ʹײ͍ͯ͡· ͢ • ѻ͍͘͢ɺγϯϓϧʹॻ͚Δ • (group-by #(-> %
second some?) results) (try (let [resp (clj-http.client/post endpoint params)] [{:resp resp resp :params params} nil]) (catch clojure.lang.ExceptionInfo e [{:params params} (ex-data e)]) (catch java.io.IOException e [{:params params} e]))
·ͱΊ • ClojureͰσʔλ࡞ͷநԽʹBuilder ཱͭ • ϥΠϒϥϦͷڍಈAPIͰ͋Δ͜ͱࣗମ֎͔ ΒӅ͢ˠޙʑ؆୯ʹมߋͰ͖Δ • Γྫ֎Ͱͳ͘σʔλͱͯ͠ѻ͍͘͢
͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ ͥͻ͝ҙݟΛԼ͍͞ɻ