{"id":91552,"date":"2025-10-05T18:01:04","date_gmt":"2025-10-05T11:01:04","guid":{"rendered":"https:\/\/itviec.com\/blog\/?p=91552"},"modified":"2025-10-05T18:01:07","modified_gmt":"2025-10-05T11:01:07","slug":"spring-cloud-la-gi","status":"publish","type":"post","link":"https:\/\/itviec.com\/blog\/spring-cloud-la-gi\/","title":{"rendered":"Spring Cloud: Chi ti\u1ebft c\u00e1ch tri\u1ec3n khai microservices \u0111\u01a1n gi\u1ea3n"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">N\u1ed9i dung b\u00e0i vi\u1ebft<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/itviec.com\/blog\/spring-cloud-la-gi\/#Spring_Cloud_la_gi_va_giai_quyet_van_de_gi\" >Spring Cloud l\u00e0 g\u00ec v\u00e0 gi\u1ea3i quy\u1ebft v\u1ea5n \u0111\u1ec1 g\u00ec?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/itviec.com\/blog\/spring-cloud-la-gi\/#Quan_ly_cau_hinh_tap_trung_voi_Spring_Cloud_Config\" >Qu\u1ea3n l\u00fd c\u1ea5u h\u00ecnh t\u1eadp trung v\u1edbi Spring Cloud Config<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/itviec.com\/blog\/spring-cloud-la-gi\/#Netflix_Eureka_%E2%80%93_Service_Registry_Pattern_cua_Spring_Cloud\" >Netflix Eureka \u2013 Service Registry Pattern c\u1ee7a Spring Cloud<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/itviec.com\/blog\/spring-cloud-la-gi\/#Spring_Cloud_Gateway_%E2%80%93_giai_phap_API_Gateway_cua_Spring\" >Spring Cloud Gateway &#8211; gi\u1ea3i ph\u00e1p API Gateway c\u1ee7a Spring<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/itviec.com\/blog\/spring-cloud-la-gi\/#Spring_Cloud_Circuit_Breaker_%E2%80%93_Tang_cuong_kha_nang_chiu_loi_trong_Microservices\" >Spring Cloud Circuit Breaker &#8211; T\u0103ng c\u01b0\u1eddng kh\u1ea3 n\u0103ng ch\u1ecbu l\u1ed7i trong Microservices<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/itviec.com\/blog\/spring-cloud-la-gi\/#Cac_cau_hoi_thuong_gap_ve_Spring_Cloud\" >C\u00e1c c\u00e2u h\u1ecfi th\u01b0\u1eddng g\u1eb7p v\u1ec1 Spring Cloud<\/a><\/li><\/ul><\/nav><\/div>\n\n<p><strong><em>\u0110\u01b0\u1ee3c x\u00e2y d\u1ef1ng tr\u00ean n\u1ec1n t\u1ea3ng Spring Boot, Spring Cloud kh\u00f4ng ph\u1ea3i l\u00e0 m\u1ed9t framework m\u1edbi m\u00e0 l\u00e0 m\u1ed9t t\u1eadp h\u1ee3p c\u00e1c &#8220;v\u0169 kh\u00ed&#8221; gi\u00fap \u0111\u01a1n gi\u1ea3n h\u00f3a vi\u1ec7c x\u00e2y d\u1ef1ng v\u00e0 tri\u1ec3n khai \u1ee9ng d\u1ee5ng theo ki\u1ebfn tr\u00fac microservices b\u1eb1ng c\u00e1ch cung c\u1ea5p c\u00e1c gi\u1ea3i ph\u00e1p s\u1eb5n c\u00f3 cho nh\u1eefng b\u00e0i to\u00e1n ph\u1ed5 bi\u1ebfn.<\/em><\/strong><\/p>\n\n\n\n<p>\u0110\u1ecdc b\u00e0i vi\u1ebft n\u00e0y \u0111\u1ec3 bi\u1ebft th\u00eam v\u1ec1:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Spring Cloud l\u00e0 g\u00ec? Gi\u00fap l\u1eadp tr\u00ecnh vi\u00ean gi\u1ea3i quy\u1ebft v\u1ea5n \u0111\u1ec1 g\u00ec?<\/li>\n\n\n\n<li>Spring Cloud qu\u1ea3n l\u00fd c\u1ea5u h\u00ecnh t\u1eadp trung nh\u01b0 th\u1ebf n\u00e0o?<\/li>\n\n\n\n<li>T\u00ecm hi\u1ec3u th\u00eam v\u1ec1 D\u1ecbch V\u1ee5 (Service Discovery &amp; Registry)<\/li>\n\n\n\n<li>API Gateway<\/li>\n\n\n\n<li>T\u0103ng c\u01b0\u1eddng kh\u1ea3 n\u0103ng ch\u1ecbu l\u1ed7i<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-spring-cloud-la-gi-va-gi\u1ea3i-quy\u1ebft-v\u1ea5n-d\u1ec1-gi\"><span class=\"ez-toc-section\" id=\"Spring_Cloud_la_gi_va_giai_quyet_van_de_gi\"><\/span><strong>Spring Cloud l\u00e0 g\u00ec v\u00e0 gi\u1ea3i quy\u1ebft v\u1ea5n \u0111\u1ec1 g\u00ec?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-spring-cloud-la-gi\"><strong>Spring Cloud l\u00e0 g\u00ec?<\/strong><\/h3>\n\n\n\n<p><strong>Spring Cloud<\/strong> l\u00e0 m\u1ed9t framework cung c\u1ea5p b\u1ed9 c\u00f4ng c\u1ee5 to\u00e0n di\u1ec7n \u0111\u1ec3 x\u00e2y d\u1ef1ng v\u00e0 v\u1eadn h\u00e0nh c\u00e1c \u1ee9ng d\u1ee5ng theo ki\u1ebfn tr\u00fac microservices. M\u1ee5c ti\u00eau ch\u00ednh c\u1ee7a n\u00f3 l\u00e0 \u0111\u01a1n gi\u1ea3n h\u00f3a s\u1ef1 ph\u1ee9c t\u1ea1p v\u1ed1n c\u00f3 c\u1ee7a c\u00e1c h\u1ec7 th\u1ed1ng ph\u00e2n t\u00e1n b\u1eb1ng c\u00e1ch cung c\u1ea5p c\u00e1c gi\u1ea3i ph\u00e1p \u0111\u00e3 \u0111\u01b0\u1ee3c ki\u1ec3m ch\u1ee9ng cho nh\u1eefng b\u00e0i to\u00e1n ph\u1ed5 bi\u1ebfn. C\u1ee5 th\u1ec3, Spring Cloud cung c\u1ea5p c\u00e1c implementation cho nh\u1eefng design pattern quan tr\u1ecdng nh\u01b0:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Service Discovery (Kh\u00e1m ph\u00e1 d\u1ecbch v\u1ee5)<\/li>\n\n\n\n<li>Centralized Configuration (Qu\u1ea3n l\u00fd c\u1ea5u h\u00ecnh t\u1eadp trung)<\/li>\n\n\n\n<li>Circuit Breakers (C\u01a1 ch\u1ebf ng\u1eaft m\u1ea1ch)<\/li>\n\n\n\n<li>Intelligent Routing (\u0110\u1ecbnh tuy\u1ebfn th\u00f4ng minh)<\/li>\n\n\n\n<li>Distributed Tracing (Truy v\u1ebft ph\u00e2n t\u00e1n)<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-m\u1ed1i-quan-h\u1ec7-v\u1edbi-spring-boot\"><strong>M\u1ed1i quan h\u1ec7 v\u1edbi Spring Boot<\/strong><\/h3>\n\n\n\n<p>M\u1ed1i quan h\u1ec7 v\u00e0 s\u1ef1 ph\u00e2n chia vai tr\u00f2 gi\u1eefa Spring Boot v\u00e0 Spring Cloud r\u1ea5t r\u00f5 r\u00e0ng:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/spring.io\/projects\/spring-boot\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Spring Boot<\/strong><\/a> t\u1eadp trung v\u00e0o vi\u1ec7c \u0111\u01a1n gi\u1ea3n h\u00f3a qu\u00e1 tr\u00ecnh ph\u00e1t tri\u1ec3n v\u00e0 \u0111\u00f3ng g\u00f3i m\u1ed9t <strong>service \u0111\u1ed9c l\u1eadp<\/strong>. N\u00f3 cung c\u1ea5p c\u01a1 ch\u1ebf auto-configuration, qu\u1ea3n l\u00fd dependency v\u00e0 m\u00e1y ch\u1ee7 nh\u00fang (embedded server) \u0111\u1ec3 b\u1ea1n c\u00f3 th\u1ec3 nhanh ch\u00f3ng t\u1ea1o ra m\u1ed9t \u1ee9ng d\u1ee5ng s\u1eb5n s\u00e0ng ch\u1ea1y (production-ready). Ph\u1ea1m vi c\u1ee7a Spring Boot l\u00e0 <em>b\u00ean trong m\u1ed9t <\/em><a href=\"https:\/\/spring.io\/microservices\" target=\"_blank\" rel=\"noreferrer noopener\"><em>microservice<\/em><\/a>.<\/li>\n\n\n\n<li><strong>Spring Cloud<\/strong> gi\u1ea3i quy\u1ebft c\u00e1c v\u1ea5n \u0111\u1ec1 ph\u00e1t sinh khi nhi\u1ec1u service \u0111\u01b0\u1ee3c t\u1ea1o b\u1edfi Spring Boot c\u1ea7n t\u01b0\u01a1ng t\u00e1c v\u1edbi nhau trong m\u1ed9t m\u00f4i tr\u01b0\u1eddng ph\u00e2n t\u00e1n. N\u00f3 cung c\u1ea5p h\u1ea1 t\u1ea7ng v\u00e0 c\u00e1c pattern \u0111\u1ec3 c\u00e1c service n\u00e0y c\u00f3 th\u1ec3 giao ti\u1ebfp, ch\u1ecbu l\u1ed7i v\u00e0 ph\u1ed1i h\u1ee3p m\u1ed9t c\u00e1ch hi\u1ec7u qu\u1ea3. Ph\u1ea1m vi c\u1ee7a Spring Cloud l\u00e0 <em>gi\u1eefa c\u00e1c microservice<\/em>.<\/li>\n<\/ul>\n\n\n\n<p>N\u00f3i m\u1ed9t c\u00e1ch kh\u00e1c, <strong>Spring Boot<\/strong> cho ph\u00e9p b\u1ea1n x\u00e2y d\u1ef1ng c\u00e1c <em>service<\/em>, c\u00f2n <strong>Spring Cloud<\/strong> cung c\u1ea5p n\u1ec1n t\u1ea3ng \u0111\u1ec3 c\u00e1c service \u0111\u00f3 k\u1ebft n\u1ed1i v\u00e0 v\u1eadn h\u00e0nh m\u1ed9t c\u00e1ch tin c\u1eady nh\u01b0 m\u1ed9t <em>h\u1ec7 th\u1ed1ng<\/em> th\u1ed1ng nh\u1ea5t.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><em>\u0110\u1ecdc chi ti\u1ebft: <strong><a href=\"https:\/\/itviec.com\/blog\/spring-boot-la-gi\/\" target=\"_blank\" rel=\"noreferrer noopener\">Spring Boot l\u00e0 g\u00ec: Chi ti\u1ebft c\u00e1ch x\u00e2y d\u1ef1ng \u1ee9ng d\u1ee5ng v\u1edbi Spring Boot<\/a><\/strong><\/em><\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-t\u1ea1i-sao-spring-cloud-h\u1ed7-tr\u1ee3-d\u1eafc-l\u1ef1c-cho-qua-trinh-chuy\u1ec3n-d\u1ed5i-sang-microservice\"><strong>T\u1ea1i sao Spring Cloud h\u1ed7 tr\u1ee3 \u0111\u1eafc l\u1ef1c cho qu\u00e1 tr\u00ecnh chuy\u1ec3n \u0111\u1ed5i sang microservice?<\/strong><\/h3>\n\n\n\n<p><strong>Ki\u1ebfn tr\u00fac microservices<\/strong> l\u00e0 m\u1ed9t m\u00f4 h\u00ecnh ki\u1ebfn tr\u00fac ph\u1ea7n m\u1ec1m, trong \u0111\u00f3 m\u1ed9t \u1ee9ng d\u1ee5ng \u0111\u01b0\u1ee3c c\u1ea5u th\u00e0nh t\u1eeb m\u1ed9t t\u1eadp h\u1ee3p c\u00e1c d\u1ecbch v\u1ee5 (services) nh\u1ecf, \u0111\u1ed9c l\u1eadp v\u00e0 c\u00f3 kh\u1ea3-n\u0103ng-tri\u1ec3n-khai-\u0111\u1ed9c-l\u1eadp (independently deployable). M\u1ed7i service th\u01b0\u1eddng \u0111\u01b0\u1ee3c x\u00e2y d\u1ef1ng xoay quanh m\u1ed9t nghi\u1ec7p v\u1ee5 (business capability), ch\u1ea1y trong ti\u1ebfn tr\u00ecnh ri\u00eang v\u00e0 giao ti\u1ebfp v\u1edbi c\u00e1c service kh\u00e1c th\u00f4ng qua c\u00e1c API \u0111\u01b0\u1ee3c \u0111\u1ecbnh ngh\u0129a r\u00f5 r\u00e0ng, th\u01b0\u1eddng l\u00e0 qua giao th\u1ee9c HTTP\/REST ho\u1eb7c gRPC.<\/p>\n\n\n\n<p>M\u00f4 h\u00ecnh n\u00e0y \u0111\u1ed1i l\u1eadp v\u1edbi <strong>ki\u1ebfn tr\u00fac Monolithic (nguy\u00ean kh\u1ed1i)<\/strong>, n\u01a1i m\u00e0 t\u1ea5t c\u1ea3 c\u00e1c th\u00e0nh ph\u1ea7n ch\u1ee9c n\u0103ng \u0111\u01b0\u1ee3c \u0111\u00f3ng g\u00f3i v\u00e0 tri\u1ec3n khai nh\u01b0 m\u1ed9t \u0111\u01a1n v\u1ecb duy nh\u1ea5t. Trong khi Monolithic \u0111\u01a1n gi\u1ea3n h\u01a1n v\u1ec1 m\u1eb7t v\u1eadn h\u00e0nh ban \u0111\u1ea7u, n\u00f3 b\u1ed9c l\u1ed9 nhi\u1ec1u nh\u01b0\u1ee3c \u0111i\u1ec3m khi h\u1ec7 th\u1ed1ng ph\u00e1t tri\u1ec3n v\u1ec1 quy m\u00f4 v\u00e0 \u0111\u1ed9 ph\u1ee9c t\u1ea1p, ch\u1eb3ng h\u1ea1n nh\u01b0:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Kh\u00f3 m\u1edf r\u1ed9ng:<\/strong> Ph\u1ea3i nh\u00e2n b\u1ea3n to\u00e0n b\u1ed9 \u1ee9ng d\u1ee5ng thay v\u00ec ch\u1ec9 m\u1edf r\u1ed9ng th\u00e0nh ph\u1ea7n \u0111ang ch\u1ecbu t\u1ea3i cao.<\/li>\n\n\n\n<li><strong>R\u00e0ng bu\u1ed9c c\u00f4ng ngh\u1ec7 :<\/strong> Kh\u00f3 \u00e1p d\u1ee5ng c\u00f4ng ngh\u1ec7 m\u1edbi cho m\u1ed9t ph\u1ea7n c\u1ee7a h\u1ec7 th\u1ed1ng.<\/li>\n\n\n\n<li><strong>Thi\u1ebfu kh\u1ea3 n\u0103ng ph\u1ee5c h\u1ed3i: <\/strong>&nbsp;L\u1ed7i \u1edf m\u1ed9t module c\u00f3 th\u1ec3 l\u00e0m s\u1eadp to\u00e0n b\u1ed9 \u1ee9ng d\u1ee5ng.<\/li>\n\n\n\n<li><strong>Chu tr\u00ecnh ph\u00e1t tri\u1ec3n ch\u1eadm:<\/strong> M\u1ecdi thay \u0111\u1ed5i nh\u1ecf \u0111\u1ec1u y\u00eau c\u1ea7u build v\u00e0 tri\u1ec3n khai l\u1ea1i to\u00e0n b\u1ed9 kh\u1ed1i \u1ee9ng d\u1ee5ng l\u1edbn.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"640\" src=\"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/09\/image-51.png\" alt=\"\" class=\"wp-image-91553\" srcset=\"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/09\/image-51.png 800w, https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/09\/image-51-300x240.png 300w, https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/09\/image-51-640x512.png 640w, https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/09\/image-51-200x160.png 200w, https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/09\/image-51-768x614.png 768w, https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/09\/image-51-1536x1229.png 1536w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-cac-v\u1ea5n-d\u1ec1-phat-sinh-ma-spring-cloud-gi\u1ea3i-quy\u1ebft\"><strong>C\u00e1c v\u1ea5n \u0111\u1ec1 ph\u00e1t sinh m\u00e0 Spring Cloud gi\u1ea3i quy\u1ebft<\/strong><\/h3>\n\n\n\n<p>Khi chia t\u00e1ch m\u1ed9t \u1ee9ng d\u1ee5ng nguy\u00ean kh\u1ed1i th\u00e0nh c\u00e1c microservice, ch\u00fang ta ph\u1ea3i gi\u1ea3i quy\u1ebft c\u00e1c v\u1ea5n \u0111\u1ec1 ph\u1ee9c t\u1ea1p v\u1ec1 t\u01b0\u01a1ng t\u00e1c v\u00e0 v\u1eadn h\u00e0nh gi\u1eefa c\u00e1c service n\u00e0y.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Service Discovery (\u0110\u1ed9 ph\u00e2n gi\u1ea3i v\u1ecb tr\u00ed d\u1ecbch v\u1ee5):<\/strong> Trong m\u1ed9t m\u00f4i tr\u01b0\u1eddng linh ho\u1ea1t nh\u01b0 Cloud ho\u1eb7c containerized (Docker\/Kubernetes), c\u00e1c instance c\u1ee7a service \u0111\u01b0\u1ee3c t\u1ea1o ra v\u00e0 h\u1ee7y \u0111i m\u1ed9t c\u00e1ch t\u1ef1 \u0111\u1ed9ng. \u0110\u1ecba ch\u1ec9 IP v\u00e0 port c\u1ee7a ch\u00fang l\u00e0 \u0111\u1ed9ng v\u00e0 kh\u00f4ng c\u1ed1 \u0111\u1ecbnh. V\u1eady l\u00e0m th\u1ebf n\u00e0o m\u1ed9t service client c\u00f3 th\u1ec3 t\u00ecm ra \u0111\u01b0\u1ee3c \u0111\u1ecba ch\u1ec9 m\u1ea1ng (network location) ch\u00ednh x\u00e1c c\u1ee7a m\u1ed9t service m\u00e0 n\u00f3 c\u1ea7n g\u1ecdi t\u1ea1i m\u1ed9t th\u1eddi \u0111i\u1ec3m b\u1ea5t k\u1ef3?<\/li>\n\n\n\n<li><strong>Externalized Configuration (Ngo\u1ea1i vi h\u00f3a c\u1ea5u h\u00ecnh):<\/strong> M\u1ed7i service c\u1ea7n c\u00e1c th\u00f4ng tin c\u1ea5u h\u00ecnh nh\u01b0 chu\u1ed7i k\u1ebft n\u1ed1i database, credentials, \u0111\u1ecba ch\u1ec9 c\u1ee7a c\u00e1c d\u1ecbch v\u1ee5 kh\u00e1c, feature flags&#8230; Qu\u1ea3n l\u00fd c\u00e1c file c\u1ea5u h\u00ecnh n\u00e0y ph\u00e2n t\u00e1n \u1edf t\u1eebng service l\u00e0 m\u1ed9t c\u01a1n \u00e1c m\u1ed9ng. Khi m\u1ed9t thu\u1ed9c t\u00ednh chung (v\u00ed d\u1ee5: m\u1eadt kh\u1ea9u database) thay \u0111\u1ed5i, l\u00e0m th\u1ebf n\u00e0o \u0111\u1ec3 c\u1eadp nh\u1eadt cho h\u00e0ng ch\u1ee5c service m\u1ed9t c\u00e1ch \u0111\u1ed3ng b\u1ed9 m\u00e0 kh\u00f4ng c\u1ea7n ph\u1ea3i restart l\u1ea1i to\u00e0n b\u1ed9?<\/li>\n\n\n\n<li><strong>Fault Tolerance (Kh\u1ea3 n\u0103ng ch\u1ecbu l\u1ed7i v\u00e0 ch\u1ed1ng l\u1ed7i d\u00e2y chuy\u1ec1n):<\/strong> Trong m\u1ed9t h\u1ec7 th\u1ed1ng ph\u00e2n t\u00e1n, l\u1ed7i m\u1ea1ng ho\u1eb7c m\u1ed9t service b\u1ecb qu\u00e1 t\u1ea3i\/s\u1eadp l\u00e0 \u0111i\u1ec1u kh\u00f4ng th\u1ec3 tr\u00e1nh kh\u1ecfi. M\u1ed9t l\u1eddi g\u1ecdi t\u1eeb service A \u0111\u1ebfn service B b\u1ecb treo c\u00f3 th\u1ec3 l\u00e0m c\u1ea1n ki\u1ec7t t\u00e0i nguy\u00ean (thread pool) c\u1ee7a A. N\u1ebfu nhi\u1ec1u service c\u00f9ng g\u1ecdi \u0111\u1ebfn B, s\u1ef1 c\u1ed1 c\u1ee7a B c\u00f3 th\u1ec3 lan truy\u1ec1n v\u00e0 g\u00e2y ra <strong>l\u1ed7i d\u00e2y chuy\u1ec1n (cascading failure)<\/strong>, l\u00e0m s\u1eadp c\u1ea3 m\u1ed9t ph\u1ea7n ho\u1eb7c to\u00e0n b\u1ed9 h\u1ec7 th\u1ed1ng.<\/li>\n\n\n\n<li><strong>API Gateway:<\/strong> Vi\u1ec7c public h\u00e0ng ch\u1ee5c endpoint c\u1ee7a c\u00e1c microservice ra b\u00ean ngo\u00e0i cho client (web, mobile) l\u00e0 kh\u00f4ng th\u1ef1c t\u1ebf v\u00e0 thi\u1ebfu an to\u00e0n. C\u1ea7n m\u1ed9t \u0111i\u1ec3m v\u00e0o (entry point) duy nh\u1ea5t \u0111\u1ec3 x\u1eed l\u00fd c\u00e1c t\u00e1c v\u1ee5 chung (cross-cutting concerns) nh\u01b0 <strong>x\u00e1c th\u1ef1c (authentication), gi\u1edbi h\u1ea1n truy c\u1eadp (rate limiting), gi\u00e1m s\u00e1t (monitoring), v\u00e0 \u0111\u1ecbnh tuy\u1ebfn (routing)<\/strong> c\u00e1c request \u0111\u1ebfn \u0111\u00fang service n\u1ed9i b\u1ed9.<\/li>\n\n\n\n<li><strong>C\u00e2n b\u1eb1ng t\u1ea3i ph\u00eda :<\/strong> \u0110\u1ec3 \u0111\u1ea3m b\u1ea3o t\u00ednh s\u1eb5n s\u00e0ng cao (high availability), m\u1ed7i service th\u01b0\u1eddng ch\u1ea1y nhi\u1ec1u instance. Khi service A g\u1ecdi service B, l\u00e0m th\u1ebf n\u00e0o n\u00f3 c\u00f3 th\u1ec3 ph\u00e2n ph\u1ed1i c\u00e1c y\u00eau c\u1ea7u m\u1ed9t c\u00e1ch th\u00f4ng minh qua c\u00e1c instance c\u1ee7a B \u0111\u1ec3 tr\u00e1nh t\u00ecnh tr\u1ea1ng m\u1ed9t instance b\u1ecb qu\u00e1 t\u1ea3i trong khi c\u00e1c instance kh\u00e1c l\u1ea1i \u0111ang r\u1ea3nh r\u1ed7i?<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-spring-cloud-gi\u1ea3i-quy\u1ebft-cac-v\u1ea5n-d\u1ec1-nay-nh\u01b0-th\u1ebf-nao\"><strong>Spring Cloud gi\u1ea3i quy\u1ebft c\u00e1c v\u1ea5n \u0111\u1ec1 n\u00e0y nh\u01b0 th\u1ebf n\u00e0o?<\/strong><\/h3>\n\n\n\n<p>Spring Cloud cung c\u1ea5p m\u1ed9t b\u1ed9 c\u00e1c project \u0111\u01b0\u1ee3c x\u00e2y d\u1ef1ng d\u1ef1a tr\u00ean h\u1ec7 sinh th\u00e1i Spring Boot \u0111\u1ec3 \u0111\u01b0a ra c\u00e1c gi\u1ea3i ph\u00e1p \u0111\u00e3 \u0111\u01b0\u1ee3c chu\u1ea9n h\u00f3a cho nh\u1eefng th\u00e1ch th\u1ee9c tr\u00ean.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Th\u00e1ch th\u1ee9c K\u1ef9 thu\u1eadt<\/strong><\/td><td><strong>Gi\u1ea3i ph\u00e1p c\u1ee7a Spring Cloud<\/strong><\/td><td><strong>C\u01a1 ch\u1ebf ho\u1ea1t \u0111\u1ed9ng<\/strong><\/td><\/tr><tr><td>\u0110\u1ed9 ph\u00e2n gi\u1ea3i v\u1ecb tr\u00ed d\u1ecbch v\u1ee5<\/td><td><a href=\"https:\/\/cloud.spring.io\/spring-cloud-netflix\/reference\/html\/\" target=\"_blank\" rel=\"noreferrer noopener\">Spring Cloud Netflix Eureka<\/a><\/td><td>Cung c\u1ea5p m\u1ed9t <strong>Service Registry<\/strong>. M\u1ed7i microservice khi kh\u1edfi \u0111\u1ed9ng s\u1ebd \u0111\u0103ng k\u00fd (register) th\u00f4ng tin \u0111\u1ecba ch\u1ec9 m\u1ea1ng c\u1ee7a n\u00f3 v\u1edbi Eureka Server v\u00e0 g\u1eedi c\u00e1c t\u00edn hi\u1ec7u &#8220;heartbeat&#8221; \u0111\u1ecbnh k\u1ef3. C\u00e1c service client s\u1ebd truy v\u1ea5n (query) Eureka Server \u0111\u1ec3 l\u1ea5y danh s\u00e1ch c\u00e1c instance \u0111ang ho\u1ea1t \u0111\u1ed9ng c\u1ee7a service m\u00e0 n\u00f3 c\u1ea7n g\u1ecdi.<\/td><\/tr><tr><td>Ngo\u1ea1i vi h\u00f3a c\u1ea5u h\u00ecnh<\/td><td><a href=\"https:\/\/docs.spring.io\/spring-cloud-config\/docs\/current\/reference\/html\/\" target=\"_blank\" rel=\"noreferrer noopener\">Spring Cloud Config<\/a><\/td><td>Cung c\u1ea5p m\u1ed9t <strong>Config Server<\/strong> qu\u1ea3n l\u00fd c\u1ea5u h\u00ecnh t\u1eadp trung, th\u01b0\u1eddng \u0111\u01b0\u1ee3c sao l\u01b0u b\u1edfi m\u1ed9t Git repository. C\u00e1c microservice tr\u1edf th\u00e0nh client, l\u1ea5y c\u1ea5u h\u00ecnh t\u1eeb Config Server khi kh\u1edfi \u0111\u1ed9ng v\u00e0 c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c c\u1ea5u h\u00ecnh \u0111\u1ec3 t\u1ef1 \u0111\u1ed9ng l\u00e0m m\u1edbi (refresh) c\u00e1c thu\u1ed9c t\u00ednh m\u00e0 kh\u00f4ng c\u1ea7n kh\u1edfi \u0111\u1ed9ng l\u1ea1i.<\/td><\/tr><tr><td>Kh\u1ea3 n\u0103ng ch\u1ecbu l\u1ed7i v\u00e0 ch\u1ed1ng l\u1ed7i d\u00e2y chuy\u1ec1n<\/td><td><a href=\"https:\/\/spring.io\/projects\/spring-cloud-circuitbreaker\" target=\"_blank\" rel=\"noreferrer noopener\">Spring Cloud Circuit Breaker (v\u1edbi Resilience4j)<\/a><\/td><td>Tri\u1ec3n khai <strong>m\u00f4 h\u00ecnh Circuit Breaker<\/strong>. N\u00f3 bao b\u1ecdc c\u00e1c l\u1eddi g\u1ecdi m\u1ea1ng trong m\u1ed9t state machine (CLOSED, OPEN, HALF-OPEN). Khi s\u1ed1 l\u01b0\u1ee3ng l\u1ed7i v\u01b0\u1ee3t ng\u01b0\u1ee1ng, breaker s\u1ebd &#8220;m\u1edf&#8221; (OPEN), c\u00e1c l\u1eddi g\u1ecdi sau \u0111\u00f3 s\u1ebd th\u1ea5t b\u1ea1i ngay l\u1eadp t\u1ee9c (fail-fast) thay v\u00ec c\u1ed1 g\u1eafng k\u1ebft n\u1ed1i \u0111\u1ebfn service \u0111ang l\u1ed7i, \u0111\u1ed3ng th\u1eddi cung c\u1ea5p m\u1ed9t ph\u01b0\u01a1ng \u00e1n d\u1ef1 ph\u00f2ng (fallback).<\/td><\/tr><tr><td>API Gateway<\/td><td><a href=\"https:\/\/spring.io\/projects\/spring-cloud-gateway\" target=\"_blank\" rel=\"noreferrer noopener\">Spring Cloud Gateway<\/a><\/td><td>\u0110\u00f3ng vai tr\u00f2 l\u00e0 m\u1ed9t <strong>Reverse Proxy<\/strong> v\u00e0 API Gateway. N\u00f3 \u0111\u1ecbnh ngh\u0129a c\u00e1c <strong>routes<\/strong> \u0111\u1ec3 \u00e1nh x\u1ea1 request t\u1eeb client t\u1edbi c\u00e1c microservice t\u01b0\u01a1ng \u1ee9ng d\u1ef1a tr\u00ean c\u00e1c \u0111i\u1ec1u ki\u1ec7n (predicates) nh\u01b0 \u0111\u01b0\u1eddng d\u1eabn, header&#8230; Gateway c\u0169ng \u00e1p d\u1ee5ng c\u00e1c <strong>filters<\/strong> \u0111\u1ec3 x\u1eed l\u00fd c\u00e1c t\u00e1c v\u1ee5 cross-cutting concerns.<\/td><\/tr><tr><td>C\u00e2n b\u1eb1ng t\u1ea3i<\/td><td><a href=\"https:\/\/spring.io\/guides\/gs\/spring-cloud-loadbalancer\" target=\"_blank\" rel=\"noreferrer noopener\">Spring Cloud LoadBalancer<\/a><\/td><td>Cung c\u1ea5p m\u1ed9t c\u01a1 ch\u1ebf <strong>Client-Side Load Balancing<\/strong>. Khi \u0111\u01b0\u1ee3c t\u00edch h\u1ee3p v\u1edbi service discovery (nh\u01b0 Eureka), n\u00f3 s\u1ebd l\u1ea5y danh s\u00e1ch c\u00e1c instance c\u00f3 s\u1eb5n v\u00e0 \u00e1p d\u1ee5ng m\u1ed9t thu\u1eadt to\u00e1n (v\u00ed d\u1ee5: Round Robin) \u0111\u1ec3 ch\u1ecdn ra m\u1ed9t instance cho m\u1ed7i request, ph\u00e2n ph\u1ed1i \u0111\u1ec1u t\u1ea3i tr\u1ecdng.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>B\u00e2y gi\u1edd h\u00e3y c\u00f9ng t\u00ecm hi\u1ec3u chi ti\u1ebft v\u1ec1 t\u1eebng t\u00ednh n\u0103ng trong Spring Cloud nh\u00e9.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-qu\u1ea3n-ly-c\u1ea5u-hinh-t\u1eadp-trung-v\u1edbi-spring-cloud-config\"><span class=\"ez-toc-section\" id=\"Quan_ly_cau_hinh_tap_trung_voi_Spring_Cloud_Config\"><\/span><strong>Qu\u1ea3n l\u00fd c\u1ea5u h\u00ecnh t\u1eadp trung v\u1edbi Spring Cloud Config<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-v\u1ea5n-d\u1ec1-nbsp\"><strong>V\u1ea5n \u0111\u1ec1:&nbsp;<\/strong><\/h3>\n\n\n\n<p>H\u00e3y t\u01b0\u1edfng t\u01b0\u1ee3ng h\u1ec7 th\u1ed1ng c\u1ee7a b\u1ea1n c\u00f3 20 microservices. M\u1ed7i service l\u1ea1i c\u00f3 m\u1ed9t file application.yml ch\u1ee9a c\u00e1c c\u1ea5u h\u00ecnh nh\u01b0:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Chu\u1ed7i k\u1ebft n\u1ed1i database<\/li>\n\n\n\n<li>\u0110\u1ecba ch\u1ec9 c\u1ee7a message broker (Kafka\/RabbitMQ)<\/li>\n\n\n\n<li>Credentials c\u1ee7a c\u00e1c d\u1ecbch v\u1ee5 b\u00ean th\u1ee9 ba<\/li>\n\n\n\n<li>C\u00e1c feature flag \u0111\u1ec3 b\u1eadt\/t\u1eaft t\u00ednh n\u0103ng<\/li>\n<\/ul>\n\n\n\n<p>Khi m\u1ed9t th\u00f4ng tin chung thay \u0111\u1ed5i, v\u00ed d\u1ee5 nh\u01b0 b\u1ea1n c\u1ea7n \u0111\u1ed5i m\u1eadt kh\u1ea9u c\u1ee7a database. Quy tr\u00ecnh &#8220;th\u1ee7 c\u00f4ng&#8221; s\u1ebd l\u00e0:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>M\u1edf project c\u1ee7a t\u1eebng service.<\/li>\n\n\n\n<li>S\u1eeda l\u1ea1i gi\u00e1 tr\u1ecb trong file <code>application.yml<\/code>.<\/li>\n\n\n\n<li>Build l\u1ea1i file <code>.jar<\/code>.<\/li>\n\n\n\n<li>Tri\u1ec3n khai (deploy) l\u1ea1i c\u1ea3 20 service.<\/li>\n<\/ol>\n\n\n\n<p>Quy tr\u00ecnh n\u00e0y kh\u00f4ng ch\u1ec9 t\u1ed1n th\u1eddi gian, c\u00f4ng s\u1ee9c m\u00e0 c\u00f2n ti\u1ec1m \u1ea9n r\u1ee7i ro sai s\u00f3t. Vi\u1ec7c qu\u1ea3n l\u00fd c\u00e1c th\u00f4ng tin nh\u1ea1y c\u1ea3m (secrets) trong code c\u0169ng l\u00e0 m\u1ed9t h\u00e0nh vi vi ph\u1ea1m b\u1ea3o m\u1eadt.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-gi\u1ea3i-phap-spring-cloud-config-server\"><strong>Gi\u1ea3i ph\u00e1p: Spring Cloud Config Server<\/strong><\/h3>\n\n\n\n<p>Spring Cloud Config cung c\u1ea5p m\u1ed9t gi\u1ea3i ph\u00e1p thanh l\u1ecbch cho b\u00e0i to\u00e1n n\u00e0y. N\u00f3 ho\u1ea1t \u0111\u1ed9ng theo m\u00f4 h\u00ecnh client-server:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Config Server:<\/strong> L\u00e0 m\u1ed9t service trung t\u00e2m, c\u00f3 nhi\u1ec7m v\u1ee5 duy nh\u1ea5t l\u00e0 \u0111\u1ecdc c\u00e1c file c\u1ea5u h\u00ecnh t\u1eeb m\u1ed9t ngu\u1ed3n (backend) v\u00e0 cung c\u1ea5p ch\u00fang qua API. Ngu\u1ed3n backend ph\u1ed5 bi\u1ebfn nh\u1ea5t l\u00e0 m\u1ed9t Git repository.<\/li>\n\n\n\n<li><strong>Config Client:<\/strong> L\u00e0 c\u00e1c microservice c\u1ee7a b\u1ea1n. Thay v\u00ec \u0111\u1ecdc file application.yml \u1edf local, khi kh\u1edfi \u0111\u1ed9ng, ch\u00fang s\u1ebd &#8220;h\u1ecfi&#8221; Config Server \u0111\u1ec3 l\u1ea5y c\u1ea5u h\u00ecnh c\u1ee7a m\u00ecnh.<\/li>\n<\/ul>\n\n\n\n<p>M\u00f4 h\u00ecnh n\u00e0y gi\u00fap <strong>t\u00e1ch bi\u1ec7t ho\u00e0n to\u00e0n c\u1ea5u h\u00ecnh ra kh\u1ecfi m\u00e3 ngu\u1ed3n<\/strong>, cho ph\u00e9p b\u1ea1n thay \u0111\u1ed5i c\u1ea5u h\u00ecnh m\u00e0 kh\u00f4ng c\u1ea7n ph\u1ea3i build hay tri\u1ec3n khai l\u1ea1i \u1ee9ng d\u1ee5ng.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-h\u01b0\u1edbng-d\u1eabn-th\u1ef1c-hanh\"><strong>H\u01b0\u1edbng d\u1eabn th\u1ef1c h\u00e0nh<\/strong><\/h3>\n\n\n\n<p>Ch\u00fang ta s\u1ebd x\u00e2y d\u1ef1ng m\u1ed9t v\u00ed d\u1ee5 \u0111\u01a1n gi\u1ea3n g\u1ed3m 1 Config Server v\u00e0 1 Config Client.<\/p>\n\n\n\n<p><strong>Y\u00eau c\u1ea7u:<\/strong> Chu\u1ea9n b\u1ecb m\u1ed9t Git repository (tr\u00ean GitHub, GitLab,&#8230;) ch\u1ee9a c\u00e1c file c\u1ea5u h\u00ecnh. V\u00ed d\u1ee5, t\u1ea1o m\u1ed9t repo c\u00f3 c\u1ea5u tr\u00fac:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/my-configs\n\u251c\u2500\u2500 application.yml\n\u2514\u2500\u2500 order-service.yml<\/code><\/pre>\n\n\n\n<p>N\u1ed9i dung file <code>application.yml<\/code> (c\u1ea5u h\u00ecnh chung):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>common:\n  message: \"Hello from default config!\"<\/code><\/pre>\n\n\n\n<p>N\u1ed9i dung file <code>order-service.yml<\/code> (c\u1ea5u h\u00ecnh ri\u00eang cho order-service):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>order:\n  discount:\n    percentage: 15<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-cai-d\u1eb7t-config-server\"><strong>C\u00e0i \u0111\u1eb7t Config Server<\/strong><\/h4>\n\n\n\n<p>\u0110\u00e2y l\u00e0 m\u1ed9t Spring Boot application \u0111\u1ed9c l\u1eadp.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Th\u00eam Dependencies (<code>pom.xml<\/code>):<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;dependencies&gt;\n    &lt;dependency&gt;\n        &lt;groupId&gt;org.springframework.cloud&lt;\/groupId&gt;\n        &lt;artifactId&gt;spring-cloud-config-server&lt;\/artifactId&gt;\n    &lt;\/dependency&gt;\n    &lt;dependency&gt;\n        &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n        &lt;artifactId&gt;spring-boot-starter-web&lt;\/artifactId&gt;\n    &lt;\/dependency&gt;\n&lt;\/dependencies&gt;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>K\u00edch ho\u1ea1t Config Server:<\/strong> Th\u00eam annotation <code>@EnableConfigServer<\/code> v\u00e0o class Application ch\u00ednh.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>@SpringBootApplication\n@EnableConfigServer\npublic class ConfigServerApplication {\n    public static void main(String&#91;] args) {\n        SpringApplication.run(ConfigServerApplication.class, args);\n    }\n}<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>C\u1ea5u h\u00ecnh Server (<code>application.yml<\/code>):<\/strong> File n\u00e0y ch\u1ec9 \u0111\u1ecbnh port cho server v\u00e0 \u0111\u01b0\u1eddng d\u1eabn \u0111\u1ebfn Git repository ch\u1ee9a c\u1ea5u h\u00ecnh.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>server:\n  port: 8888 # Port m\u1eb7c \u0111\u1ecbnh cho config server\n\nspring:\n  cloud:\n    config:\n      server:\n        git:\n          uri: https:\/\/github.com\/your-username\/my-configs.git # Thay b\u1eb1ng URI repo c\u1ee7a b\u1ea1n\n          # clone-on-start: true # (Optional) K\u00e9o repo v\u1ec1 ngay khi kh\u1edfi \u0111\u1ed9ng<\/code><\/pre>\n\n\n\n<p>B\u00e2y gi\u1edd, h\u00e3y kh\u1edfi ch\u1ea1y Config Server. B\u1ea1n c\u00f3 th\u1ec3 ki\u1ec3m tra b\u1eb1ng c\u00e1ch truy c\u1eadp <code>http:\/\/localhost:8888\/order-service\/default<\/code>. B\u1ea1n s\u1ebd th\u1ea5y m\u1ed9t JSON tr\u1ea3 v\u1ec1 ch\u1ee9a n\u1ed9i dung c\u1ee7a c\u1ea3 2 file <code>application.yml<\/code> v\u00e0 <code>order-service.yml<\/code>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-c\u1ea5u-hinh-config-client\"><strong>C\u1ea5u h\u00ecnh Config Client<\/strong><\/h4>\n\n\n\n<p>\u0110\u00e2y l\u00e0 microservice <code>order-service<\/code>.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Th\u00eam Dependencies (<code>pom.xml<\/code>):<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;dependencies&gt;\n    &lt;dependency&gt;\n        &lt;groupId&gt;org.springframework.cloud&lt;\/groupId&gt;\n        &lt;artifactId&gt;spring-cloud-starter-config&lt;\/artifactId&gt;\n    &lt;\/dependency&gt;\n    &lt;dependency&gt;\n        &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n        &lt;artifactId&gt;spring-boot-starter-web&lt;\/artifactId&gt;\n    &lt;\/dependency&gt;\n&lt;\/dependencies&gt;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>C\u1ea5u h\u00ecnh Bootstrap:<\/strong>&nbsp;<\/li>\n<\/ul>\n\n\n\n<p>\u0110\u1ec3 client bi\u1ebft \u0111\u1ecba ch\u1ec9 Config Server <strong>ngay khi b\u1eaft \u0111\u1ea7u kh\u1edfi \u0111\u1ed9ng<\/strong>, ch\u00fang ta c\u1ea7n t\u1ea1o m\u1ed9t file <code>src\/main\/resources\/bootstrap.yml<\/code> (thay v\u00ec <code>application.yml<\/code>).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>spring:\n  application:\n    name: order-service # T\u00ean n\u00e0y ph\u1ea3i tr\u00f9ng v\u1edbi t\u00ean file c\u1ea5u h\u00ecnh trong repo Git\n  cloud:\n    config:\n      uri: http:\/\/localhost:8888 # \u0110\u1ecba ch\u1ec9 c\u1ee7a Config Server<\/code><\/pre>\n\n\n\n<p>L\u01b0u \u00fd: <code>spring.application.name<\/code> r\u1ea5t quan tr\u1ecdng, Config Server s\u1ebd d\u1ef1a v\u00e0o t\u00ean n\u00e0y \u0111\u1ec3 t\u00ecm file c\u1ea5u h\u00ecnh t\u01b0\u01a1ng \u1ee9ng (<code>order-service.yml<\/code>).<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>C\u1ea5u h\u00ecnh Client:<\/strong><\/li>\n<\/ul>\n\n\n\n<p>Th\u00eam dependency <code>spring-boot-starter-actuator<\/code>.<\/p>\n\n\n\n<p>Trong <code>application.yml<\/code> c\u1ee7a <code>order-service<\/code>, th\u00eam d\u00f2ng sau \u0111\u1ec3 expose endpoint <code>refresh<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>management:\n  endpoints:\n    web:\n      exposure:\n        include: \"refresh\"<\/code><\/pre>\n\n\n\n<p>Th\u00eam annotation <code>@RefreshScope<\/code> v\u00e0o class Controller. Annotation n\u00e0y b\u00e1o cho Spring bi\u1ebft r\u1eb1ng bean n\u00e0y c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c t\u1ea1o l\u1ea1i khi c\u00f3 s\u1ef1 ki\u1ec7n refresh.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@RestController\n@RefreshScope \/\/ R\u1ea5t quan tr\u1ecdng!\npublic class ConfigController {\n    \/\/ ... n\u1ed9i dung nh\u01b0 c\u0169\n}<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Quy tr\u00ecnh Refresh:<\/strong><\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Ch\u1ea1y c\u1ea3 Config Server v\u00e0 order-service. Truy c\u1eadp http:\/\/localhost:8080\/config v\u00e0 xem gi\u00e1 tr\u1ecb ban \u0111\u1ea7u.<\/li>\n\n\n\n<li>V\u00e0o Git repository, s\u1eeda gi\u00e1 tr\u1ecb order.discount.percentage t\u1eeb 15 th\u00e0nh 20 v\u00e0 commit.<\/li>\n\n\n\n<li>Truy c\u1eadp l\u1ea1i http:\/\/localhost:8080\/config, gi\u00e1 tr\u1ecb v\u1eabn l\u00e0 15.<\/li>\n\n\n\n<li>M\u1edf m\u1ed9t terminal ho\u1eb7c Postman, g\u1eedi m\u1ed9t request POST r\u1ed7ng \u0111\u1ebfn endpoint c\u1ee7a Actuator: curl -X POST http:\/\/localhost:8080\/actuator\/refresh<\/li>\n\n\n\n<li>Truy c\u1eadp l\u1ea1i http:\/\/localhost:8080\/config. <strong>B\u00e2y gi\u1edd b\u1ea1n s\u1ebd th\u1ea5y gi\u00e1 tr\u1ecb \u0111\u00e3 \u0111\u01b0\u1ee3c c\u1eadp nh\u1eadt th\u00e0nh <\/strong><strong>20<\/strong><strong> m\u00e0 kh\u00f4ng c\u1ea7n kh\u1edfi \u0111\u1ed9ng l\u1ea1i service!<\/strong><\/li>\n<\/ol>\n\n\n\n<p>L\u01b0u \u00fd: Trong m\u00f4i tr\u01b0\u1eddng th\u1ef1c t\u1ebf, vi\u1ec7c g\u1ecdi API refresh th\u1ee7 c\u00f4ng kh\u00f4ng kh\u1ea3 thi. Thay v\u00e0o \u0111\u00f3, ng\u01b0\u1eddi ta th\u01b0\u1eddng d\u00f9ng Spring Cloud Bus k\u1ebft h\u1ee3p v\u1edbi RabbitMQ ho\u1eb7c Kafka. Khi c\u00f3 commit m\u1edbi trong Git, m\u1ed9t webhook s\u1ebd k\u00edch ho\u1ea1t v\u00e0 g\u1eedi tin nh\u1eafn qua message bus, t\u1ea5t c\u1ea3 c\u00e1c instance c\u1ee7a service s\u1ebd t\u1ef1 \u0111\u1ed9ng nh\u1eadn \u0111\u01b0\u1ee3c t\u00edn hi\u1ec7u v\u00e0 refresh c\u1ea5u h\u00ecnh.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-netflix-eureka-service-registry-pattern-c\u1ee7a-spring-cloud\"><span class=\"ez-toc-section\" id=\"Netflix_Eureka_%E2%80%93_Service_Registry_Pattern_cua_Spring_Cloud\"><\/span><strong>Netflix Eureka \u2013 Service Registry Pattern c\u1ee7a Spring Cloud<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-v\u1ea5n-d\u1ec1\"><strong>V\u1ea5n \u0111\u1ec1<\/strong><\/h3>\n\n\n\n<p>Trong ki\u1ebfn tr\u00fac microservices, vi\u1ec7c g\u1ecdi t\u1eeb service n\u00e0y \u0111\u1ebfn service kh\u00e1c l\u00e0 ho\u1ea1t \u0111\u1ed9ng di\u1ec5n ra li\u00ean t\u1ee5c. \u1ede m\u00f4i tr\u01b0\u1eddng ph\u00e1t tri\u1ec3n, b\u1ea1n c\u00f3 th\u1ec3 t\u1ea1m &#8220;hard-code&#8221; \u0111\u1ecba ch\u1ec9 http:\/\/localhost:8081 trong file c\u1ea5u h\u00ecnh. Nh\u01b0ng tr\u00ean m\u00f4i tr\u01b0\u1eddng production, c\u00e1ch ti\u1ebfp c\u1eadn n\u00e0y ho\u00e0n to\u00e0n th\u1ea5t b\u1ea1i. T\u1ea1i sao?<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u0110\u1ecba ch\u1ec9 IP \u0111\u1ed9ng:<\/strong> Trong c\u00e1c n\u1ec1n t\u1ea3ng cloud (AWS, Azure) ho\u1eb7c container (Docker, Kubernetes), c\u00e1c service instance \u0111\u01b0\u1ee3c g\u00e1n \u0111\u1ecba ch\u1ec9 IP m\u1ed9t c\u00e1ch t\u1ef1 \u0111\u1ed9ng v\u00e0 c\u00f3 th\u1ec3 thay \u0111\u1ed5i sau m\u1ed7i l\u1ea7n kh\u1edfi \u0111\u1ed9ng l\u1ea1i ho\u1eb7c redeploy.<\/li>\n\n\n\n<li><strong>T\u1ef1 \u0111\u1ed9ng co gi\u00e3n (Auto-scaling):<\/strong> \u0110\u1ec3 \u0111\u00e1p \u1ee9ng t\u1ea3i, h\u1ec7 th\u1ed1ng c\u00f3 th\u1ec3 t\u1ef1 \u0111\u1ed9ng t\u1ea1o th\u00eam ho\u1eb7c x\u00f3a b\u1edbt c\u00e1c instance c\u1ee7a m\u1ed9t service. Vi\u1ec7c c\u1eadp nh\u1eadt danh s\u00e1ch \u0111\u1ecba ch\u1ec9 IP n\u00e0y b\u1eb1ng tay l\u00e0 kh\u00f4ng th\u1ec3.<\/li>\n\n\n\n<li><strong>T\u00ednh s\u1eb5n s\u00e0ng (Availability):<\/strong> N\u1ebfu m\u1ed9t instance t\u1ea1i \u0111\u1ecba ch\u1ec9 IP \u0111\u00e3 \u0111\u01b0\u1ee3c hard-code g\u1eb7p s\u1ef1 c\u1ed1, h\u1ec7 th\u1ed1ng kh\u00f4ng c\u00f3 c\u00e1ch n\u00e0o t\u1ef1 \u0111\u1ed9ng chuy\u1ec3n h\u01b0\u1edbng request sang m\u1ed9t instance kh\u00e1c \u0111ang kh\u1ecfe m\u1ea1nh.<\/li>\n<\/ul>\n\n\n\n<p>B\u00e0i to\u00e1n \u0111\u1eb7t ra l\u00e0: C\u1ea7n m\u1ed9t c\u01a1 ch\u1ebf t\u1ef1 \u0111\u1ed9ng v\u00e0 linh ho\u1ea1t \u0111\u1ec3 m\u1ed9t service c\u00f3 th\u1ec3 t\u00ecm ra \u0111\u1ecba ch\u1ec9 m\u1ea1ng (network location) hi\u1ec7n t\u1ea1i c\u1ee7a service kh\u00e1c ch\u1ec9 b\u1eb1ng c\u00e1ch s\u1eed d\u1ee5ng m\u1ed9t c\u00e1i t\u00ean logic.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-gi\u1ea3i-phap-service-registry-pattern-va-netflix-eureka\"><strong>Gi\u1ea3i ph\u00e1p: Service Registry Pattern v\u00e0 Netflix Eureka<\/strong><\/h3>\n\n\n\n<p><strong>Service Registry Pattern<\/strong> nh\u01b0 m\u1ed9t &#8220;danh b\u1ea1 \u0111i\u1ec7n tho\u1ea1i&#8221; \u0111\u1ed9ng cho to\u00e0n b\u1ed9 h\u1ec7 th\u1ed1ng microservice c\u1ee7a b\u1ea1n. N\u00f3 h\u1ed7 tr\u1ee3:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u0110\u0103ng k\u00fd (Registration): Khi m\u1ed9t service instance kh\u1edfi \u0111\u1ed9ng, n\u00f3 s\u1ebd &#8220;g\u1ecdi \u0111i\u1ec7n&#8221; cho danh b\u1ea1 v\u00e0 n\u00f3i: &#8220;T\u00f4i l\u00e0 product-service, \u0111ang ch\u1ea1y t\u1ea1i \u0111\u1ecba ch\u1ec9 <code>10.20.30.40:8081<\/code>&#8220;.<\/li>\n\n\n\n<li>Kh\u00e1m ph\u00e1 (Discovery): Khi order-service mu\u1ed1n g\u1ecdi product-service, n\u00f3 s\u1ebd h\u1ecfi danh b\u1ea1: &#8220;Cho t\u00f4i xin \u0111\u1ecba ch\u1ec9 c\u1ee7a product-service&#8221;. Danh b\u1ea1 s\u1ebd tr\u1ea3 v\u1ec1 m\u1ed9t danh s\u00e1ch c\u00e1c \u0111\u1ecba ch\u1ec9 \u0111ang ho\u1ea1t \u0111\u1ed9ng.<\/li>\n<\/ul>\n\n\n\n<p><strong>Spring Cloud Netflix Eureka<\/strong> l\u00e0 m\u1ed9t project c\u1ee7a Spring Cloud gi\u00fap tri\u1ec3n khai m\u00f4 h\u00ecnh n\u00e0y m\u1ed9t c\u00e1ch hi\u1ec7u qu\u1ea3.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-cach-ho\u1ea1t-d\u1ed9ng-c\u1ee7a-eureka\"><strong>C\u00e1ch ho\u1ea1t \u0111\u1ed9ng c\u1ee7a Eureka<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Eureka Server:<\/strong> L\u00e0 service &#8220;danh b\u1ea1&#8221; trung t\u00e2m. N\u00f3 cung c\u1ea5p m\u1ed9t dashboard \u0111\u1ec3 theo d\u00f5i tr\u1ea1ng th\u00e1i c\u1ee7a t\u1ea5t c\u1ea3 c\u00e1c microservice.<\/li>\n\n\n\n<li><strong>Eureka Client:<\/strong> L\u00e0 m\u1ed9t th\u01b0 vi\u1ec7n \u0111\u01b0\u1ee3c t\u00edch h\u1ee3p v\u00e0o m\u1ed7i microservice.\n<ul class=\"wp-block-list\">\n<li>Khi service kh\u1edfi \u0111\u1ed9ng, client s\u1ebd t\u1ef1 \u0111\u1ed9ng \u0111\u0103ng k\u00fd (register) th\u00f4ng tin c\u1ee7a service \u0111\u00f3 v\u1edbi Eureka Server.<\/li>\n\n\n\n<li>\u0110\u1ecbnh k\u1ef3, client s\u1ebd g\u1eedi m\u1ed9t t\u00edn hi\u1ec7u <strong>heartbeat<\/strong> (nh\u1ecbp tim) \u0111\u1ebfn Server \u0111\u1ec3 b\u00e1o r\u1eb1ng &#8220;t\u00f4i v\u1eabn c\u00f2n s\u1ed1ng&#8221;. N\u1ebfu Server kh\u00f4ng nh\u1eadn \u0111\u01b0\u1ee3c heartbeat trong m\u1ed9t kho\u1ea3ng th\u1eddi gian nh\u1ea5t \u0111\u1ecbnh, n\u00f3 s\u1ebd coi nh\u01b0 instance \u0111\u00f3 \u0111\u00e3 ch\u1ebft v\u00e0 lo\u1ea1i b\u1ecf kh\u1ecfi danh b\u1ea1.<\/li>\n\n\n\n<li>Client c\u0169ng \u0111\u1ecbnh k\u1ef3 k\u00e9o (fetch) b\u1ea3n sao c\u1ee7a danh b\u1ea1 t\u1eeb Server v\u1ec1 v\u00e0 l\u01b0u tr\u1eef \u1edf local cache \u0111\u1ec3 t\u0103ng t\u1ed1c \u0111\u1ed9 truy v\u1ea5n v\u00e0 kh\u1ea3 n\u0103ng ch\u1ecbu l\u1ed7i.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-h\u01b0\u1edbng-d\u1eabn-th\u1ef1c-hanh-0\"><strong>H\u01b0\u1edbng d\u1eabn th\u1ef1c h\u00e0nh<\/strong><\/h3>\n\n\n\n<p>Ch\u00fang ta s\u1ebd x\u00e2y d\u1ef1ng m\u1ed9t h\u1ec7 th\u1ed1ng g\u1ed3m:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>eureka-server:<\/strong> Service danh b\u1ea1.<\/li>\n\n\n\n<li><strong>product-service:<\/strong> Service \u0111\u0103ng k\u00fd v\u1edbi t\u00ean <code>PRODUCT-SERVICE<\/code>.<\/li>\n\n\n\n<li><strong>order-service:<\/strong> Service c\u0169ng \u0111\u0103ng k\u00fd v\u00e0 s\u1ebd g\u1ecdi \u0111\u1ebfn <code>PRODUCT-SERVICE<\/code>.<\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-1-thi\u1ebft-l\u1eadp-eureka-server\"><strong>1. Thi\u1ebft l\u1eadp Eureka Server<\/strong><\/h4>\n\n\n\n<p><strong>a. Dependencies (<code>pom.xml<\/code>):<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>XML\n&lt;dependency&gt;\n    &lt;groupId&gt;org.springframework.cloud&lt;\/groupId&gt;\n    &lt;artifactId&gt;spring-cloud-starter-netflix-eureka-server&lt;\/artifactId&gt;\n&lt;\/dependency&gt;<\/code><\/pre>\n\n\n\n<p><strong>b. K\u00edch ho\u1ea1t Eureka Server:<\/strong> Trong class Application ch\u00ednh, th\u00eam annotation <code>@EnableEurekaServer<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@SpringBootApplication\n@EnableEurekaServer\npublic class EurekaServerApplication {\n    public static void main(String&#91;] args) {\n        SpringApplication.run(EurekaServerApplication.class, args);\n    }\n}<\/code><\/pre>\n\n\n\n<p><strong>C\u1ea5u h\u00ecnh Server (<code>application.yml<\/code>):<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>server:\n  port: 8761 # Port m\u1eb7c \u0111\u1ecbnh c\u1ee7a Eureka\n\neureka:\n  client:\n    register-with-eureka: false # Server kh\u00f4ng c\u1ea7n t\u1ef1 \u0111\u0103ng k\u00fd v\u1edbi ch\u00ednh n\u00f3\n    fetch-registry: false # Server kh\u00f4ng c\u1ea7n l\u1ea5y th\u00f4ng tin t\u1eeb ch\u00ednh n\u00f3<\/code><\/pre>\n\n\n\n<p>Kh\u1edfi ch\u1ea1y <code>eureka-server<\/code>. Truy c\u1eadp <code>http:\/\/localhost:8761<\/code>, b\u1ea1n s\u1ebd th\u1ea5y dashboard c\u1ee7a Eureka.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-2-c\u1ea5u-hinh-microservice-clients-product-service-amp-order-service\"><strong>2. C\u1ea5u h\u00ecnh Microservice Clients (<code>product-service<\/code> &amp; <code>order-service<\/code>)<\/strong><\/h4>\n\n\n\n<p>C\u1ea3 hai service n\u00e0y s\u1ebd c\u00f3 c\u1ea5u h\u00ecnh t\u01b0\u01a1ng t\u1ef1 nhau.<\/p>\n\n\n\n<p><strong>a. Dependencies (<code>pom.xml<\/code>):<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>XML\n&lt;dependency&gt;\n    &lt;groupId&gt;org.springframework.cloud&lt;\/groupId&gt;\n    &lt;artifactId&gt;spring-cloud-starter-netflix-eureka-client&lt;\/artifactId&gt;\n&lt;\/dependency&gt;\n&lt;dependency&gt;\n    &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n    &lt;artifactId&gt;spring-boot-starter-web&lt;\/artifactId&gt;\n&lt;\/dependency&gt;<\/code><\/pre>\n\n\n\n<p><strong>b. K\u00edch ho\u1ea1t Eureka Client:<\/strong>&nbsp;<\/p>\n\n\n\n<p>Trong class Application ch\u00ednh, th\u00eam annotation <code>@EnableDiscoveryClient<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Java\n@SpringBootApplication\n@EnableDiscoveryClient\npublic class ProductServiceApplication {\n    \/\/ ...\n}<\/code><\/pre>\n\n\n\n<p><strong>c. C\u1ea5u h\u00ecnh Client (<code>application.yml<\/code> c\u1ee7a <code>product-service<\/code>):<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>spring:\n  application:\n    name: product-service # T\u00ean logic s\u1ebd \u0111\u01b0\u1ee3c \u0111\u0103ng k\u00fd\n\nserver:\n  port: 8081 # Ch\u1ea1y \u1edf port 8081\n\neureka:\n  client:\n    service-url:\n      defaultZone: http:\/\/localhost:8761\/eureka\/ # \u0110\u1ecba ch\u1ec9 Eureka Server<\/code><\/pre>\n\n\n\n<p><em>T\u01b0\u01a1ng t\u1ef1, c\u1ea5u h\u00ecnh cho <code>order-service<\/code> v\u1edbi <code>name: order-service v\u00e0 port: 8082<\/code>.<\/em><\/p>\n\n\n\n<p>B\u00e2y gi\u1edd, h\u00e3y ch\u1ea1y <code>product-service<\/code> v\u00e0 <code>order-service<\/code>. Quay l\u1ea1i dashboard Eureka (<code>http:\/\/localhost:8761<\/code>), b\u1ea1n s\u1ebd th\u1ea5y <code>PRODUCT-SERVICE<\/code> v\u00e0 <code>ORDER-SERVICE<\/code> xu\u1ea5t hi\u1ec7n trong danh s\u00e1ch &#8220;Instances currently registered&#8221;.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-3-giao-ti\u1ebfp-gi\u1eefa-cac-service\"><strong>3. Giao ti\u1ebfp gi\u1eefa c\u00e1c Service<\/strong><\/h4>\n\n\n\n<p>Gi\u1edd l\u00e0 ph\u1ea7n quan tr\u1ecdng nh\u1ea5t: l\u00e0m sao <code>order-service<\/code> g\u1ecdi \u0111\u01b0\u1ee3c <code>product-service<\/code> m\u00e0 kh\u00f4ng c\u1ea7n bi\u1ebft \u0111\u1ecba ch\u1ec9 IP\/port.<\/p>\n\n\n\n<p><strong>C\u00e1ch l\u00e0m \u0111\u01b0\u1ee3c khuy\u1ebfn ngh\u1ecb: S\u1eed d\u1ee5ng <code>RestTemplate<\/code> v\u1edbi <code>@LoadBalanced<\/code><\/strong><\/p>\n\n\n\n<p><strong>a. T\u1ea1o m\u1ed9t <code>RestTemplate<\/code> Bean trong <code>order-service<\/code>:<\/strong> T\u1ea1o m\u1ed9t class config v\u00e0 khai b\u00e1o bean. Annotation&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@LoadBalanced \n@Configuration\npublic class AppConfig {\n    @Bean\n    @LoadBalanced \/\/ B\u1eadt t\u00ednh n\u0103ng client-side load balancing\n    public RestTemplate restTemplate() {\n        return new RestTemplate();\n    }\n}<\/code><\/pre>\n\n\n\n<p><strong>b. T\u1ea1o m\u1ed9t API trong <code>product-service<\/code> \u0111\u1ec3 <code>order-service<\/code> g\u1ecdi:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Trong ProductController c\u1ee7a product-service\n@RestController\n@RequestMapping(\"\/products\")\npublic class ProductController {\n    @GetMapping(\"\/{id}\")\n    public String getProductById(@PathVariable String id) {\n        \/\/ Gi\u1ea3 l\u1eadp tr\u1ea3 v\u1ec1 th\u00f4ng tin s\u1ea3n ph\u1ea9m\n        return \"Product details for ID: \" + id;\n    }\n}<\/code><\/pre>\n\n\n\n<p><strong>c. G\u1ecdi <code>product-service<\/code> t\u1eeb <code>order-service<\/code>:<\/strong> Trong <code>order-service<\/code>, inject <code>RestTemplate<\/code> v\u00e0 g\u1ecdi \u0111\u1ebfn p<code>roduct-service<\/code> b\u1eb1ng <strong>t\u00ean logic<\/strong> \u0111\u00e3 \u0111\u0103ng k\u00fd.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Trong OrderController c\u1ee7a order-service\n@RestController\n@RequestMapping(\"\/orders\")\npublic class OrderController {\n\n    @Autowired\n    private RestTemplate restTemplate;\n\n    @GetMapping(\"\/{orderId}\")\n    public String getOrderDetails(@PathVariable String orderId) {\n        \/\/ G\u1ecdi \u0111\u1ebfn product-service b\u1eb1ng t\u00ean logic \"PRODUCT-SERVICE\"\n        \/\/ Spring s\u1ebd t\u1ef1 \u0111\u1ed9ng ph\u00e2n gi\u1ea3i t\u00ean n\u00e0y th\u00e0nh \u0111\u1ecba ch\u1ec9 IP:port th\u1ef1c t\u1ebf\n        String productId = \"p123\"; \/\/ Gi\u1ea3 l\u1eadp l\u1ea5y product ID t\u1eeb order\n        String productInfo = restTemplate.getForObject(\n            \"http:\/\/PRODUCT-SERVICE\/products\/{id}\", \/\/ &lt;-- Ch\u00fa \u00fd: d\u00f9ng t\u00ean service, kh\u00f4ng d\u00f9ng IP\n            String.class,\n            productId\n        );\n\n        return \"Order ID: \" + orderId + \" | Contains -&gt; &#91; \" + productInfo + \" ]\";\n    }\n}<\/code><\/pre>\n\n\n\n<p><strong>d. Ki\u1ec3m tra:<\/strong> Ch\u1ea1y c\u1ea3 3 service. D\u00f9ng Postman ho\u1eb7c tr\u00ecnh duy\u1ec7t truy c\u1eadp v\u00e0o <code>http:\/\/localhost:8082\/orders\/o456<\/code>. K\u1ebft qu\u1ea3 tr\u1ea3 v\u1ec1 s\u1ebd l\u00e0: <code>Order ID: o456 | Contains -&gt; [ Product details for ID: p123 ]<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-spring-cloud-gateway-gi\u1ea3i-phap-api-gateway-c\u1ee7a-spring\"><span class=\"ez-toc-section\" id=\"Spring_Cloud_Gateway_%E2%80%93_giai_phap_API_Gateway_cua_Spring\"><\/span><strong>Spring Cloud Gateway &#8211; gi\u1ea3i ph\u00e1p API Gateway c\u1ee7a Spring<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Khi c\u00e1c microservice \u0111\u00e3 c\u00f3 th\u1ec3 t\u1ef1 t\u00ecm th\u1ea5y v\u00e0 giao ti\u1ebfp v\u1edbi nhau, m\u1ed9t c\u00e2u h\u1ecfi l\u1edbn kh\u00e1c n\u1ea3y sinh: Client (\u1ee9ng d\u1ee5ng web, mobile) t\u1eeb b\u00ean ngo\u00e0i s\u1ebd t\u01b0\u01a1ng t\u00e1c v\u1edbi h\u1ec7 th\u1ed1ng c\u1ee7a ch\u00fang ta nh\u01b0 th\u1ebf n\u00e0o?<\/p>\n\n\n\n<p>Vi\u1ec7c \u0111\u1ec3 client g\u1ecdi tr\u1ef1c ti\u1ebfp \u0111\u1ebfn t\u1eebng microservice s\u1ebd g\u00e2y ra nhi\u1ec1u v\u1ea5n \u0111\u1ec1 nghi\u00eam tr\u1ecdng:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>T\u0103ng \u0111\u1ed9 ph\u1ee9c t\u1ea1p ph\u00eda Client:<\/strong> Client ph\u1ea3i bi\u1ebft \u0111\u1ecba ch\u1ec9 c\u1ee7a h\u00e0ng ch\u1ee5c service, t\u1ea1o ra s\u1ef1 ph\u1ee5 thu\u1ed9c (coupling) ch\u1eb7t ch\u1ebd.<\/li>\n\n\n\n<li><strong>L\u1eb7p l\u1ea1i logic:<\/strong> C\u00e1c t\u00e1c v\u1ee5 chung nh\u01b0 x\u00e1c th\u1ef1c (authentication), ghi log (logging), gi\u1edbi h\u1ea1n t\u1ea7n su\u1ea5t (rate limiting) s\u1ebd ph\u1ea3i \u0111\u01b0\u1ee3c c\u00e0i \u0111\u1eb7t \u1edf m\u1ed7i service, d\u1eabn \u0111\u1ebfn tr\u00f9ng l\u1eb7p code v\u00e0 kh\u00f3 b\u1ea3o tr\u00ec.<\/li>\n\n\n\n<li><strong>R\u1ee7i ro b\u1ea3o m\u1eadt:<\/strong> To\u00e0n b\u1ed9 c\u1ea5u tr\u00fac h\u1ec7 th\u1ed1ng b\u00ean trong b\u1ecb l\u1ed9 ra ngo\u00e0i. Vi\u1ec7c t\u00e1i c\u1ea5u tr\u00fac (refactoring) c\u00e1c service b\u00ean trong tr\u1edf th\u00e0nh m\u1ed9t c\u01a1n \u00e1c m\u1ed9ng v\u00ec c\u00f3 th\u1ec3 ph\u00e1 v\u1ee1 t\u00edch h\u1ee3p v\u1edbi client.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-gi\u1ea3i-phap-spring-cloud-gateway\"><strong>Gi\u1ea3i ph\u00e1p: Spring Cloud Gateway<\/strong><\/h3>\n\n\n\n<p>M\u00f4 h\u00ecnh <strong>API Gateway<\/strong> ra \u0111\u1eddi \u0111\u1ec3 gi\u1ea3i quy\u1ebft tri\u1ec7t \u0111\u1ec3 v\u1ea5n \u0111\u1ec1 n\u00e0y. N\u00f3 ho\u1ea1t \u0111\u1ed9ng nh\u01b0 m\u1ed9t l\u1edbp \u0111\u1ec7m, m\u1ed9t &#8220;l\u1ed1i v\u00e0o duy nh\u1ea5t&#8221; cho t\u1ea5t c\u1ea3 c\u00e1c y\u00eau c\u1ea7u t\u1eeb b\u00ean ngo\u00e0i. M\u1ecdi request t\u1eeb client \u0111\u1ec1u ph\u1ea3i \u0111i qua Gateway tr\u01b0\u1edbc khi \u0111\u01b0\u1ee3c chuy\u1ec3n \u0111\u1ebfn c\u00e1c microservice t\u01b0\u01a1ng \u1ee9ng.<\/p>\n\n\n\n<p><strong>Spring Cloud Gateway<\/strong> l\u00e0 gi\u1ea3i ph\u00e1p API Gateway th\u1ebf h\u1ec7 m\u1edbi c\u1ee7a Spring, \u0111\u01b0\u1ee3c x\u00e2y d\u1ef1ng tr\u00ean n\u1ec1n t\u1ea3ng non-blocking (kh\u00f4ng kh\u00f3a), mang l\u1ea1i hi\u1ec7u n\u0103ng v\u00e0 kh\u1ea3 n\u0103ng m\u1edf r\u1ed9ng v\u01b0\u1ee3t tr\u1ed9i so v\u1edbi Zuul 1.<\/p>\n\n\n\n<p><strong>C\u00e1c ch\u1ee9c n\u0103ng ch\u00ednh c\u1ee7a m\u1ed9t API Gateway:<\/strong><\/p>\n\n\n\n<p><strong>\u0110\u1ecbnh tuy\u1ebfn (Routing):<\/strong> \u0110\u00e2y l\u00e0 nhi\u1ec7m v\u1ee5 c\u1ed1t l\u00f5i. Gateway s\u1ebd x\u00e1c \u0111\u1ecbnh xem m\u1ed9t request n\u00ean \u0111\u01b0\u1ee3c chuy\u1ec3n \u0111\u1ebfn microservice n\u00e0o d\u1ef1a tr\u00ean c\u00e1c quy t\u1eafc (v\u00ed d\u1ee5: \u0111\u01b0\u1eddng d\u1eabn URL, t\u00ean mi\u1ec1n, header).<\/p>\n\n\n\n<p><strong>X\u1eed l\u00fd c\u00e1c t\u00e1c v\u1ee5 chung (Cross-Cutting Concerns):<\/strong> Gateway l\u00e0 n\u01a1i l\u00fd t\u01b0\u1edfng \u0111\u1ec3 x\u1eed l\u00fd c\u00e1c logic chung m\u1ed9t c\u00e1ch t\u1eadp trung. C\u00e1c logic n\u00e0y \u0111\u01b0\u1ee3c tri\u1ec3n khai d\u01b0\u1edbi d\u1ea1ng c\u00e1c <strong>Filters<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>B\u1ea3o m\u1eadt:<\/strong> X\u00e1c th\u1ef1c token (JWT), ki\u1ec3m tra API key.<\/li>\n\n\n\n<li><strong>Gi\u00e1m s\u00e1t:<\/strong> Ghi log request\/response.<\/li>\n\n\n\n<li><strong>T\u0103ng hi\u1ec7u n\u0103ng:<\/strong> Caching c\u00e1c response th\u01b0\u1eddng xuy\u00ean truy c\u1eadp.<\/li>\n\n\n\n<li><strong>B\u1ea3o v\u1ec7 h\u1ec7 th\u1ed1ng:<\/strong> Gi\u1edbi h\u1ea1n t\u1ea7n su\u1ea5t request (Rate Limiting).<\/li>\n<\/ul>\n\n\n\n<p><strong>Chuy\u1ec3n \u0111\u1ed5i giao th\u1ee9c (Protocol Translation):<\/strong> C\u00f3 th\u1ec3 chuy\u1ec3n \u0111\u1ed5i y\u00eau c\u1ea7u t\u1eeb giao th\u1ee9c n\u00e0y sang giao th\u1ee9c kh\u00e1c, v\u00ed d\u1ee5: t\u1eeb REST sang gRPC.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-h\u01b0\u1edbng-d\u1eabn-th\u1ef1c-hanh-nbsp\"><strong>H\u01b0\u1edbng d\u1eabn th\u1ef1c h\u00e0nh&nbsp;<\/strong><\/h3>\n\n\n\n<p>Ch\u00fang ta s\u1ebd c\u00e0i \u0111\u1eb7t m\u1ed9t Gateway \u0111\u1ec3 \u0111\u1ecbnh tuy\u1ebfn c\u00e1c request \u0111\u1ebfn <code>product-service<\/code> v\u00e0 <code>order-service<\/code> \u0111\u00e3 t\u1ea1o \u1edf ph\u1ea7n tr\u01b0\u1edbc.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-1-cai-d\u1eb7t-spring-cloud-gateway\"><strong>1. C\u00e0i \u0111\u1eb7t Spring Cloud Gateway<\/strong><\/h4>\n\n\n\n<p>T\u1ea1o m\u1ed9t Spring Boot project m\u1edbi v\u1edbi dependency<code> spring-cloud-starter-gateway<\/code> v\u00e0 <code>spring-cloud-starter-netflix-eureka-client<\/code> (\u0111\u1ec3 Gateway c\u00f3 th\u1ec3 t\u00ecm th\u1ea5y c\u00e1c service kh\u00e1c qua Eureka).<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-2-c\u1ea5u-hinh-routes-va-filters\"><strong>2. C\u1ea5u h\u00ecnh Routes v\u00e0 Filters<\/strong><\/h4>\n\n\n\n<p>Ph\u1ea7n quan tr\u1ecdng nh\u1ea5t n\u1eb1m trong file <code>application.yml<\/code> c\u1ee7a Gateway. Ch\u00fang ta s\u1ebd \u0111\u1ecbnh ngh\u0129a c\u00e1c quy t\u1eafc \u0111\u1ecbnh tuy\u1ebfn.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>server:\n  port: 9000 # C\u1ed5ng c\u1ee7a Gateway\n\nspring:\n  application:\n    name: gateway-service\n  cloud:\n    gateway:\n      routes:\n        # Route cho Product Service\n        - id: product-service-route\n          uri: lb:\/\/PRODUCT-SERVICE # lb:\/\/ -&gt; L\u1ea5y service t\u1eeb Eureka v\u00e0 c\u00e2n b\u1eb1ng t\u1ea3i\n          predicates:\n            - Path=\/api\/products\/** # N\u1ebfu path kh\u1edbp v\u1edbi m\u1eabu n\u00e0y...\n          filters:\n            - AddRequestHeader=X-Request-Source, api-gateway # ...th\u00ec th\u00eam header n\u00e0y v\u00e0o request\n\n        # Route cho Order Service\n        - id: order-service-route\n          uri: lb:\/\/ORDER-SERVICE\n          predicates:\n            - Path=\/api\/orders\/**<\/code><\/pre>\n\n\n\n<p><strong>Gi\u1ea3i th\u00edch:<\/strong><\/p>\n\n\n\n<p><strong><code>uri: lb:\/\/PRODUCT-SERVICE<\/code><\/strong>: <code>lb<\/code> l\u00e0 vi\u1ebft t\u1eaft c\u1ee7a load-balancer. D\u00f2ng n\u00e0y y\u00eau c\u1ea7u Gateway: &#8220;H\u00e3y t\u00ecm t\u1ea5t c\u1ea3 c\u00e1c instance c\u1ee7a service c\u00f3 t\u00ean <code>PRODUCT-SERVICE<\/code> tr\u00ean Eureka v\u00e0 chuy\u1ec3n ti\u1ebfp request \u0111\u1ebfn m\u1ed9t trong s\u1ed1 ch\u00fang&#8221;.<\/p>\n\n\n\n<p><strong><code>predicates: - Path=\/api\/products\/**<\/code><\/strong>: \u0110\u00e2y l\u00e0 \u0111i\u1ec1u ki\u1ec7n \u0111\u1ec3 k\u00edch ho\u1ea1t route. B\u1ea5t k\u1ef3 request n\u00e0o c\u00f3 \u0111\u01b0\u1eddng d\u1eabn b\u1eaft \u0111\u1ea7u b\u1eb1ng <code>\/api\/products\/<\/code> s\u1ebd \u0111\u01b0\u1ee3c x\u1eed l\u00fd b\u1edfi route n\u00e0y.<\/p>\n\n\n\n<p><strong><code>filters: - AddRequestHeader=...<\/code><\/strong>: \u0110\u00e2y l\u00e0 m\u1ed9t h\u00e0nh \u0111\u1ed9ng \u0111\u01b0\u1ee3c th\u1ef1c thi tr\u01b0\u1edbc khi request \u0111\u01b0\u1ee3c chuy\u1ec3n \u0111i. \u1ede \u0111\u00e2y, ch\u00fang ta th\u00eam m\u1ed9t header <code>X-Request-Source<\/code> v\u1edbi gi\u00e1 tr\u1ecb <code>api-gateway<\/code> v\u00e0o request.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-3-ki\u1ec3m-tra\"><strong>3. Ki\u1ec3m tra<\/strong><\/h4>\n\n\n\n<p>Sau khi kh\u1edfi ch\u1ea1y Gateway c\u00f9ng v\u1edbi Eureka v\u00e0 2 service kia, to\u00e0n b\u1ed9 vi\u1ec7c giao ti\u1ebfp t\u1eeb b\u00ean ngo\u00e0i s\u1ebd thay \u0111\u1ed5i:<\/p>\n\n\n\n<p><strong>Thay v\u00ec g\u1ecdi:<\/strong> <code>http:\/\/localhost:8081\/products\/{id}<\/code><\/p>\n\n\n\n<p><strong>B\u00e2y gi\u1edd Client s\u1ebd g\u1ecdi:<\/strong> <code>http:\/\/localhost:9000\/api\/products\/{id}<\/code><\/p>\n\n\n\n<p>Request s\u1ebd \u0111i \u0111\u1ebfn Gateway, Gateway kh\u1edbp v\u1edbi route c\u1ee7a <code>product-service<\/code>, th\u00eam header, t\u00ecm \u0111\u1ecba ch\u1ec9 c\u1ee7a <code>product-service<\/code> qua Eureka v\u00e0 chuy\u1ec3n ti\u1ebfp request \u0111\u1ebfn \u0111\u00f3. Client ho\u00e0n to\u00e0n kh\u00f4ng c\u1ea7n bi\u1ebft s\u1ef1 t\u1ed3n t\u1ea1i c\u1ee7a <code>localhost:8081<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-spring-cloud-circuit-breaker-tang-c\u01b0\u1eddng-kh\u1ea3-nang-ch\u1ecbu-l\u1ed7i-trong-microservices\"><span class=\"ez-toc-section\" id=\"Spring_Cloud_Circuit_Breaker_%E2%80%93_Tang_cuong_kha_nang_chiu_loi_trong_Microservices\"><\/span><strong>Spring Cloud Circuit Breaker &#8211; T\u0103ng c\u01b0\u1eddng kh\u1ea3 n\u0103ng ch\u1ecbu l\u1ed7i trong Microservices<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-v\u1ea5n-d\u1ec1-hi\u1ec7u-\u1ee9ng-domino-cascading-failure\"><strong>V\u1ea5n \u0111\u1ec1: Hi\u1ec7u \u1ee9ng Domino (Cascading Failure)<\/strong><\/h3>\n\n\n\n<p>Trong m\u1ed9t h\u1ec7 th\u1ed1ng ph\u00e2n t\u00e1n, &#8220;l\u1ed7i&#8221; kh\u00f4ng ph\u1ea3i l\u00e0 m\u1ed9t kh\u1ea3 n\u0103ng, m\u00e0 l\u00e0 m\u1ed9t \u0111i\u1ec1u ch\u1eafc ch\u1eafn s\u1ebd x\u1ea3y ra. M\u1ed9t service c\u00f3 th\u1ec3 b\u1ecb s\u1eadp, qu\u00e1 t\u1ea3i, ho\u1eb7c ph\u1ea3n h\u1ed3i ch\u1eadm do l\u1ed7i m\u1ea1ng. V\u1ea5n \u0111\u1ec1 nghi\u00eam tr\u1ecdng x\u1ea3y ra khi m\u1ed9t s\u1ef1 c\u1ed1 nh\u1ecf lan truy\u1ec1n ra to\u00e0n h\u1ec7 th\u1ed1ng.<\/p>\n\n\n\n<p>H\u00e3y xem x\u00e9t k\u1ecbch b\u1ea3n sau: <code>Order-Service<\/code> g\u1ecdi \u0111\u1ebfn <code>Product-Service<\/code> \u0111\u1ec3 l\u1ea5y th\u00f4ng tin s\u1ea3n ph\u1ea9m. \u0110\u1ed9t nhi\u00ean, <code>Product-Service<\/code> b\u1ecb l\u1ed7i v\u00e0 ph\u1ea3n h\u1ed3i r\u1ea5t ch\u1eadm. C\u00e1c request t\u1eeb <code>Order-Service<\/code> s\u1ebd b\u1ecb treo l\u1ea1i \u0111\u1ec3 ch\u1edd \u0111\u1ee3i. N\u1ebfu c\u00f3 nhi\u1ec1u request \u0111\u1ebfn c\u00f9ng l\u00fac, to\u00e0n b\u1ed9 thread pool c\u1ee7a Order-Service s\u1ebd b\u1ecb chi\u1ebfm d\u1ee5ng h\u1ebft b\u1edfi vi\u1ec7c ch\u1edd \u0111\u1ee3i <code>Product-Service<\/code>. K\u1ebft qu\u1ea3 l\u00e0 <code>Order-Service<\/code> c\u0169ng b\u1ecb treo v\u00e0 kh\u00f4ng th\u1ec3 x\u1eed l\u00fd b\u1ea5t k\u1ef3 y\u00eau c\u1ea7u n\u00e0o kh\u00e1c. B\u1ea5t k\u1ef3 service n\u00e0o g\u1ecdi \u0111\u1ebfn <code>Order-Service<\/code> c\u0169ng s\u1ebd b\u1ecb \u1ea3nh h\u01b0\u1edfng theo. \u0110\u00e2y ch\u00ednh l\u00e0 <strong>hi\u1ec7u \u1ee9ng domino (cascading failure)<\/strong>, m\u1ed9t s\u1ef1 c\u1ed1 nh\u1ecf c\u00f3 th\u1ec3 k\u00e9o s\u1eadp c\u1ea3 m\u1ed9t h\u1ec7 th\u1ed1ng l\u1edbn.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-gi\u1ea3i-phap-mo-hinh-circuit-breaker\"><strong>Gi\u1ea3i ph\u00e1p: M\u00f4 h\u00ecnh Circuit Breaker<\/strong><\/h3>\n\n\n\n<p>\u0110\u1ec3 ng\u0103n ch\u1eb7n th\u1ea3m h\u1ecda tr\u00ean, ch\u00fang ta \u00e1p d\u1ee5ng m\u00f4 h\u00ecnh <strong>Circuit Breaker<\/strong>. \u0110\u00fang nh\u01b0 t\u00ean g\u1ecdi, n\u00f3 ho\u1ea1t \u0111\u1ed9ng nh\u01b0 m\u1ed9t <strong>&#8220;c\u1ea7u dao \u0111i\u1ec7n&#8221;<\/strong> t\u1ef1 \u0111\u1ed9ng trong code c\u1ee7a b\u1ea1n.<\/p>\n\n\n\n<p>Circuit Breaker bao b\u1ecdc c\u00e1c l\u1eddi g\u1ecdi m\u1ea1ng v\u00e0 theo d\u00f5i tr\u1ea1ng th\u00e1i c\u1ee7a ch\u00fang qua 3 tr\u1ea1ng th\u00e1i:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>CLOSED<\/code> (\u0110\u00f3ng):<\/strong> Tr\u1ea1ng th\u00e1i m\u1eb7c \u0111\u1ecbnh, m\u1ecdi request \u0111\u1ec1u \u0111\u01b0\u1ee3c ph\u00e9p \u0111i qua. N\u1ebfu s\u1ed1 l\u01b0\u1ee3ng l\u1ed7i v\u01b0\u1ee3t m\u1ed9t ng\u01b0\u1ee1ng cho ph\u00e9p, c\u1ea7u dao s\u1ebd &#8220;nh\u1ea3y&#8221; sang tr\u1ea1ng th\u00e1i <code>OPEN<\/code>.<\/li>\n\n\n\n<li><strong><code>OPEN<\/code> (M\u1edf):<\/strong> Khi m\u1ea1ch \u0111\u00e3 m\u1edf, m\u1ecdi request ti\u1ebfp theo s\u1ebd b\u1ecb t\u1eeb ch\u1ed1i ngay l\u1eadp t\u1ee9c m\u00e0 kh\u00f4ng c\u1ea7n th\u1ef1c hi\u1ec7n l\u1eddi g\u1ecdi m\u1ea1ng. Thay v\u00e0o \u0111\u00f3, n\u00f3 s\u1ebd tr\u1ea3 v\u1ec1 l\u1ed7i ho\u1eb7c th\u1ef1c thi m\u1ed9t <strong>ph\u01b0\u01a1ng th\u1ee9c d\u1ef1 ph\u00f2ng (fallback)<\/strong>. \u0110i\u1ec1u n\u00e0y gi\u00fap b\u1ea3o v\u1ec7 h\u1ec7 th\u1ed1ng v\u00e0 cho service \u0111ang l\u1ed7i c\u00f3 th\u1eddi gian \u0111\u1ec3 ph\u1ee5c h\u1ed3i.<\/li>\n\n\n\n<li><strong><code>HALF-OPEN<\/code> (N\u1eeda m\u1edf):<\/strong> Sau m\u1ed9t kho\u1ea3ng th\u1eddi gian ch\u1edd, c\u1ea7u dao s\u1ebd chuy\u1ec3n sang tr\u1ea1ng th\u00e1i n\u00e0y. N\u00f3 cho ph\u00e9p m\u1ed9t v\u00e0i request &#8220;th\u1eed nghi\u1ec7m&#8221; \u0111i qua. N\u1ebfu c\u00e1c request n\u00e0y th\u00e0nh c\u00f4ng, c\u1ea7u dao s\u1ebd quay v\u1ec1 tr\u1ea1ng th\u00e1i <code>CLOSED<\/code>. N\u1ebfu th\u1ea5t b\u1ea1i, n\u00f3 s\u1ebd quay l\u1ea1i <code>OPEN<\/code>.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-spring-cloud-circuit-breaker-v\u1edbi-resilience4j\"><strong>Spring Cloud Circuit Breaker v\u1edbi Resilience4j<\/strong><\/h3>\n\n\n\n<p><strong>Spring Cloud Circuit Breaker<\/strong> l\u00e0 m\u1ed9t module cung c\u1ea5p m\u1ed9t l\u1edbp tr\u1eebu t\u01b0\u1ee3ng (abstraction) cho vi\u1ec7c t\u00edch h\u1ee3p c\u00e1c th\u01b0 vi\u1ec7n Circuit Breaker. <strong>Resilience4j<\/strong> l\u00e0 th\u01b0 vi\u1ec7n hi\u1ec7n \u0111\u1ea1i, nh\u1eb9 v\u00e0 \u0111\u01b0\u1ee3c khuy\u1ebfn ngh\u1ecb s\u1eed d\u1ee5ng hi\u1ec7n nay (thay th\u1ebf cho Netflix Hystrix \u0111\u00e3 c\u0169 v\u00e0 \u0111ang trong ch\u1ebf \u0111\u1ed9 b\u1ea3o tr\u00ec).<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-h\u01b0\u1edbng-d\u1eabn-th\u1ef1c-hanh-1\"><strong>H\u01b0\u1edbng d\u1eabn th\u1ef1c h\u00e0nh<\/strong><\/h4>\n\n\n\n<p>Ch\u00fang ta s\u1ebd t\u00edch h\u1ee3p Resilience4j v\u00e0o <code>order-service<\/code> \u0111\u1ec3 b\u1ea3o v\u1ec7 l\u1eddi g\u1ecdi \u0111\u1ebfn <code>product-service<\/code>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-1-cai-d\u1eb7t\"><strong>1. C\u00e0i \u0111\u1eb7t<\/strong><\/h4>\n\n\n\n<p>Th\u00eam dependency sau v\u00e0o <code>pom.xml<\/code> c\u1ee7a <code>order-service<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;dependency&gt;\n    &lt;groupId&gt;org.springframework.cloud&lt;\/groupId&gt;\n    &lt;artifactId&gt;spring-cloud-starter-circuitbreaker-resilience4j&lt;\/artifactId&gt;\n&lt;\/dependency&gt;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-2-c\u1ea5u-hinh-circuit-breaker\"><strong>2. C\u1ea5u h\u00ecnh Circuit Breaker<\/strong><\/h4>\n\n\n\n<p>Trong <code>application.yml<\/code> c\u1ee7a order-service, ta c\u00f3 th\u1ec3 tinh ch\u1ec9nh h\u00e0nh vi c\u1ee7a Circuit Breaker.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>resilience4j:\n  circuitbreaker:\n    instances:\n      productService: # T\u00ean c\u1ee7a Circuit Breaker, s\u1ebd d\u00f9ng trong code\n        slidingWindowSize: 10 # Theo d\u00f5i k\u1ebft qu\u1ea3 c\u1ee7a 10 request g\u1ea7n nh\u1ea5t\n        failureRateThreshold: 50 # N\u1ebfu 50% request l\u1ed7i -&gt; M\u1edf m\u1ea1ch\n        waitDurationInOpenState: 10s # Th\u1eddi gian ch\u1edd tr\u01b0\u1edbc khi chuy\u1ec3n sang HALF-OPEN<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-3-ap-d\u1ee5ng-circuitbreaker-va-fallback\"><strong>3. \u00c1p d\u1ee5ng <code>@CircuitBreaker<\/code> v\u00e0 Fallback<\/strong><\/h4>\n\n\n\n<p>Trong <code>order-service<\/code>, ch\u00fang ta s\u1ebd b\u1ecdc l\u1eddi g\u1ecdi <code>RestTemplate<\/code> b\u1eb1ng annotation <code>@CircuitBreaker<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@Service\npublic class OrderService {\n\n    @Autowired\n    private RestTemplate restTemplate;\n\n    \/\/ Annotation @CircuitBreaker s\u1ebd bao b\u1ecdc ph\u01b0\u01a1ng th\u1ee9c n\u00e0y\n    @CircuitBreaker(name = \"productService\", fallbackMethod = \"getProductFallback\")\n    public String getProductInfo(String productId) {\n        \/\/ L\u1eddi g\u1ecdi \u0111\u1ebfn service c\u00f3 th\u1ec3 g\u00e2y l\u1ed7i\n        return restTemplate.getForObject(\n            \"http:\/\/PRODUCT-SERVICE\/products\/{id}\",\n            String.class,\n            productId\n        );\n    }\n\n    \/\/ Ph\u01b0\u01a1ng th\u1ee9c Fallback, \u0111\u01b0\u1ee3c g\u1ecdi khi m\u1ea1ch m\u1edf (OPEN)\n    \/\/ Ph\u1ea3i c\u00f3 c\u00f9ng signature v\u1edbi ph\u01b0\u01a1ng th\u1ee9c g\u1ed1c, c\u00f3 th\u1ec3 th\u00eam Exception e\n    public String getProductFallback(String productId, Exception e) {\n        \/\/ Tr\u1ea3 v\u1ec1 d\u1eef li\u1ec7u cache, ho\u1eb7c m\u1ed9t th\u00f4ng b\u00e1o m\u1eb7c \u0111\u1ecbnh\n        System.out.println(\"Circuit is open! Falling back for product: \" + productId);\n        return \"Default Product Information\";\n    }\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-4-ki\u1ec3m-tra\"><strong>4. Ki\u1ec3m tra<\/strong><\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Ch\u1ea1y t\u1ea5t c\u1ea3 c\u00e1c service (<code>eureka<\/code>, <code>product-service<\/code>, <code>order-service<\/code>), l\u1eddi g\u1ecdi API ho\u1ea1t \u0111\u1ed9ng b\u00ecnh th\u01b0\u1eddng.<\/li>\n\n\n\n<li>T\u1eaft <code>product-service<\/code> \u0111i.<\/li>\n\n\n\n<li>G\u1ecdi API c\u1ee7a <code>order-service<\/code> v\u00e0i l\u1ea7n. Ban \u0111\u1ea7u b\u1ea1n s\u1ebd nh\u1eadn l\u1ed7i, nh\u01b0ng sau khi \u0111\u1ee7 s\u1ed1 l\u01b0\u1ee3ng l\u1ed7i theo c\u1ea5u h\u00ecnh, Circuit Breaker s\u1ebd &#8220;nh\u1ea3y&#8221;.<\/li>\n\n\n\n<li>C\u00e1c l\u1eddi g\u1ecdi ti\u1ebfp theo s\u1ebd kh\u00f4ng c\u00f2n ch\u1edd \u0111\u1ee3i l\u00e2u n\u1eefa, thay v\u00e0o \u0111\u00f3 ch\u00fang s\u1ebd ngay l\u1eadp t\u1ee9c tr\u1ea3 v\u1ec1 chu\u1ed7i <code>\"Default Product Information\"<\/code> t\u1eeb ph\u01b0\u01a1ng th\u1ee9c <code>getProductFallback<\/code>.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-cac-cau-h\u1ecfi-th\u01b0\u1eddng-g\u1eb7p-v\u1ec1-spring-cloud\"><span class=\"ez-toc-section\" id=\"Cac_cau_hoi_thuong_gap_ve_Spring_Cloud\"><\/span><strong>C\u00e1c c\u00e2u h\u1ecfi th\u01b0\u1eddng g\u1eb7p v\u1ec1 Spring Cloud<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-cac-l\u1ed7i-th\u01b0\u1eddng-g\u1eb7p-v\u1edbi-spring-cloud-la-gi\"><strong>C\u00e1c l\u1ed7i th\u01b0\u1eddng g\u1eb7p v\u1edbi Spring Cloud l\u00e0 g\u00ec?<\/strong><\/h3>\n\n\n\n<p>L\u00e0m vi\u1ec7c v\u1edbi h\u1ec7 th\u1ed1ng ph\u00e2n t\u00e1n lu\u00f4n \u0111i k\u00e8m v\u1edbi nh\u1eefng th\u00e1ch th\u1ee9c g\u1ee1 l\u1ed7i m\u1edbi. D\u01b0\u1edbi \u0111\u00e2y l\u00e0 m\u1ed9t s\u1ed1 l\u1ed7i kinh \u0111i\u1ec3n:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Xung \u0111\u1ed9t phi\u00ean b\u1ea3n (Version Conflict):<\/strong> \u0110\u00e2y l\u00e0 l\u1ed7i ph\u1ed5 bi\u1ebfn nh\u1ea5t. Spring Cloud c\u00f3 m\u1ed9t phi\u00ean b\u1ea3n ph\u00e1t h\u00e0nh (release train) ri\u00eang (v\u00ed d\u1ee5: 2023.0.1, Hoxton) ph\u1ea3i t\u01b0\u01a1ng th\u00edch v\u1edbi m\u1ed9t phi\u00ean b\u1ea3n Spring Boot c\u1ee5 th\u1ec3. Vi\u1ec7c s\u1eed d\u1ee5ng c\u00e1c phi\u00ean b\u1ea3n kh\u00f4ng t\u01b0\u01a1ng th\u00edch s\u1ebd g\u00e2y ra c\u00e1c l\u1ed7i kh\u00f3 hi\u1ec3u.<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Gi\u1ea3i ph\u00e1p:<\/strong> Lu\u00f4n s\u1eed d\u1ee5ng <strong>Spring Cloud BOM (Bill of Materials)<\/strong> trong file pom.xml \u0111\u1ec3 \u0111\u1ea3m b\u1ea3o Spring qu\u1ea3n l\u00fd t\u1ea5t c\u1ea3 c\u00e1c phi\u00ean b\u1ea3n c\u1ee7a c\u00e1c module con m\u1ed9t c\u00e1ch \u0111\u1ed3ng b\u1ed9.<\/li>\n<\/ul>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>L\u1ed7i <code>No instances available for [service-name]<\/code>:<\/strong> Service A kh\u00f4ng th\u1ec3 t\u00ecm th\u1ea5y Service B tr\u00ean Eureka.<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Nguy\u00ean nh\u00e2n:<\/strong> Th\u01b0\u1eddng do l\u1ed7i c\u1ea5u h\u00ecnh. C\u00f3 th\u1ec3 Service B \u0111\u00e3 kh\u00f4ng \u0111\u0103ng k\u00fd th\u00e0nh c\u00f4ng, ho\u1eb7c t\u00ean \u1ee9ng d\u1ee5ng (<code>spring.application.name<\/code>) trong file <code>application.yml <\/code>c\u1ee7a Service B b\u1ecb g\u00f5 sai, ho\u1eb7c kh\u00f4ng kh\u1edbp v\u1edbi t\u00ean logic m\u00e0 Service A \u0111ang d\u00f9ng \u0111\u1ec3 g\u1ecdi.<\/li>\n\n\n\n<li><strong>Ki\u1ec3m tra:<\/strong> Lu\u00f4n ki\u1ec3m tra Dashboard c\u1ee7a Eureka Server \u0111\u1ec3 ch\u1eafc ch\u1eafn r\u1eb1ng service b\u1ea1n c\u1ea7n g\u1ecdi \u0111\u00e3 \u0111\u0103ng k\u00fd v\u00e0 \u0111ang \u1edf tr\u1ea1ng th\u00e1i <code>UP<\/code>.<\/li>\n<\/ul>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>C\u1ea5u h\u00ecnh kh\u00f4ng \u0111\u01b0\u1ee3c n\u1ea1p t\u1eeb Config Server:<\/strong> Service client kh\u1edfi \u0111\u1ed9ng nh\u01b0ng kh\u00f4ng nh\u1eadn \u0111\u01b0\u1ee3c c\u1ea5u h\u00ecnh t\u1eeb Config Server.<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Nguy\u00ean nh\u00e2n:<\/strong> M\u1ed9t l\u1ed7i kinh \u0111i\u1ec3n l\u00e0 \u0111\u1eb7t c\u1ea5u h\u00ecnh k\u1ebft n\u1ed1i t\u1edbi Config Server trong file <code>application.yml<\/code>. C\u1ea5u h\u00ecnh n\u00e0y ph\u1ea3i \u0111\u01b0\u1ee3c \u0111\u1eb7t trong file <code>bootstrap.yml<\/code>, v\u00ec n\u00f3 c\u1ea7n \u0111\u01b0\u1ee3c n\u1ea1p <em>tr\u01b0\u1edbc khi<\/em> context c\u1ee7a \u1ee9ng d\u1ee5ng ch\u00ednh \u0111\u01b0\u1ee3c t\u1ea1o.<\/li>\n\n\n\n<li><strong>Gi\u1ea3i ph\u00e1p:<\/strong> Chuy\u1ec3n c\u00e1c thu\u1ed9c t\u00ednh <code>spring.cloud.config.uri<\/code> sang file <code>bootstrap.yml<\/code>.<\/li>\n<\/ul>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li><strong>Qu\u00ean c\u00e1c Annotation quan tr\u1ecdng:&nbsp;<\/strong><\/li>\n<\/ol>\n\n\n\n<p>V\u00ed d\u1ee5 nh\u01b0:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Qu\u00ean <code>@EnableEurekaServer<\/code> tr\u00ean Eureka Server.<\/li>\n\n\n\n<li>Qu\u00ean <code>@RefreshScope<\/code> tr\u00ean c\u00e1c Bean c\u1ea7n c\u1eadp nh\u1eadt c\u1ea5u h\u00ecnh \u0111\u1ed9ng.&nbsp;<\/li>\n<\/ul>\n\n\n\n<p>\u0110\u1ec3 kh\u1eafc ph\u1ee5c l\u1ed7i n\u00e0y, l\u1eadp tr\u00ecnh vi\u00ean n\u00ean \u0111i theo m\u1ed9t quy tr\u00ecnh g\u1ed3m 3 b\u01b0\u1edbc logic: Hi\u1ec3u ch\u1ee9c n\u0103ng -&gt; T\u00ecm \u0111\u00fang Annotation -&gt; B\u1ed5 sung v\u00e0 ki\u1ec3m tra l\u1ea1i.&nbsp;<\/p>\n\n\n\n<p>\u0110i\u1ec1u n\u00e0y d\u1eabn \u0111\u1ebfn vi\u1ec7c b\u1ea1n g\u1ecdi <code>\/actuator\/refresh<\/code> th\u00e0nh c\u00f4ng nh\u01b0ng gi\u00e1 tr\u1ecb trong code kh\u00f4ng thay \u0111\u1ed5i.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-khi-nao-nen-va-khong-nen-dung-spring-cloud\"><strong>Khi n\u00e0o n\u00ean (v\u00e0 kh\u00f4ng n\u00ean) d\u00f9ng Spring Cloud?<\/strong><\/h3>\n\n\n\n<p>\u0110\u00e2y l\u00e0 m\u1ed9t c\u00e2u h\u1ecfi quan tr\u1ecdng v\u1ec1 ki\u1ebfn tr\u00fac. Vi\u1ec7c l\u1ef1a ch\u1ecdn sai c\u00f4ng c\u1ee5 c\u00f3 th\u1ec3 d\u1eabn \u0111\u1ebfn s\u1ef1 ph\u1ee9c t\u1ea1p kh\u00f4ng c\u1ea7n thi\u1ebft.<\/p>\n\n\n\n<p><strong>B\u1ea1n n\u00ean s\u1eed d\u1ee5ng Spring Cloud khi:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>X\u00e2y d\u1ef1ng ki\u1ebfn tr\u00fac Microservices:<\/strong> \u0110\u00e2y l\u00e0 l\u00fd do t\u1ed3n t\u1ea1i ch\u00ednh c\u1ee7a Spring Cloud. N\u1ebfu b\u1ea1n \u0111ang x\u00e2y d\u1ef1ng m\u1ed9t h\u1ec7 th\u1ed1ng g\u1ed3m nhi\u1ec1u d\u1ecbch v\u1ee5 nh\u1ecf, \u0111\u1ed9c l\u1eadp c\u1ea7n giao ti\u1ebfp v\u00e0 ph\u1ed1i h\u1ee3p v\u1edbi nhau, Spring Cloud cung c\u1ea5p m\u1ed9t b\u1ed9 gi\u1ea3i ph\u00e1p \u0111\u00e3 \u0111\u01b0\u1ee3c chu\u1ea9n h\u00f3a.<\/li>\n\n\n\n<li><strong>H\u1ec7 th\u1ed1ng c\u00f3 y\u00eau c\u1ea7u ph\u1ee9c t\u1ea1p v\u1ec1 v\u1eadn h\u00e0nh:<\/strong> Khi b\u1ea1n c\u1ea7n gi\u1ea3i quy\u1ebft c\u00e1c b\u00e0i to\u00e1n nh\u01b0 kh\u00e1m ph\u00e1 d\u1ecbch v\u1ee5 (service discovery), qu\u1ea3n l\u00fd c\u1ea5u h\u00ecnh t\u1eadp trung, kh\u1ea3 n\u0103ng ch\u1ecbu l\u1ed7i (fault tolerance), \u0111\u1ecbnh tuy\u1ebfn th\u00f4ng minh&#8230; Spring Cloud l\u00e0 m\u1ed9t l\u1ef1a ch\u1ecdn tuy\u1ec7t v\u1eddi.<\/li>\n\n\n\n<li><strong>\u0110\u1ed9i ng\u0169 \u0111\u00e3 quen thu\u1ed9c v\u1edbi Spring Boot:<\/strong> Spring Cloud t\u00edch h\u1ee3p m\u1ed9t c\u00e1ch t\u1ef1 nhi\u00ean v\u00e0 li\u1ec1n m\u1ea1ch v\u1edbi Spring Boot. N\u1ebfu team c\u1ee7a b\u1ea1n \u0111\u00e3 c\u00f3 kinh nghi\u1ec7m v\u1edbi Spring, vi\u1ec7c ti\u1ebfp c\u1eadn Spring Cloud s\u1ebd r\u1ea5t nhanh ch\u00f3ng v\u00e0 hi\u1ec7u qu\u1ea3.<\/li>\n<\/ul>\n\n\n\n<p><strong>B\u1ea1n n\u00ean c\u00e2n nh\u1eafc l\u1ea1i ho\u1eb7c kh\u00f4ng n\u00ean d\u00f9ng Spring Cloud khi:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>X\u00e2y d\u1ef1ng \u1ee9ng d\u1ee5ng nguy\u00ean kh\u1ed1i (Monolithic):<\/strong> N\u1ebfu \u1ee9ng d\u1ee5ng c\u1ee7a b\u1ea1n l\u00e0 m\u1ed9t kh\u1ed1i \u0111\u01a1n gi\u1ea3n, kh\u00f4ng c\u00f3 nhu c\u1ea7u chia t\u00e1ch th\u00e0nh c\u00e1c service, vi\u1ec7c th\u00eam Spring Cloud v\u00e0o ch\u1ec9 l\u00e0m t\u0103ng s\u1ef1 ph\u1ee9c t\u1ea1p m\u00e0 kh\u00f4ng mang l\u1ea1i l\u1ee3i \u00edch r\u00f5 r\u1ec7t.<\/li>\n\n\n\n<li><strong>D\u1ef1 \u00e1n qu\u00e1 nh\u1ecf ho\u1eb7c \u0111\u01a1n gi\u1ea3n:<\/strong> \u0110\u1ed1i v\u1edbi c\u00e1c \u1ee9ng d\u1ee5ng CRUD \u0111\u01a1n gi\u1ea3n ho\u1eb7c c\u00e1c c\u00f4ng c\u1ee5 d\u00f2ng l\u1ec7nh (CLI tools), vi\u1ec7c thi\u1ebft l\u1eadp c\u1ea3 m\u1ed9t h\u1ec7 sinh th\u00e1i Spring Cloud (nh\u01b0 Eureka Server, Config Server) l\u00e0 kh\u00f4ng c\u1ea7n thi\u1ebft v\u00e0 t\u1ed1n k\u00e9m t\u00e0i nguy\u00ean.<\/li>\n\n\n\n<li><strong>S\u1eed d\u1ee5ng n\u1ec1n t\u1ea3ng Cloud-Native \u0111\u00e3 c\u00f3 s\u1eb5n c\u00e1c gi\u1ea3i ph\u00e1p t\u01b0\u01a1ng t\u1ef1:<\/strong> C\u00e1c n\u1ec1n t\u1ea3ng nh\u01b0 Kubernetes cung c\u1ea5p c\u00e1c c\u01a1 ch\u1ebf ri\u00eang cho service discovery, configuration (qua ConfigMaps\/Secrets), v\u00e0 load balancing. Trong m\u00f4i tr\u01b0\u1eddng ho\u00e0n to\u00e0n l\u00e0 Kubernetes, b\u1ea1n c\u00f3 th\u1ec3 c\u00e2n nh\u1eafc s\u1eed d\u1ee5ng c\u00e1c gi\u1ea3i ph\u00e1p &#8220;thu\u1ea7n&#8221; c\u1ee7a n\u1ec1n t\u1ea3ng \u0111\u00f3 thay v\u00ec tri\u1ec3n khai th\u00eam c\u00e1c th\u00e0nh ph\u1ea7n c\u1ee7a Spring Cloud. Tuy nhi\u00ean, vi\u1ec7c k\u1ebft h\u1ee3p c\u1ea3 hai v\u1eabn l\u00e0 m\u1ed9t ph\u01b0\u01a1ng \u00e1n ph\u1ed5 bi\u1ebfn.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-lam-th\u1ebf-nao-d\u1ec3-cai-d\u1eb7t-spring-cloud\"><strong>L\u00e0m th\u1ebf n\u00e0o \u0111\u1ec3 c\u00e0i \u0111\u1eb7t Spring Cloud?<\/strong><\/h3>\n\n\n\n<p>M\u1ed9t hi\u1ec3u l\u1ea7m ph\u1ed5 bi\u1ebfn l\u00e0 xem Spring Cloud nh\u01b0 m\u1ed9t ph\u1ea7n m\u1ec1m c\u1ea7n &#8220;c\u00e0i \u0111\u1eb7t&#8221;. Th\u1ef1c t\u1ebf, b\u1ea1n kh\u00f4ng &#8220;c\u00e0i \u0111\u1eb7t&#8221; Spring Cloud. Thay v\u00e0o \u0111\u00f3, b\u1ea1n th\u00eam n\u00f3 v\u00e0o d\u1ef1 \u00e1n Spring Boot c\u1ee7a m\u00ecnh th\u00f4ng qua vi\u1ec7c qu\u1ea3n l\u00fd c\u00e1c dependency.<\/p>\n\n\n\n<p>Quy tr\u00ecnh chu\u1ea9n bao g\u1ed3m 3 b\u01b0\u1edbc:<\/p>\n\n\n\n<p><strong>B\u01b0\u1edbc 1: Khai b\u00e1o Spring Cloud BOM \u0111\u1ec3 qu\u1ea3n l\u00fd phi\u00ean b\u1ea3n<\/strong><\/p>\n\n\n\n<p>\u0110\u00e2y l\u00e0 b\u01b0\u1edbc quan tr\u1ecdng nh\u1ea5t \u0111\u1ec3 tr\u00e1nh xung \u0111\u1ed9t phi\u00ean b\u1ea3n. Trong file <code>pom.xml<\/code>, th\u00eam v\u00e0o trong th\u1ebb <code>&lt;dependencyManagement&gt;<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;dependencyManagement&gt;\n    &lt;dependencies&gt;\n        &lt;dependency&gt;\n            &lt;groupId&gt;org.springframework.cloud&lt;\/groupId&gt;\n            &lt;artifactId&gt;spring-cloud-dependencies&lt;\/artifactId&gt;\n            &lt;version&gt;2023.0.1&lt;\/version&gt; &lt;type&gt;pom&lt;\/type&gt;\n            &lt;scope&gt;import&lt;\/scope&gt;\n        &lt;\/dependency&gt;\n    &lt;\/dependencies&gt;\n&lt;\/dependencyManagement&gt;<\/code><\/pre>\n\n\n\n<p><strong>B\u01b0\u1edbc 2: Th\u00eam c\u00e1c &#8220;Starters&#8221; c\u1ea7n thi\u1ebft<\/strong><\/p>\n\n\n\n<p>D\u1ef1a tr\u00ean nhu c\u1ea7u c\u1ee7a b\u1ea1n, h\u00e3y th\u00eam c\u00e1c dependency t\u01b0\u01a1ng \u1ee9ng v\u00e0o th\u1ebb <code>&lt;dependencies&gt;<\/code>. V\u00ed d\u1ee5:<\/p>\n\n\n\n<p><strong>\u0110\u1ec3 d\u00f9ng Config Server:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;dependency&gt;\n    &lt;groupId&gt;org.springframework.cloud&lt;\/groupId&gt;\n    &lt;artifactId&gt;spring-cloud-config-server&lt;\/artifactId&gt;\n&lt;\/dependency&gt;<\/code><\/pre>\n\n\n\n<p><strong>\u0110\u1ec3 m\u1ed9t service tr\u1edf th\u00e0nh Eureka Client:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;dependency&gt;\n    &lt;groupId&gt;org.springframework.cloud&lt;\/groupId&gt;\n    &lt;artifactId&gt;spring-cloud-starter-netflix-eureka-client&lt;\/artifactId&gt;\n&lt;\/dependency&gt;<\/code><\/pre>\n\n\n\n<p><strong>\u0110\u1ec3 d\u00f9ng API Gateway:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;dependency&gt;\n    &lt;groupId&gt;org.springframework.cloud&lt;\/groupId&gt;\n    &lt;artifactId&gt;spring-cloud-starter-gateway&lt;\/artifactId&gt;\n&lt;\/dependency&gt;<\/code><\/pre>\n\n\n\n<p><strong>B\u01b0\u1edbc 3: C\u1ea5u h\u00ecnh v\u00e0 K\u00edch ho\u1ea1t<\/strong><\/p>\n\n\n\n<p>Sau khi \u0111\u00e3 th\u00eam dependency, b\u1ea1n ch\u1ec9 c\u1ea7n c\u1ea5u h\u00ecnh c\u00e1c thu\u1ed9c t\u00ednh c\u1ea7n thi\u1ebft trong <code>application.yml<\/code> (ho\u1eb7c <code>bootstrap.yml<\/code>) v\u00e0 th\u00eam c\u00e1c annotation k\u00edch ho\u1ea1t (<code>@Enable...<\/code>) n\u1ebfu c\u1ea7n, nh\u01b0 \u0111\u00e3 tr\u00ecnh b\u00e0y trong c\u00e1c ph\u1ea7n h\u01b0\u1edbng d\u1eabn th\u1ef1c h\u00e0nh.<\/p>\n\n\n\n<p>\u0110\u1ec3 b\u1eaft \u0111\u1ea7u m\u1ed9t d\u1ef1 \u00e1n m\u1edbi, c\u00e1ch d\u1ec5 nh\u1ea5t l\u00e0 s\u1eed d\u1ee5ng <strong>Spring Initializr (start.spring.io)<\/strong> v\u00e0 ch\u1ecdn c\u00e1c module Spring Cloud b\u1ea1n c\u1ea7n t\u1eeb danh s\u00e1ch.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-spring-cloud-bus-dung-d\u1ec3-lam-gi\"><strong>Spring Cloud Bus d\u00f9ng \u0111\u1ec3 l\u00e0m g\u00ec?<\/strong><\/h3>\n\n\n\n<p>Trong ph\u1ea7n h\u01b0\u1edbng d\u1eabn v\u1ec1 Config Server, ch\u00fang ta \u0111\u00e3 th\u1ef1c hi\u1ec7n refresh c\u1ea5u h\u00ecnh \u0111\u1ed9ng b\u1eb1ng c\u00e1ch g\u1ecdi m\u1ed9t API <code>POST<\/code> \u0111\u1ebfn endpoint <code>\/actuator\/refresh<\/code>. C\u00e1ch n\u00e0y ch\u1ec9 ho\u1ea1t \u0111\u1ed9ng cho m\u1ed9t instance duy nh\u1ea5t. V\u1eady n\u1ebfu h\u1ec7 th\u1ed1ng c\u00f3 10 instance c\u1ee7a <code>order-service<\/code> \u0111ang ch\u1ea1y, l\u00e0m sao \u0111\u1ec3 t\u1ea5t c\u1ea3 ch\u00fang c\u00f9ng c\u1eadp nh\u1eadt c\u1ea5u h\u00ecnh?<\/p>\n\n\n\n<p>\u0110\u00e2y ch\u00ednh l\u00e0 l\u00fac <strong>Spring Cloud Bus<\/strong> ph\u00e1t huy t\u00e1c d\u1ee5ng.<\/p>\n\n\n\n<p><strong>Spring Cloud Bus<\/strong> l\u00e0 m\u1ed9t project gi\u00fap li\u00ean k\u1ebft c\u00e1c node (instance) c\u1ee7a m\u1ed9t h\u1ec7 th\u1ed1ng ph\u00e2n t\u00e1n b\u1eb1ng m\u1ed9t message broker nh\u1eb9 (nh\u01b0 RabbitMQ ho\u1eb7c Kafka). N\u00f3 ho\u1ea1t \u0111\u1ed9ng nh\u01b0 m\u1ed9t k\u00eanh giao ti\u1ebfp chung.<\/p>\n\n\n\n<p><strong>C\u01a1 ch\u1ebf ho\u1ea1t \u0111\u1ed9ng:<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>T\u1ea5t c\u1ea3 c\u00e1c instance c\u1ee7a <code>order-service<\/code> \u0111\u1ec1u k\u1ebft n\u1ed1i v\u00e0o m\u1ed9t message broker.<\/li>\n\n\n\n<li>B\u1ea1n ch\u1ec9 c\u1ea7n g\u1eedi request <code>POST<\/code> \u0111\u1ebfn endpoint <code>\/actuator\/bus-refresh <\/code>c\u1ee7a <strong>b\u1ea5t k\u1ef3 m\u1ed9t instance n\u00e0o<\/strong>.<\/li>\n\n\n\n<li>Instance \u0111\u00f3 s\u1ebd g\u1eedi m\u1ed9t tin nh\u1eafn &#8220;refresh&#8221; l\u00ean message broker.<\/li>\n\n\n\n<li>T\u1ea5t c\u1ea3 c\u00e1c instance kh\u00e1c (bao g\u1ed3m c\u1ea3 ch\u00ednh n\u00f3) \u0111ang l\u1eafng nghe tr\u00ean k\u00eanh n\u00e0y s\u1ebd nh\u1eadn \u0111\u01b0\u1ee3c tin nh\u1eafn v\u00e0 \u0111\u1ed3ng lo\u1ea1t k\u00edch ho\u1ea1t qu\u00e1 tr\u00ecnh l\u00e0m m\u1edbi c\u1ea5u h\u00ecnh c\u1ee7a m\u00ecnh.<\/li>\n<\/ol>\n\n\n\n<p>T\u00f3m l\u1ea1i, <a href=\"https:\/\/spring.io\/projects\/spring-cloud-bus\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Spring Cloud Bus<\/strong> <\/a>gi\u00fap qu\u1ea3ng b\u00e1 c\u00e1c thay \u0111\u1ed5i v\u1ec1 tr\u1ea1ng th\u00e1i (ph\u1ed5 bi\u1ebfn nh\u1ea5t l\u00e0 thay \u0111\u1ed5i c\u1ea5u h\u00ecnh) \u0111\u1ebfn t\u1ea5t-c\u1ea3-c\u00e1c-instance c\u1ee7a m\u1ed9t service m\u1ed9t c\u00e1ch t\u1ef1 \u0111\u1ed9ng, thay v\u00ec ph\u1ea3i th\u1ef1c hi\u1ec7n th\u1ee7 c\u00f4ng tr\u00ean t\u1eebng instance.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"h-t\u1ed5ng-k\u1ebft\"><strong>T\u1ed5ng k\u1ebft<\/strong><\/h1>\n\n\n\n<p>Spring Cloud l\u00e0 b\u1ed9 c\u00f4ng c\u1ee5 k\u1ef9 thu\u1eadt gi\u00fap b\u1ea1n ch\u1ebf ng\u1ef1 s\u1ef1 ph\u1ee9c t\u1ea1p c\u1ee7a ki\u1ebfn tr\u00fac microservices. N\u00f3 cung c\u1ea5p c\u00e1c gi\u1ea3i ph\u00e1p \u0111\u00e3 \u0111\u01b0\u1ee3c chu\u1ea9n h\u00f3a cho nh\u1eefng b\u00e0i to\u00e1n kinh \u0111i\u1ec3n nh\u01b0 service discovery, qu\u1ea3n l\u00fd c\u1ea5u h\u00ecnh, \u0111\u1ecbnh tuy\u1ebfn v\u00e0 kh\u1ea3 n\u0103ng ch\u1ecbu l\u1ed7i. L\u1ee3i \u00edch l\u1edbn nh\u1ea5t m\u00e0 Spring Cloud mang l\u1ea1i l\u00e0 cho ph\u00e9p b\u1ea1n t\u1eadp trung v\u00e0o vi\u1ec7c x\u00e2y d\u1ef1ng <strong>logic nghi\u1ec7p v\u1ee5<\/strong>, thay v\u00ec ph\u1ea3i t\u1ef1 m\u00e0y m\u00f2 gi\u1ea3i quy\u1ebft c\u00e1c v\u1ea5n \u0111\u1ec1 h\u1ea1 t\u1ea7ng ph\u1ee9c t\u1ea1p. Hy v\u1ecdng b\u00e0i vi\u1ebft n\u00e0y \u0111\u00e3 cung c\u1ea5p m\u1ed9t n\u1ec1n t\u1ea3ng v\u1eefng ch\u1eafc \u0111\u1ec3 b\u1ea1n b\u1eaft \u0111\u1ea7u.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0110\u01b0\u1ee3c x\u00e2y d\u1ef1ng tr\u00ean n\u1ec1n t\u1ea3ng Spring Boot, Spring Cloud kh\u00f4ng ph\u1ea3i l\u00e0 m\u1ed9t framework m\u1edbi m\u00e0 l\u00e0 m\u1ed9t t\u1eadp h\u1ee3p c\u00e1c &#8220;v\u0169 kh\u00ed&#8221; gi\u00fap \u0111\u01a1n gi\u1ea3n h\u00f3a vi\u1ec7c x\u00e2y d\u1ef1ng v\u00e0 tri\u1ec3n khai \u1ee9ng d\u1ee5ng theo ki\u1ebfn tr\u00fac microservices b\u1eb1ng c\u00e1ch cung c\u1ea5p c\u00e1c gi\u1ea3i ph\u00e1p s\u1eb5n c\u00f3 cho nh\u1eefng b\u00e0i to\u00e1n ph\u1ed5 bi\u1ebfn. [&hellip;]<\/p>\n","protected":false},"author":203,"featured_media":92011,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_gspb_post_css":"","footnotes":""},"categories":[109,10350],"tags":[],"class_list":["post-91552","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-chuyen-mon-it","category-java"],"blocksy_meta":[],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.8 (Yoast SEO v27.7) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Spring Cloud: Chi ti\u1ebft c\u00e1ch tri\u1ec3n khai microservices \u0111\u01a1n gi\u1ea3n - ITviec Blog<\/title>\n<meta name=\"description\" content=\"Spring Cloud gi\u00fap ph\u00e1t tri\u1ec3n \u1ee9ng d\u1ee5ng microservices \u0111\u01a1n gi\u1ea3n h\u01a1n. T\u00ecm hi\u1ec3u v\u1ec1 c\u00e1ch Spring Cloud h\u1ed7 tr\u1ee3 l\u1eadp tr\u00ecnh vi\u00ean x\u1eeb l\u00fd h\u1ea1 t\u1ea7ng ph\u1ee9c t\u1ea1p.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/itviec.com\/blog\/spring-cloud-la-gi\/\" \/>\n<meta property=\"og:locale\" content=\"vi_VN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring Cloud: Chi ti\u1ebft c\u00e1ch tri\u1ec3n khai microservices \u0111\u01a1n gi\u1ea3n\" \/>\n<meta property=\"og:description\" content=\"\u0110\u01b0\u1ee3c x\u00e2y d\u1ef1ng tr\u00ean n\u1ec1n t\u1ea3ng Spring Boot, Spring Cloud kh\u00f4ng ph\u1ea3i l\u00e0 m\u1ed9t framework m\u1edbi m\u00e0 l\u00e0 m\u1ed9t t\u1eadp h\u1ee3p c\u00e1c &quot;v\u0169 kh\u00ed&quot; gi\u00fap \u0111\u01a1n gi\u1ea3n h\u00f3a vi\u1ec7c x\u00e2y d\u1ef1ng v\u00e0\" \/>\n<meta property=\"og:url\" content=\"https:\/\/itviec.com\/blog\/spring-cloud-la-gi\/\" \/>\n<meta property=\"og:site_name\" content=\"ITviec Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ITviec\" \/>\n<meta property=\"article:published_time\" content=\"2025-10-05T11:01:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-10-05T11:01:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/09\/spring-cloud-scaled.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2560\" \/>\n\t<meta property=\"og:image:height\" content=\"1347\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Tien Tran\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ITviec\" \/>\n<meta name=\"twitter:site\" content=\"@ITviec\" \/>\n<meta name=\"twitter:label1\" content=\"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi\" \/>\n\t<meta name=\"twitter:data1\" content=\"Tien Tran\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc\" \/>\n\t<meta name=\"twitter:data2\" content=\"29 ph\u00fat\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Spring Cloud: Chi ti\u1ebft c\u00e1ch tri\u1ec3n khai microservices \u0111\u01a1n gi\u1ea3n - ITviec Blog","description":"Spring Cloud gi\u00fap ph\u00e1t tri\u1ec3n \u1ee9ng d\u1ee5ng microservices \u0111\u01a1n gi\u1ea3n h\u01a1n. T\u00ecm hi\u1ec3u v\u1ec1 c\u00e1ch Spring Cloud h\u1ed7 tr\u1ee3 l\u1eadp tr\u00ecnh vi\u00ean x\u1eeb l\u00fd h\u1ea1 t\u1ea7ng ph\u1ee9c t\u1ea1p.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/itviec.com\/blog\/spring-cloud-la-gi\/","og_locale":"vi_VN","og_type":"article","og_title":"Spring Cloud: Chi ti\u1ebft c\u00e1ch tri\u1ec3n khai microservices \u0111\u01a1n gi\u1ea3n","og_description":"\u0110\u01b0\u1ee3c x\u00e2y d\u1ef1ng tr\u00ean n\u1ec1n t\u1ea3ng Spring Boot, Spring Cloud kh\u00f4ng ph\u1ea3i l\u00e0 m\u1ed9t framework m\u1edbi m\u00e0 l\u00e0 m\u1ed9t t\u1eadp h\u1ee3p c\u00e1c \"v\u0169 kh\u00ed\" gi\u00fap \u0111\u01a1n gi\u1ea3n h\u00f3a vi\u1ec7c x\u00e2y d\u1ef1ng v\u00e0","og_url":"https:\/\/itviec.com\/blog\/spring-cloud-la-gi\/","og_site_name":"ITviec Blog","article_publisher":"https:\/\/www.facebook.com\/ITviec","article_published_time":"2025-10-05T11:01:04+00:00","article_modified_time":"2025-10-05T11:01:07+00:00","og_image":[{"width":2560,"height":1347,"url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/09\/spring-cloud-scaled.png","type":"image\/png"}],"author":"Tien Tran","twitter_card":"summary_large_image","twitter_creator":"@ITviec","twitter_site":"@ITviec","twitter_misc":{"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi":"Tien Tran","\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc":"29 ph\u00fat"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/itviec.com\/blog\/spring-cloud-la-gi\/#article","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/spring-cloud-la-gi\/"},"author":{"name":"Tien Tran","@id":"https:\/\/itviec.com\/blog\/#\/schema\/person\/1595d671c49cfa2a48cd3c0a047a1298"},"headline":"Spring Cloud: Chi ti\u1ebft c\u00e1ch tri\u1ec3n khai microservices \u0111\u01a1n gi\u1ea3n","datePublished":"2025-10-05T11:01:04+00:00","dateModified":"2025-10-05T11:01:07+00:00","mainEntityOfPage":{"@id":"https:\/\/itviec.com\/blog\/spring-cloud-la-gi\/"},"wordCount":7653,"publisher":{"@id":"https:\/\/itviec.com\/blog\/#organization"},"image":{"@id":"https:\/\/itviec.com\/blog\/spring-cloud-la-gi\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/09\/spring-cloud-scaled.png","articleSection":["Chuy\u00ean m\u00f4n IT","Java"],"inLanguage":"vi"},{"@type":"WebPage","@id":"https:\/\/itviec.com\/blog\/spring-cloud-la-gi\/","url":"https:\/\/itviec.com\/blog\/spring-cloud-la-gi\/","name":"Spring Cloud: Chi ti\u1ebft c\u00e1ch tri\u1ec3n khai microservices \u0111\u01a1n gi\u1ea3n - ITviec Blog","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/itviec.com\/blog\/spring-cloud-la-gi\/#primaryimage"},"image":{"@id":"https:\/\/itviec.com\/blog\/spring-cloud-la-gi\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/09\/spring-cloud-scaled.png","datePublished":"2025-10-05T11:01:04+00:00","dateModified":"2025-10-05T11:01:07+00:00","description":"Spring Cloud gi\u00fap ph\u00e1t tri\u1ec3n \u1ee9ng d\u1ee5ng microservices \u0111\u01a1n gi\u1ea3n h\u01a1n. T\u00ecm hi\u1ec3u v\u1ec1 c\u00e1ch Spring Cloud h\u1ed7 tr\u1ee3 l\u1eadp tr\u00ecnh vi\u00ean x\u1eeb l\u00fd h\u1ea1 t\u1ea7ng ph\u1ee9c t\u1ea1p.","breadcrumb":{"@id":"https:\/\/itviec.com\/blog\/spring-cloud-la-gi\/#breadcrumb"},"inLanguage":"vi","potentialAction":[{"@type":"ReadAction","target":["https:\/\/itviec.com\/blog\/spring-cloud-la-gi\/"]}]},{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/spring-cloud-la-gi\/#primaryimage","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/09\/spring-cloud-scaled.png","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/09\/spring-cloud-scaled.png","width":800,"height":421,"caption":"spring cloud - itviec blog"},{"@type":"BreadcrumbList","@id":"https:\/\/itviec.com\/blog\/spring-cloud-la-gi\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Chuy\u00ean m\u00f4n IT","item":"https:\/\/itviec.com\/blog\/chuyen-mon-it\/"},{"@type":"ListItem","position":2,"name":"Spring Cloud: Chi ti\u1ebft c\u00e1ch tri\u1ec3n khai microservices \u0111\u01a1n gi\u1ea3n"}]},{"@type":"WebSite","@id":"https:\/\/itviec.com\/blog\/#website","url":"https:\/\/itviec.com\/blog\/","name":"ITviec Blog","description":"IT Jobs &amp; People in Vietnam","publisher":{"@id":"https:\/\/itviec.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/itviec.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"vi"},{"@type":"Organization","@id":"https:\/\/itviec.com\/blog\/#organization","name":"ITviec","url":"https:\/\/itviec.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2018\/12\/itviec-black-square-facebook.png","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2018\/12\/itviec-black-square-facebook.png","width":1800,"height":1800,"caption":"ITviec"},"image":{"@id":"https:\/\/itviec.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/ITviec","https:\/\/x.com\/ITviec","https:\/\/www.linkedin.com\/company\/itviec","https:\/\/www.youtube.com\/channel\/UCYthAQ3bcGr57M_ag5gHDvQ"]},{"@type":"Person","@id":"https:\/\/itviec.com\/blog\/#\/schema\/person\/1595d671c49cfa2a48cd3c0a047a1298","name":"Tien Tran","image":{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/05\/tien-tran-author-e1715658627643-100x100.jpg","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/05\/tien-tran-author-e1715658627643-100x100.jpg","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/05\/tien-tran-author-e1715658627643-100x100.jpg","caption":"Tien Tran"},"url":"https:\/\/itviec.com\/blog\/author\/tien-tran\/"}]}},"_links":{"self":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/91552","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/users\/203"}],"replies":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/comments?post=91552"}],"version-history":[{"count":4,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/91552\/revisions"}],"predecessor-version":[{"id":92012,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/91552\/revisions\/92012"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media\/92011"}],"wp:attachment":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media?parent=91552"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/categories?post=91552"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/tags?post=91552"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}