Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Spring Bootで実装とインフラをこれでもかと分離するための試み
Search
Shin Tanimoto
April 17, 2025
Technology
7
1.4k
Spring Bootで実装とインフラをこれでもかと分離するための試み
JJUG Night Seminar (2025-04-17)
Shin Tanimoto
April 17, 2025
Tweet
Share
More Decks by Shin Tanimoto
See All by Shin Tanimoto
クラウドネイティブ時代のコンテナ環境におけるJavaアプリケーションのメトリクス・ログ・トレースモニタリング
shintanimoto
5
2.4k
26 Java Years
shintanimoto
0
100
Let’s Have Fun with Reactive Programming, Using Reactor and WebFlux
shintanimoto
0
310
Monitoring and Visualizing Your (Micro)services
shintanimoto
1
390
現代に求められるJavaコミュニティとは / What should be the Java Community of Today?
shintanimoto
0
980
人生がときめく「学び」の魔法 / The Life-Changing Magic of Studying
shintanimoto
6
1.8k
業務で使いたいWebFluxによるReactiveプログラミング / Introduction to Reactive Programming using Spring WebFlux
shintanimoto
9
9.7k
from old Java to modern Java (2017) #jjug
shintanimoto
4
1.8k
Spring Cloud Sleuth + Zipkin with Elasticsearch #zipkin_jp
shintanimoto
1
1.3k
Other Decks in Technology
See All in Technology
私も懇親会は苦手でした ~苦手だからこそ懇親会を楽しむ方法~ / 20251127 Masaki Okuda
shift_evolve
PRO
4
350
経営から紐解くデータマネジメント
pacocat
8
1.7k
名刺メーカーDevグループ 紹介資料
sansan33
PRO
0
970
Claude Code はじめてガイド -1時間で学べるAI駆動開発の基本と実践-
oikon48
20
11k
Flutter Thread Merge - Flutter Tokyo #11
itsmedreamwalker
1
110
Bedrock のコスト監視設計
fohte
2
250
Codeer.LowCode.Blazor 紹介と成長録
wadawada
0
110
DGX SparkでローカルLLMをLangChainで動かした話
ruzia
0
130
今すぐGoogle Antigravityを触りましょう
rfdnxbro
0
230
変わるもの、変わらないもの :OSSアーキテクチャで実現する持続可能なシステム
gree_tech
PRO
0
1.2k
Master Dataグループ紹介資料
sansan33
PRO
1
4k
TypeScript 6.0で非推奨化されるオプションたち
uhyo
15
5.6k
Featured
See All Featured
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3k
Large-scale JavaScript Application Architecture
addyosmani
514
110k
Embracing the Ebb and Flow
colly
88
4.9k
The Power of CSS Pseudo Elements
geoffreycrofte
80
6.1k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.6k
Why You Should Never Use an ORM
jnunemaker
PRO
60
9.6k
Making the Leap to Tech Lead
cromwellryan
135
9.6k
Balancing Empowerment & Direction
lara
5
770
GitHub's CSS Performance
jonrohan
1032
470k
BBQ
matthewcrist
89
9.9k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
36
6.1k
Raft: Consensus for Rubyists
vanstee
140
7.2k
Transcript
#JJUG Shin Tanimoto / 2025-04-17 SPRING BOOTͰ࣮ͱΠϯϑϥΛ ͜ΕͰ͔ͱ͢ΔͨΊͷࢼΈ JJUGφΠτηϛφʔ 20254݄
୩ຊ ৺ (Shin Tanimoto) EverforthɺAcroquest Technologyͷ2ࣾͰಇ͘ΤϯδχΞ Java ChampionɺOracle ACEɺJJUGද ஶॻʮJavaຊ֨ೖʯ
झຯϕϏϝλͷϥΠϒͱϑΝϯΧϜࡱӨ Twitter - @cero_t ࣗݾհ
࠷ۙɺաܹͷਓ͕πΠολʔʢݱɿXʣʹډͯා͍ͷͰ͕͢… ࣗݾհ
Spring Boot + Spring CloudΛͬͯϚΠΫϩαʔϏε։ൃΛ͢Δ͜ͱ ΞϓϦέʔγϣϯྖҬʹؔ৺ࣄ͕૿͍͑ͯͬͨ ҙࣝͷഎܠ Spring Boot ΞϓϦέʔγϣϯྖҬ
ΞϓϦέʔγϣϯྖҬ Spring Boot + Spring CloudΛͬͯϚΠΫϩαʔϏε։ൃΛ͢Δ͜ͱ ΞϓϦέʔγϣϯྖҬʹؔ৺ࣄ͕૿͍͑ͯͬͨ ҙࣝͷഎܠ Spring Cloud
Eureka ผͷSpring Boot ϚΠΫϩαʔϏε Spring Boot
Spring Boot + Spring CloudΛͬͯϚΠΫϩαʔϏε։ൃΛ͢Δ͜ͱ ΞϓϦέʔγϣϯྖҬʹؔ৺ࣄ͕૿͍͑ͯͬͨ ҙࣝͷഎܠ Spring Cloud Eureka
Spring Cloud Stream ผͷSpring Boot ϚΠΫϩαʔϏε RabbitMQ Spring Boot ΞϓϦέʔγϣϯྖҬ
Spring Boot + Spring CloudΛͬͯϚΠΫϩαʔϏε։ൃΛ͢Δ͜ͱ ΞϓϦέʔγϣϯྖҬʹؔ৺ࣄ͕૿͍͑ͯͬͨ ҙࣝͷഎܠ Spring Cloud Eureka
Spring Cloud Stream Spring Cloud Sleuth ผͷSpring Boot ϚΠΫϩαʔϏε RabbitMQ Zipkin Spring Boot ΞϓϦέʔγϣϯྖҬ
Spring CloudΛͬͯΔͱɺόʔδϣϯΞοϓׂ͕ͱਏ͍… ϝδϟʔόʔδϣϯʢδΣωϨʔγϣϯʣ͕มΘΔͱAPI͕େ͖͘มԽ͢Δ͜ͱ͕͋Δ Spring BootɺSpring CloudͷผϓϩδΣΫτͱͷฒΈ͕߹Θͳ͍͜ͱ͕͋Δ JavaΛόʔδϣϯΞοϓΛ͢ΔࡍʹɺϥΠϒϥϦϑϨʔϜϫʔΫͷόʔδϣϯΞοϓඞཁ ʹͳΔ͜ͱ͕͋Δ͕ɺ্ͷཧ༝ͰԘ௮͚ʹͤ͟ΔΛಘͳ͘ͳΔ͜ͱ͕͋Δ ҙࣝͷഎܠ
SPRING BOOT͚͓ͩ͏
Spring Boot͚ͩͬͯɺͦΕҎ֎Ͱ͖Δ͚ͩ֎෦ʹ͍࣋ͬͯ͜͏ ҙࣝͷഎܠ Spring Cloud Eureka Spring Cloud Stream Spring
Cloud Sleuth ผͷSpring Boot ϚΠΫϩαʔϏε RabbitMQ Zipkin Spring Boot ΞϓϦέʔγϣϯྖҬ
Spring Boot͚ͩͬͯɺͦΕҎ֎Ͱ͖Δ͚ͩ֎෦ʹ͍࣋ͬͯ͜͏ αΠυΧʔαʔϏεΛ͓͏ ҙࣝͷഎܠ ผͷSpring Boot ϚΠΫϩαʔϏε RabbitMQ Zipkin Spring
Boot Dapr ΞϓϦέʔγϣϯྖҬ
Daprk8sͰͷӡ༻͕جຊ ҙࣝͷഎܠ Spring Boot Dapr Pod K8s
։ൃڥʹDockerͱminikubeͱdaprΛೖΕͯɺͯ͢ͷ։ൃऀʹk8sΛֶΜͰΒͬͯ ։ൃڥͰϞοΫΛ͑ΔΑ͏ʹͯ͠ ຊ൪ڥͰࢹ༻ͷΤʔδΣϯτೖΕͯ ར༻͢Δڥͷҧ͍ɺڥ͝ͱͷଓઃఆ࣮ͷΛ͢Δͷͱ ڥ͝ͱͷ application-*.yaml Λ্खͬͯ͘ٵऩͯ͠ ҙࣝͷഎܠ
ΞϓϦέʔγϣϯྖҬ ڥͷ͜ͱΛΞϓϦέʔγϣϯͷ࣮ઃఆϑΝΠϧ͕୲͏ ҙࣝͷഎܠ ։ൃڥ༻ ઃఆϑΝΠϧ ςετڥ༻ ઃఆϑΝΠϧ ӡ༻ڥ༻ ઃఆϑΝΠϧ ։ൃڥ
ςετڥ ӡ༻ڥ Spring Boot ଓ ଓ ଓ ࣮ߦ ࣮ߦ ࣮ߦ
ΞϓϦέʔγϣϯྖҬ ڥͷ͜ͱΛΞϓϦέʔγϣϯͷ࣮ઃఆϑΝΠϧ͕୲͏ͷɺ࣮࣭తͳʮ૬ޓࢀরʯ ҙࣝͷഎܠ ։ൃڥ༻ ઃఆϑΝΠϧ ςετڥ༻ ઃఆϑΝΠϧ ӡ༻ڥ༻ ઃఆϑΝΠϧ ։ൃڥ
ςετڥ ӡ༻ڥ Spring Boot ଓ ଓ ଓ ࣮ߦ ࣮ߦ ࣮ߦ
૬ޓࢀর͢ΔΑ͏ͳঢ়ଶΛ Ϥγͱͨ͘͠ͳ͍
ͦ͏ͩͰ͖Δ͚ͩ ࣮ͱΠϯϑϥΛ͠Α͏
#JJUG Shin Tanimoto / 2025-04-17 SPRING BOOTͰ࣮ͱΠϯϑϥΛ ͜ΕͰ͔ͱ͢ΔͨΊͷࢼΈ JJUGφΠτηϛφʔ 20254݄
1. ઃఆϑΝΠϧͷྲّྀ 2. HTTPଓͷྲّྀ 3. Ωϡʔଓͷྲّྀ 4. DBଓͷྲّྀ 5. ΞϓϦέʔγϣϯࢹͷྲّྀ
ΞδΣϯμ
1. ઃఆϑΝΠϧͷྲّྀ
աܹͳͷͰ ʮapplication.yaml ʹ։ൃڥͷઃఆͷΈΛೖΕͯ ɹͦΕҎ֎ͷ application-test.yaml application-prod.yaml Έ͍ͨͳͷ ɹܾͯ͠࡞Δ͖Ͱͳ͍ʯ ͱ͍͏͕͋Γ·͢
Spring BootͷϓϩϑΝΠϧػೳʢ—spring.pro f iles.active=devͱ͔ʣېࢭͰ͢ 1. ઃఆϑΝΠϧͷྲّྀ
৽͍͠։ൃऀ͕ git ͔ΒίʔυΛऔಘ͖ͯͯ͠ɺԿͷΦϓγϣϯ͚ͭͣʹ࣮ߦͨ͠Β ͳ͘ಈ͘ͱ͍͏ঢ়ଶΛࢦ͢ ։ൃڥߏஙʹ࣌ؒΛֻ͚ͤ͞ͳ͍ ୯ମςετʢ͍͍ͩͨJUnitʣ·Ͱ։ൃڥͷൣᙝ ݁߹ςετڥӡ༻ڥͷ͜ͱΛʮΞϓϦέʔγϣϯʯͷؔ৺ࣄʹ͠ͳ͍ 1. ઃఆϑΝΠϧͷྲّྀ
݁߹ςετڥӡ༻ڥͰɺͦΕͧΕͷڥʢDockerͱ͔ECSͱ͔k8sͱ͔ʣͷ ڥมΛར༻ͯ͠ application.yaml ͷઃఆΛ্ॻ͖͢Δ = σϓϩΠ༻εΫϦϓτͷதʹೖΕΔ σϓϩΠ༻εΫϦϓτʮΠϯϑϥʯΛ୲͏ׂ σϓϩΠ༻εΫϦϓτΞϓϦέʔγϣϯͱผͷgitϦϙδτϦʹೖΕΔ ҟೝΊΔɻ༏͍͠ͷͰ 1.
ઃఆϑΝΠϧͷྲّྀ
ΞϓϦέʔγϣϯྖҬ 1. ઃఆϑΝΠϧͷྲّྀ ։ൃڥ༻ ઃఆϑΝΠϧ Spring Boot ͦΕͧΕͷڥ ଓ ࣮ߦ
্ॻ͖ ڥʹؔ͢ΔใΛ֎͔Β༩͑Δ͜ͱͰɺ࣮࣭తʹΠϯϑϥˠΞϓϦͷҰํతͳࢀরʹͳΔ
ͪΐͬͱ͚ͩτϦοΩʔͳ͜ͱ͕ඞཁʹͳΔ߹͋Δ͚Ͳৄׂ͍͠Ѫ͢ΔͶ ։ൃڥͰDBଓύεϫʔυΛฏจͰॻ͍ͪΌ͏͚Ͳ ςετڥҎ߱ secretsʢSecretManagerͱ͔ʣʹೖΕΔͱ͍͏߹ʹ จ๏͕গ͠มΘΔͱ͔ host ࢦఆͰͷଓ͔ɺprotocol://user:id@address ࢦఆͰͷଓ͔ͱ͔ ۩ମతͳΛ͢Δͱ͕࣌ؒΓͳ͍ͷͰɺઌഐ͔AIʹฉ͍ͯͶ 1.
ઃఆϑΝΠϧͷྲّྀ
2. HTTPଓͷྲّྀ
աܹͳͷͰ ʮϓϩηε֎ͷURLͯ͢ઃఆϑΝΠϧʹॻ͖͘Ͱ͋Δɻ ɹ͍ͭͰɺͲΜͳଓઌͰɻ ɹJDBCAMQP͚ͩͰͳ͘ɺHTTPؚΊͯɺͯ͢ྫ֎ͳ͘ʯ ͱ͍͏͕͋Γ·͢ɻ 2. HTTPଓͷྲّྀ
ϚΠΫϩαʔϏεA͔ΒϚΠΫϩαʔϏεBΛݺͼग़͢ඞཁ͕͋Γ·͢ ։ൃڥ - http://localhost:8081/serviceB/ Dockerςετڥӡ༻ڥ - http://serviceB/ ͳ͔ͥEC2Ͱಈ͍ͯΔςετڥ - http://192.168.10.123/
2. HTTPଓͷྲّྀ
ઃఆϑΝΠϧʹ։ൃڥͷURLͷΈهࡌ͢Δ myApp.urls.serviceB=http://localhost:8081/serviceB/ ͦΕͧΕͷڥͷڥมͰ্ॻ͖͢Δ myApp.urls.serviceB=http://serviceB/ export myApp_urls_serviceB=http://192.168.10.123/ 2. HTTPଓͷྲّྀ
࣮ଆͰ @Value @Con f igurationProperties ΛͬͯઃఆΛར༻͢Δ @Value("${myApp.urls.serviceB}") String baseUrlServiceB;
restClient.get() .baseUrl(baseUrlServiceB) .retrieve() .body(String.class); 2. HTTPଓͷྲّྀ
ͲͷڥͰɺͲͷαʔϏεσΟεΧόϦʢ໊લʣΛ͍ͬͯΔ͔ؾʹͯ͠Ͷ Dockerk8sΛ͏Α͠ɺeurekaΛ͏Α͠ɺECS Service ConnectΛ͏Α͠ ࢀߟ: αʔϏεσΟεΧόϦ “serviceB” ͱ͍͏Α͏ͳϗετ໊͔Βɺ࣮ࡍͷIPΞυϨε܈ͳͲΛҾͨ͘ΊͷαʔϏε ಈతʹϨίʔυ͕มΘΔDNSΈ͍ͨͳΜ 2.
HTTPଓͷྲّྀ
ϩʔΧϧڥͷαʔϏεσΟεΧόϦʹͳΔ͜ͱ͕͋ΔͶ ݹདྷΑΓ hosts ϑΝΠϧʹॻ͘ͱ͍͏ྲྀ͕͋Δ ϩʔΧϧڥͰৗʹDocker্Ͱ࣮ߦͯ͠Dockerͷ໊લղܾΛ͏ྲྀ͋Δ͔ ͦΕΑΓ։ൃ࣌αʔϏεBͷϙʔτ൪߸ΛܾΊଧͪͯ͠ ϙʔτࢦఆͰΞΫηεͤͨ͞ํָ͕Ͱ͠ΐɻҟೝΊͳ͍ 2. HTTPଓͷྲّྀ
3. Ωϡʔଓͷྲّྀ
աܹͳͷͰɺ ʮαʔϏεؒͷ௨৴σϑΥϧτඇಉظɻ ɹͦͯ͠ಉظʹ͠ͳ͚ΕͲ͏ͯ͠ࠔΔͱ͜Ζ͚ͩಉظʹ͖͢ʯ ͱ͍͏͕͋Γ·͢ ฏʹʮ͍͠ͷʯʮτϥϒϧ͕ى͖͍͢ͷʯͱ͍͏ΠϝʔδͩͬͨΩϡʔ ྩʹ͓͍͍ͯ͘͢ͳΓɺඪ४උͰ͋Δ 3. Ωϡʔଓͷྲّྀ
ΩϡʔΛ༻͍ͨඇಉظॲཧͰར༻͢Δٕज़ղ Spring Cloud Stream Spring AMQPSpring Ka f kaͳͲ DaprͳͲͷαΠυΧʔ
ࣗͰ࡞ΔϝοηʔδϯάαʔϏε 3. Ωϡʔଓͷྲّྀ
Spring Cloud StreamΛͬͨ߹ 3. Ωϡʔଓͷྲّྀ ΞϓϦέʔγϣϯ1 Spring Cloud Stream Spring
Boot RabbitMQͳͲ ΞϓϦέʔγϣϯ2 Spring Cloud Stream Spring Boot ΤϯΩϡʔ σΩϡʔ
ΩϡʔΛ༻͍ͨඇಉظॲཧʹ͓͍ͯɺSpring Cloud StreamݶΓͳ͘ਖ਼ղʹ͔ۙͬͨ RabbitMQ / Ka f ka / Pulser
/ Google PubSub / Azure Event Hubs / AWS SNS ͳͲ ͍ͬͯΔϛυϧΣΞΛҙࣝͤͣʹ࣮͕Ͱ͖Δʢઃఆ͚ͩͰٵऩͰ͖Δʣ ૹ৴ଆɾड৴ଆ͕ࣗͷؔ৺ࣄͷΈهड़͢Εྑ͍ destination ͱ group Λ༻͍ͨఆ͕ٛඇৗʹ͔Γ͘͢ૉΒ͍͠ 3. Ωϡʔଓͷྲّྀ
ΩϡʔΛ༻͍ͨඇಉظॲཧʹ͓͍ͯɺSpring Cloud StreamݶΓͳ͘ਖ਼ղʹ͔ۙͬͨ Spring Cloud Stream 2.x ͔Β 3.x ʹͳͬͯAPIઃఆ͕͔ΓͮΒ͘ͳͬͨ
Spring CloudϑΝϛϦʔͳͷͰΞοϓσʔτͰّͦ͠͏ͳݒ೦͕͋Δ ʢफ࣍ୈ͕ͩʣݸผͷΞϓϦέʔγϣϯ͕ؔ৺ࣄΛهड़͢Δ͜ͱͰఆٛ͢Δ γεςϜશମͱͯ͠ɺԿ͕Ͳ͜ʹӨڹͯ͠ඇಉظॲཧ͕Δ͔ͷݟ௨͕͠ѱ͍ 3. Ωϡʔଓͷྲّྀ
Spring AMQPΛͬͨ߹ 3. Ωϡʔଓͷྲّྀ ΞϓϦέʔγϣϯ1 Spring AMQP Spring Boot RabbitMQ
ΞϓϦέʔγϣϯ2 Spring AMQP Spring Boot ΤϯΩϡʔ σΩϡʔ
Spring AMQPSpring Ka f kaѱ͘ͳ͍ͷͷɺؾ͕ར͔ͳ͍෦͕͋Δ Spring Cloud StreamʹൺΔͱɺϩʔϨϕϧAPIʹ͍ۙ Spring Cloud
SleuthMicrometer TracingͷτϨʔεID͕ɺσϑΥϧτແޮ ͜ΕΛ։ൃऀΈΜͳʹΘͤΔ͜ͱʹɺׂͱ߅͕͋Δ RabbitMQKa f ka·ͩ͠Amazon SNSΛ͏߹ɺ։ൃڥͰࠔΓ͕ͪ 3. Ωϡʔଓͷྲّྀ
DaprͷΑ͏ͳαΠυΧʔΛ༻͍ͨ߹ 3. Ωϡʔଓͷྲّྀ ΞϓϦέʔγϣϯPod1 αΠυΧʔ ʢDaprͳͲʣ Spring Boot RabbitMQͳͲ HTTP
ΞϓϦέʔγϣϯPod2 αΠυΧʔ ʢDaprͳͲʣ Spring Boot HTTP ΤϯΩϡʔ σΩϡʔ
αΠυΧʔίϯςφΛ༻͍ͨ߹ 3. Ωϡʔଓͷྲّྀ ΞϓϦέʔγϣϯ1 αΠυΧʔίϯςφ Spring Boot RabbitMQͳͲ ΞϓϦέʔγϣϯ2 αΠυΧʔίϯςφ
Spring Boot ΤϯΩϡʔ σΩϡʔ HTTP HTTP
DaprͷΑ͏ͳαΠυΧʔΛ༻͍ͨΈਖ਼ղʹ͍ۙ αΠυΧʔύλʔϯ ΞϓϦέʔγϣϯͱ1:1Ͱಈ࡞͢Δิॿతͳπʔϧ܈ʢαΠυΧʔʣΛར༻͢Δύλʔϯ αΠυΧʔɺ୯ಠϓϩηεʢk8sͳΒpodʹڞଘʣ͋Δ͍ίϯςφͱͯ͠ఏڙ ઌʹڍ໊͛ͨલղܾɺϩʔυόϥϯεɺΩϡʔॲཧɺࢹใૹ৴ͳͲଟ༻్ʹ͑Δ 3. Ωϡʔଓͷྲّྀ
DaprͷΑ͏ͳαΠυΧʔΛ༻͍ͨΈਖ਼ղʹ͍ۙ ΞϓϦέʔγϣϯͱαΠυΧʔHTTP௨৴͔gRPC௨৴͚ͩͰࡁΉ ࣮ͱΠϯϑϥΛϓϩτίϧϨϕϧͰͰ͖Δ ͭ·ΓΞϓϦέʔγϣϯHTTP௨৴͔gRPC௨৴͚ͩΕྑ͍ͱ͍͏͜ͱʹͳΔ 3. Ωϡʔଓͷྲّྀ
DaprͷΑ͏ͳαΠυΧʔΛ༻͍ͨΈਖ਼ղʹ͍ۙ αΠυΧʔϓϩηεࣗମ͕ෆ҆ఆʹͳΔͱɺΞϓϦέʔγϣϯ͕ෆ҆ఆʹͳΔ αΠυΧʔίϯςφͷͨΊͷϦιʔε͕ඞཁ Daprͷ߹ඞવతʹk8sΛલఏͱͨ͠ߏͱͳΔ 3. Ωϡʔଓͷྲّྀ
ࣗͰ࡞ΔϝοηʔδϯάαʔϏεΛ༻͍ͨ߹ 3. Ωϡʔଓͷྲّྀ ΞϓϦέʔγϣϯ1 ϝοηʔδϯάαʔϏε Spring Boot RabbitMQͳͲ ΞϓϦέʔγϣϯ2 Spring
Boot ΤϯΩϡʔ σΩϡʔ HTTP HTTP
ࣗͰϝοηʔδϯάαʔϏεΛ࡞ΔͷҰҰ͕ͩɺݱ࣮ղʹ͍ۙ ΞϓϦέʔγϣϯͱϝοηʔδϯάαʔϏεؒHTTP௨৴ͳͲΛ͑ΔͨΊ ΞϓϦέʔγϣϯͱΠϯϑϥ͕ϓϩτίϧϨϕϧͰͰ͖Δ ΄ͱΜͲͷ։ൃϝϯόʔΩϡʔͱͷతͳ௨৴ॲཧΛॻ͔ͳͯ͘ࡁΉ Spring Cloud StreamΛ෦తʹ࠶࣮͢ΔΑ͏ͳͷʹͳΔͷͰ࣮໘ 3. Ωϡʔଓͷྲّྀ
ͲͷखஈΛબͿ͖͔߹ʹΑΔͱ͔͠ݴ͑ͳ͍͕ ʮΩϡʔΛܦ༝ͤͣͱHTTPܦ༝ͰAPIίʔϧͰ͖ΔΑ͏ʹ͢Δ͖ʯ ͱ͍͏ڧΊʹओு͍ͨ͠ ࣗಈςετͷࡍʹɺΩϡʔΛར༻͢ΔͷͰͳ͘ɺ ड৴ଆͷHTTPΤϯυϙΠϯτʹ௨৴͢ΔΑ͏ͳʹ͢Δ͜ͱͰ ʢຊདྷͷʣඇಉظॲཧͷऴྃΛͨͣʹɺಉظॲཧͱͯ݁͠ՌΛ֬ೝͰ͖ΔͨΊ ςετͷ༰қੑ্͕͢Δ ςετίʔυʹ Thread.sleep(5000); ͱ͔ॻ͔ͳͯ͘ྑ͍ɻ
3. Ωϡʔଓͷྲّྀ
ࣗಈςετͷ࣌ʹݶΓɺಉظ௨৴ʹ͢Δ 3. Ωϡʔଓͷྲّྀ ΞϓϦέʔγϣϯ1 αΠυΧʔίϯςφ Spring Boot RabbitMQͳͲ ΞϓϦέʔγϣϯ2 αΠυΧʔίϯςφ
Spring Boot ΤϯΩϡʔ σΩϡʔ HTTP HTTP ςετ࣌ͷHTTP௨৴ઌ
Spring Cloud StreamSpring AMQPΛ͏߹ͰɺΩϡʔͱͷΤϯυϙΠϯτҎ֎ʹ HTTPΞΫηεͰ͖ΔΤϯυϙΠϯτΛՃ͢Δ @RabbitListener void onPurchase(PurchaseMessage message) //
RabbitMQͷϝοηʔδ @Post(“/purchase”) void purchase(PurchaseEvent event) // ϝοηʔδͷPOJOͷΈ ௨ৗ࣌RabbitTemplateͰΤϯΩϡʔ͢Δ͕ ࣗಈςετ࣌ͷΈ RestClient RestTemplate Ͱ /purchase ʹΞΫηε͢Δ 3. Ωϡʔଓͷྲّྀ
αΠυΧʔΛར༻͢Δ߹ɺࣗ࡞ϝοηʔδϯάαʔϏεΛ͏߹ ࣗಈςετ࣌ʹݶΓHTTPΤϯυϙΠϯτΛม͑Δ͚ͩͰࡁΉ ࣮ͱΠϯϑϥͷΛ͢ΔతͳϝϦοτͰͳ͘ ෭࣍తͳޮՌͰ͋Δ͕ɺςετ༰қੑಈ࡞֬ೝͷΓ্͕͢͢͞Δͷྑ͍ 3. Ωϡʔଓͷྲّྀ
4. DBଓͷྲّྀ
աܹͳͷͰ ʮσʔλϕʔεશମͷΠϯϑϥͰͳ͘ɺΞϓϦέʔγϣϯͷ࣋ͪͰ͋Δʯ ͱ͍͏͕͋Γ·͢ 4. DBଓͷྲّྀ
σʔλϕʔεͷύϒϦοΫΠϝʔδ 4. DBଓͷྲّྀ ΞϓϦέʔγϣϯ1 Spring Boot σʔλετΞ ΞϓϦέʔγϣϯ2 Spring Boot
ΫΤϦ ΫΤϦ
͕࣋ͭσʔλϕʔεͷΠϝʔδ 4. DBଓͷྲّྀ ΞϓϦέʔγϣϯ1 σʔλετΞ Spring Boot ΞϓϦέʔγϣϯ2 σʔλετΞ Spring
Boot ΫΤϦ ΫΤϦ ※͋͘·Ͱந֓೦తͳଊ͑ํͰ͋Γ ɹ࣮ࡍʹΞϓϦέʔγϣϯϓϩηεͱ ɹσʔλετΞͷϓϩηεΛಉډͤ͞Δ ɹΘ͚Ͱ͋Γ·ͤΜ
ϚΠΫϩαʔϏεతͳൃͰσʔλετΞΞϓϦέʔγϣϯͱಉ༷ʹ͞ΕΔ ֎෦͔ΒσʔλετΞʹΞΫηεͤͣɺϚΠΫϩαʔϏεΛܦ༝ͯ͠ΞΫηε͢Δ ͭ·ΓϚΠΫϩαʔϏεͷWeb API͕ͦ͜σʔλͷදݱͰ͋Γ ෦ͷσʔλετΞ࣮Ӆṭ͞Ε͔ͯ͠Δ͖Ͱ͋Δ 4. DBଓͷྲّྀ
Τϥͦ͏ͳ͜ͱΛݴ͍·͕ͨ͠ɺԿΛݴ͍͍͔ͨͱ͍͏ͱ ʮDBΞΫηεΛHTTPͳͲͬͯϓϩτίϧӅṭͨ͠Γ ɹΫΤϦΛHTTP bodyͰදݱ͠Α͏ͱ͢Δͷେม͔ͩΒ ɹΊͱ͜͏ͥʯ ͬͯ͜ͱͰ͢ DaprʹDBΞΫηεػೳ͕͋Δ͕ɺͬͨ͜ͱ͓͏ͱࢥͬͨ͜ͱͳ͍ 4. DBଓͷྲّྀ
DBͱΞϓϦέʔγϣϯྑ͠ɻζο༑ͩϤʂ 4. DBଓͷྲّྀ
5. ΞϓϦέʔγϣϯࢹͷ ྲّྀ
աܹ͚ͩͲ ࢹʹ͍ͭͯʮࢄτϨʔγϯά100%ऩू͢ΔΑͶʯఔͷ͜ͱ͔͠ࢥͬͯ·ͤΜ 5. ΞϓϦέʔγϣϯࢹͷྲّྀ
ΞϓϦέʔγϣϯࢹͷͨΊͷใʢϝτϦΫεɺϩάɺτϨʔεʣͷऩूํ๏ෳ͋Δ Pullܕ - ֎෦ͷαʔϏε͕ऩूʹདྷΔʢPrometheusͳͲʣ Pushܕ ϥΠϒϥϦ - ΞϓϦέʔγϣϯͷϥΠϒϥϦ͕ऩूͯ͠ૹ৴͢ΔʢbraveͳͲʣ ΤʔδΣϯτ -
ΞϓϦέʔγϣϯͱผͷϓϩηεͰऩूͯ͠ૹ৴͢ΔʢAPMͳͲʣ 5. ΞϓϦέʔγϣϯࢹͷྲّྀ
Pullܕ 5. ΞϓϦέʔγϣϯࢹͷྲّྀ ΞϓϦέʔγϣϯ1 micrometer-registry- prometheus Spring Boot Prometheus ΞϓϦέʔγϣϯ2
micrometer-registry- prometheus Spring Boot ऩू ऩू
Pushܕ - ϥΠϒϥϦ 5. ΞϓϦέʔγϣϯࢹͷྲّྀ ΞϓϦέʔγϣϯ1 micrometer-tracing- bridge-brave Spring Boot
Zipkin ΞϓϦέʔγϣϯ2 micrometer-tracing- bridge-brave Spring Boot ૹ৴ ૹ৴
Pushܕ - ΤʔδΣϯτ 5. ΞϓϦέʔγϣϯࢹͷྲّྀ ΞϓϦέʔγϣϯ1 Elastic APM Spring Boot
Zipkin ΞϓϦέʔγϣϯ2 Elastic APM Spring Boot ૹ৴ ૹ৴ ऩू ऩू
࣮ͱΠϯϑϥΛ͢Δͱ͍͏؍ͩͱɺԿ͕ྑ͍ͷ͔ʁ Pullܕ ΞϓϦέʔγϣϯଆʹʮࢹใΛऔಘͰ͖ΔAPIʯΛ༻ҙ͓͚ͯͩ͘͠ ࢹใΛ࣮ࡍʹऩू͢Δ͔Ͳ͏͔ڥʹͤΔ ϝτϦΫεͱϩά͜ͷํ๏͕࠾ΕΔ͕ɺPullܕͷτϨʔεʢΒʣͳ͍ 5. ΞϓϦέʔγϣϯࢹͷྲّྀ
࣮ͱΠϯϑϥΛ͢Δͱ͍͏؍ͩͱɺԿ͕ྑ͍ͷ͔ʁ Pushܕ - ΤʔδΣϯτܕ ࢹ͕ඞཁͳॴʹͷΈΤʔδΣϯτΛద༻͢Εɺ࣮ͱΠϯϑϥ͔ΕΔ ͨͱ͑ϩʔΧϧͷ։ൃڥʹΤʔδΣϯτΛద༻͠ͳͯ͘ྑ͍ ݱ࣮తʹ͜Ε͕ਖ਼ղ Ͱݸਓతʹ͋Μ·Γ͖͡Όͳ͍ 5. ΞϓϦέʔγϣϯࢹͷྲّྀ
࣮ͱΠϯϑϥΛ͢Δͱ͍͏؍ͩͱɺԿ͕ྑ͍ͷ͔ʁ Pushܕ - ϥΠϒϥϦ ΞϓϦέʔγϣϯ֎ʹಠࣗϓϩτίϧͰૹ৴͢Δ ։ൃڥͰૹ৴͠Α͏ͱ͢Δ ͔ͳΓ࣮ͱΠϯϑϥ͕ີͰ͋Δ 5. ΞϓϦέʔγϣϯࢹͷྲّྀ
PushͰ͋ͬͯ֎෦ʹૹ৴͢Δख๏ͱϓϩτίϧ͕ඪ४Խ͞ΕͨͷͰ͋Εྑ͍ͷͰʁ OTLP - OpenTelemetry Protocol ϝτϦΫεɺϩΪϯάɺτϨʔεͱʹOTLPͰૹ͢ΔΈ͋Γ ଟ͘ͷࢹϓϥοτϑΥʔϜ͕OTLPରԠ࢝͠Ί͍ͯΔ Otel CollectorΛར༻͢Εɺ͞ΒʹॊೈʹࢹϓϥοτϑΥʔϜΛબΔ 5.
ΞϓϦέʔγϣϯࢹͷྲّྀ
OTLPΛͬͨ߹ 5. ΞϓϦέʔγϣϯࢹͷྲّྀ ΞϓϦέʔγϣϯ1 micrometer-registry- otlp Spring Boot GrafanaͳͲ ΞϓϦέʔγϣϯ2
micrometer-registry- otlp Spring Boot OTLPૹ৴ OTLPૹ৴
OTLPͱOtel CollectorΛͬͨ߹ 5. ΞϓϦέʔγϣϯࢹͷྲّྀ ΞϓϦέʔγϣϯ1 micrometer-registry- otlp Spring Boot Otel
Collector ΞϓϦέʔγϣϯ2 micrometer-registry- otlp Spring Boot OTLPૹ৴ OTLPૹ৴ DatadogɺAWSͳͲ ҙͷϓϩτίϧ
ࢹ·ͩॊΒ͔͍ͷͰɺঢ়گΛࢹதɻͦͷ͏ͪ͠·͢ 5. ΞϓϦέʔγϣϯࢹͷྲّྀ
·ͱΊɾ࠷ޙʹ
࣮ͱΠϯϑϥΛͤ͞Δ͜ͱͰ ΞϓϦέʔγϣϯଆʹɺڥ͝ͱͷࠩΛهड़͢Δඞཁ͕ͳ͘ͳΔ ࣮ͱΠϯϑϥͷ૬ޓࢀর͕ͳ͘ͳΓɺΠϯϑϥ͔ΒͷҰํ௨ߦʹͳΔ ಛʹ։ൃڥΛɺ֤छϛυϧΣΞίϯςφͳͲΛΘͣʹߏஙͰ͖Δ ӡ༻ڥ͕k8sEKSͰɺ։ൃڥͰk8sAmazon SNSͳͲ͕ඞཁͳ͘ͳΔ RDBMS͘Βཱ͍ͯΔ͚Ͳ ·ͱΊ
࣮ͱΠϯϑϥΛͤ͞Δ͜ͱͰ ςετ͕༰қʹͳΓ͍͢ ΩϡʔΛ༻͍ͨॲཧΛɺHTTPͰݺͼग़ͤΔ ʢผʹ࣮ͱΠϯϑϥΛ͠ͳͯ͘Ͱ͖Δ͜ͱ͚ͩͲɻ෭࣍తͳޮՌʣ ΩϡʔΛ༻͍ͨඇಉظॲཧͰɺHTTPͷಉظॲཧͱͯ͠ςετͰ͖Δ ·ͱΊ
࣮ͱΠϯϑϥΛͤ͞ΔͨΊʹ application.yaml ϩʔΧϧ։ൃڥ͚ͷΈͱ͢Δʢ੍ʣ ͦΕҎ֎ͷڥͰɺڥมΛར༻ͯ͠ઃఆΛ্ॻ͖͢Δ ͦͦʮ࣮ͱΠϯϑϥΛͤ͞Δʯͱ͍͏ڧ͍ҙࢤΛ࣋ͭ ·ͱΊ
࣮ͱΠϯϑϥΛ͢Δํཱ͕ࣜ֬͢Ε ΞϓϦέʔγϣϯ͕ʮWeb APIΛఏڙ͢ΔͷΈʯͱ͍͏ঢ়ଶʹͳΔ ڥʹ͍ͭͯͷؔ৺ࣄ͔ΒΓ͞ΕɺϩδοΫʹྗͰ͖ΔΑ͏ʹͳΔ Spring Bootʹͩ͜ΘΒͣɺͲͷΑ͏ͳϑϨʔϜϫʔΫͰ͑ΔΑ͏ʹͳΔ ͬͱݴ͑ɺͲͷݴޠͰ࣮ͯ͠ߏΘͳ͘ͳΔ ಠཱੑɾ૬ޓӡ༻ੑ͕ߴ͍ঢ়ଶʹͳΔ ࠷ޙʹ