$30 off During Our Annual Pro Sale. View Details »

複数のマイクロサービスと連携したWeb APIの設計と構築 in Playframework Scala / play-scala with services

Yusuke Wada
September 29, 2016

複数のマイクロサービスと連携したWeb APIの設計と構築 in Playframework Scala / play-scala with services

https://eventdots.jp/event/599919
にて発表したスライドです。

Yusuke Wada

September 29, 2016
Tweet

More Decks by Yusuke Wada

Other Decks in Programming

Transcript

  1. 8FC"1*ͷ ઃܭͱߏங JO1MBZGSBNFXPSL4DBMB Ϋϥεϝιουגࣜձࣾɹ࿨ా༞հ #dots_meetup

  2. • ձࣾ֓ཁ • Ϋϥεϝιουגࣜձࣾ • ʮ͢΂ͯͷਓʑͷ૑଄׆ಈʹߩݙ͠ଓ͚Δʯ • ࣄۀ಺༰ • "84ίϯαϧςΟϯά

    • ϞόΠϧΞϓϦ։ൃ • Ϗοάσʔλ෼ੳ • %FWFMPQFST*0ͷϒϩά 2 ձࣾ঺հ
  3. • ໊લɿ࿨ా༞հ • ܦྺ • ೥݄ɿ۝भେֶେֶӃଔ • ೥݄ɿෆಈ࢈޲͚Ϋϥ΢υαʔϏεͷ։ൃձࣾ΁ೖࣾ • 8JDLU

    +BWB Ͱ8FCΞϓϦͷ։ൃɾอकӡ༻ • ೥݄ɿΫϥεϝιουגࣜձࣾ΁ೖࣾ • ϞόΠϧΞϓϦͷ"1*։ൃΛ୲౰ 3 ࣗݾ঺հ
  4. ࠓ೔͸ɺϞόΠϧΞϓϦͷόοΫΤϯυ8FC"1*։ൃ ͷɺ͓࿩Ͱ͢

  5. ͳͥࢲͨͪ͸৽͍ٕ͠ज़ΛٻΊΔͷ͔ • αʔϏεͷ࣭Λ্͍͛ͨ • αʔϏε๊͕͑Δ໰୊Λղܾ͍ͨ͠ • ։ൃޮ཰Λ্͍͛ͨ • ୯७ʹָ͍͠ •

    นʹͿͪ͋ͨͬͯղܾͨ͠ͱ͖ͷخ͠͞Λ΋ͱΊͯ • ϒϥϯσΟϯάʢձࣾͱͯ͠PSݸਓͱͯ͠ʣ 5
  6. ৽ٕज़ͷ࠾༻৽͍͠खஈͷ֫ಘ౤ࢿ

  7. ࠓ೔࿩͢͜ͱ • ͳͥ1MBZGSBNFXPSL4DBMB͔ • ͳʹ͕ͭ͘ΕΔ͔ • ౤ࢿ͢ΔՁ஋͕͋Δ͔ 7

  8. ͳͥ1MBZ4DBMB͔

  9. 4DBMBʁ • 0CKFDU0SJFOUFE.FFUT'VODUJPOBM • 53"*54 • $PNCJOFUIFqFYJCJMJUZPG
 +BWBTUZMFJOUFSGBDFT
 XJUIUIFQPXFSPGDMBTTFT
 5IJOLQSJODJQMFENVMUJQMFJOIFSJUBODF

    • 1"55&3/."5$)*/( • 5IJOLlTXJUDIzPOTUFSPJET
 .BUDIBHBJOTUDMBTTIJFSBSDIJFT 
 TFRVFODFT BOENPSF 9 The Scala Programming Language 
 http://www.scala-lang.org/
  10. 1MBZGSBNFXPSLʁ • %FWFMPQFSGSJFOEMZ • 5ZQFTBGFUZ • #VJMUJOUFTUJOHUPPMT • 4DBMFQSFEJDUBCMZ •

    /POCMPDLJOH*0 • #VJMUPO"LLB • .PEFSOXFCNPCJMF • 3&45GVMCZEFGBVMU • +40/JTBpSTUDMBTTDJUJ[FO 10 Play Framework - Build Modern & Scalable Web Apps with Java and Scala https://www.playframework.com/
  11. ฐࣾʹͯ8&#"1*ͷ։ൃͰར༻ • ϞόΠϧόοΫΤϯυͱͯ͠ͷ8FC"1*Λ։ൃ͍ͯ͠·͢ • աڈʹ͸OPEFKT΍SVCZͰ΋ • ݱࡏ͸1MBZGSBNFXPSL4DBMB͕ϝΠϯ 11 O’Reilly Japan

    - ϚΠΫϩαʔϏεΞʔΩςΫνϟ https://www.oreilly.co.jp/books/9784873117607/
  12. ٕज़ͷબఆ͸ͲͷΑ͏ʹߦͬͨͷ͔ • ։ൃ͢ΔγεςϜ͕େن໛ʹͳ͍ͬͯ͘ɺ௥Ճ։ൃ͕͋Δͱ ͍͏લఏʹཱͬͯߟ͑ͨ • ύϑΥʔϚϯε • 1MBZ4DBMBWTOPEFKTWT3VCZPO3BJMT • ࣾ಺ϕϯνϚʔΫͰ1MBZ4DBMBͷਓউͪ

    • େن໛ͳίʔυͷॻ͖΍͢͞ɾݟ΍͢͞ • ΦϒδΣΫτࢦ޲ͱؔ਺ܕͷ͍͍ͱ͜औΓ • ௥Ճɾमਖ਼ͷετϨεܰݮ 12
  13. ͳͥ1MBZGSBNFXPSL4DBMB͔ • ։ൃ໘ • େن໛ɾ௥Ճ։ൃͷલఏʹͨͬͨͱ͖ͷϝϯςφϯεੑ • -JOLFE*OΛ͸͡Ίͱͨ͠େن໛γεςϜͰͷ࠾༻ࣄྫ͋Γ  • ӡ༻໘

    • +7. "LLBɻੑೳ͕ظ଴Ͱ͖Δ • +BWBͰͷӡ༻஌ݟɾӡ༻πʔϧ͕ྲྀ༻Ͱ͖Δ 13 [*] The Play Framework at LinkedIn | LinkedIn Engineering https://engineering.linkedin.com/play/play- framework-linkedin
  14. ͳʹ͕ͭ͘ΕΔ͔

  15. ঢ়گઃఆ • ϞόΠϧΞϓϦ։ൃҊ݅Λड஫ͨ͠ɻ͓٬༷͸Ϣʔβاۀ • ཁٻͦͷ΋ͷ͸ϞόΠϧΞϓϦͱͦͷ$.4ͷ։ൃͰɺ8FC "1*΋Ұॹʹ։ൃ͢Δ • ͢Ͱʹళฮͷ104Ϩδ΍ϙʔλϧαΠτ޲͚ʹՔಇ͍ͯ͠Δ ଞϕϯμͷαʔϏε͕͋Δ •

    Ծ૝௨՟αʔϏεʢίΠϯͷݮࢉɺՃࢉʹରԠʣ • ܠ඼αʔϏεʢܠ඼ͷ෇༩ػೳ͕͋Δʣ 15
  16. ঢ়گઃఆ 16

  17. ࿩ͷ͢͢Ίํ • ϞόΠϧόοΫΤϯυ΁ͷཁٻʹରͯ͠ɺ1MBZ 4DBMB "84 Λ࢖ͬͯͲͷΑ͏ʹઃܭɾ։ൃ͔ͨ͠Λ࣮૷୲౰ͷࢹ఺͔Β ࿩͠·͢ • Ϣʔβొ࿥ॲཧ •

    ଞͷαʔϏεͱ࿈ܞͨ͠ॲཧ • ςετʹΑΔ඼࣭ͷ޲্ 17
  18. ࿩ͷ͢͢Ίํ • ϞόΠϧόοΫΤϯυ΁ͷཁٻʹରͯ͠ɺ1MBZ 4DBMB "84 Λ࢖ͬͯͲͷΑ͏ʹઃܭɾ։ൃ͔ͨ͠Λ࣮૷୲౰ͷࢹ఺͔Β ࿩͠·͢ • Ϣʔβొ࿥ॲཧ •

    ଞͷαʔϏεͱ࿈ܞͨ͠ॲཧʢࠓ೔͸͜Εʣ • ςετʹΑΔ඼࣭ͷ޲্ 18
  19. ίΠϯͱܠ඼Λ ަ׵Ͱ͖ΔΑ͏ʹͯ͠ɻ

  20. ՝୊ • ୯७ʹίΠϯΛݮΒͯ͠ܠ඼Λ͚ͭΔ͚ͩͰ͸ෆे෼ • ͭͷαʔϏεͷؒͰτϥϯβΫγϣϯΛ͸Εͳ͍͜ͱ͕࠷ େͷ՝୊ 20

  21. ํ਑ • ͍ͪ͹Μආ͚͍ͨঢ়گ͸ɺ
 ίΠϯ͕ݮͬͯɺܠ඼͕෇༩Ͱ͖ͳ͍͜ͱɻ
 ๷ࢭ͢ΔͨΊʹɺ • ίΠϯΛݮΒ͢લʹϩοΫ • ܠ඼෇༩ʹࣦഊͨ͠ΒɺϦτϥΠΛ͔͚Δ •

    ։࢝ɾऴྃϩάΛग़͢ 21
  22. ࣮૷ 22

  23. ॲཧͷϩοΫ • ͘͝୹͍࣌ؒʹɺҙਤͤͣ࿈ଓͯ͠ొ࿥ϦΫΤετ͕ඈΜͰ ͖ͨ৔߹ɺσʔλෆ੔߹͕ൃੜ͢Δ͔΋͠Εͳ͍ • ϞόΠϧΞϓϦ͚ͩʹ੍ޚΛٻΊΔͷ͸ࠅ • ႈ౳ੑΛ୲อͰ͖ͳ͍1651045ϦΫΤετΛอޢ͍ͨ͠ • 3FEJTͷTFUOYͷੑ࣭Λར༻ͯ͠ϩοΫΛ࣮ݱ͢Δ

    • &MBTUJDBDIFΛར༻͢Δ͜ͱͰϚϧναʔό؀ڥͰͷϩοΫ ػߏ͕࣮ݱͰ͖Δ 23
  24. ϦτϥΠॲཧͷྫ • 424ͰϦτϥΠϝοηʔδΛ؅ཧ • ϝοηʔδͷडऔਓͱͳΔϫʔΧʔΛ
 1MBZGSBNFXPSLʹಉࠝ͞Ε͍ͯΔ"LLB"DUPSͰ࣮૷͢Δ • "DUPS͸෼ࢄγεςϜʹΑΔߴ͍ॲཧੑೳΛތΔ͕ɺࠓճͷέʔ εͰ͸4VQFSWJTPS4USBUFHZʹΑΔϑΥʔϧττϨϥϯεͷଆ ໘Λॏࢹ

    24 Fault Tolerance — Akka Documentation http://doc.akka.io/docs/akka/snapshot/scala/fault-tolerance.html
  25. ։࢝ɾऴྃϩάͷྫ • <*/'0>GSPNUSBOTBDUJPOJO5SBOTBDUJPO"DUPS-PHHFSBLLBBDUPSEFGBVMU EJTQBUDIFS
 USBOTBDUJPOUZQF$PJO&YDIBOHFUSBOTBDUJPOUBH$PJO&YDIBOHF4UBSU USBOTBDUJPOUSBOTBDUJPO)BTI,FZGDEGCCFGC USBOTBDUJPOKTU5SBOTBDUJPO%BUF5JNF5 • <*/'0>GSPNUSBOTBDUJPOJO5SBOTBDUJPO"DUPS-PHHFSBLLBBDUPSEFGBVMU EJTQBUDIFS


    USBOTBDUJPOUZQF$PJO&YDIBOHFUSBOTBDUJPOUBH$PJO&YDIBOHF'JOJTI
 USBOTBDUJPOUSBOTBDUJPO)BTI,FZGDEGCCFGC
 USBOTBDUJPOQSFTFOU*E&
 USBOTBDUJPOKTU5SBOTBDUJPO%BUF5JNF5 USBOTBDUJPOSFTVMU4VDDFTTUSBOTBDUJPOOPUF$PJOFYDIBOHFDPNQMFUFEz • "DUPS-PHHJOHͰຊॲཧͷύϑΥʔϚϯεΛམͱͣ͞ඇಉظϩάग़ྗ͕Մೳ 25 Logging (Scala) — Akka Documentation http://doc.akka.io/docs/akka/2.0/scala/logging.html
  26. ͳʹ͕ͭ͘ΕΔ͔ʁ • ෳ਺ͷϚΠΫϩαʔϏεͱ࿈ܞͨ͠όοΫΤϯυ • %ZOBNP%#΍424΋ҰछͷϚΠΫϩαʔϏε • ඇಉظʹΞΫηεɺཉ͍͠෦෼Λ౷߹ͯ͠ΫϥΠΞϯτ΁ฦ͢ • େن໛ͳ8FC"1* •

    σβΠϯύλʔϯ͕ద༻Ͱ͖ΔΫϥεߏ଄ • ؔ਺ܕͷ؆͕ܿ͞ద༻Ͱ͖ΔϩδοΫ • ߴՄ༻ΞϓϦέʔγϣϯ • +BWBͷڧྗͳΤίγεςϜͷԸܙʹ͔͋ͣΕΔ • l+7.্Ͱಈ͔͠ଓ͚Δʹ͸z஌ݟ͕ྲྀ༻Մೳ 26
  27. ΞϦ͔ʁφγ͔ʁ

  28. 1MBZ4DBMB౤ࢿ͢ΔՁ஋͕͋Δ͔ʁ • ΞϦʂ • େن໛ʢΤϯυϙΠϯτ͕Ҏ্ʣ • όοΫΤϯυͱͯ͠ͷ"1*։ൃ • +BWB΍3VCZΤϯδχΞ͕ͦΘͦΘ͍ͯ͠Δ •

    ஫ҙʂ • ͪΐͬͱͨ͠αʔϏεΛ࡞Δఔ౓Ͱ͸ԸܙΛײ͡ͳ͍͔΋͠Ε·ͤ Μɻ΍ΔͳΒҊ݅ϨϕϧͰɻ৽αʔϏεɺϑϧϦχϡʔΞϧ • ڭҭίετɻΤίγεςϜ΋ؚΊͯ࢖͍͜ͳͤΔΑ͏ʹͳΔ͸
 ೥ఔ౓ඞཁɻͰ͖Ε͹ઌಋͯ͘͠ΕΔϝϯόʔ͕ډΔͱޮ཰ྑ͍ɻ 28
  29. ฐࣾͰ͸͜ΜͳਓࡐΛืू͍ͯ͠·͢ • ࠷৽ͷٕज़Λ࣮Ҋ݅΁ੵۃతʹ౤ೖ͍ͨ͠ʂ • "84ɺαʔόʔαΠυɺϞόΠϧΞϓϦؔ͢Δઐ໳తͳΤ ϯδχΞͱҰॹʹಇ͖͍ͨʂ • %FWFMPQFST*0Ͱϒϩάॻ͖͍ͨʂ • εΩϧ

    • J04"OESPJE • +BWB4DBMB3VCZ • "84 29
  30. νʔϜମ੍ • J04։ൃਓ • "OESPJE։ൃਓ • ϞόΠϧόοΫΤϯυ։ൃʢ8FC"1* $.4ʣਓ • Ϛωʔδϝϯτɺਐ௙؅ཧਓ

    30
  31. ར༻πʔϧ • 4MBDL • ϝϯόʔಉ࢜ͷίϛϡχέʔγϣϯɺ$*௨஌ɺϩά؂ࢹ௨஌ • (JU)VC 5SBWJT$* • "OTJCMF

    $MPVE'PSNBUJPO • -PHFOUSJFT • %BUBEPH • ;VCF ;FO)VC 31
  32. '"2 • ೖࣾͨ͠Βͦͷٕज़͹͔Γʁ • ͍͍͑ɺ΍ͬͺΓϞόΠϧΞϓϦ࡞Γ͍ͨɺαʔόαΠυ͕΍Γ ͍ͨɺΞϦͰ͢ɻ࣮ࡍʹҠͬͨΤϯδχΞͨ͘͞Μ͍·͢ • ٕज़ྗߴͦ͏ͳਓ͹͔ΓͳΠϝʔδʁ • ֤ʑಘखෆಘख͋Γ·͢ɻʮ͜ΕͩͬͨΒ΍͍͚ͬͯΔ͔΋ʯͱ

    ͸ձࣾઆ໌ձ΁ࢀՃͳͬͨ͞ํʑͷײ૝ • ϒϩάͬͯઈରॻ͔ͳ͍ͱ͍͚ͳ͍ͷʁ • ͦΜͳ͜ͱ͸ͳ͍Ͱ͢ɻͨͩॻ͖ͨ͘ͳΔෆࢥٞͳνΧϥ͕͜ͷ ձࣾʹ͸͋Δ 32