[{"data":1,"prerenderedAt":5055},["ShallowReactive",2],{"post-async-java-completable-vs-reactive":3,"rel-async-java-completable-vs-reactive":1873,"sib-async-java-completable-vs-reactive":4983},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"layout":11,"subtitle":12,"image":13,"optimized_image":13,"category":14,"tags":15,"author":20,"paginate":6,"body":21,"_type":1867,"_id":1868,"_source":1869,"_file":1870,"_stem":1871,"_extension":1872},"/posts/async-java-completable-vs-reactive","posts",false,"","Asynchronous Programming in Java: CompletableFuture vs Reactive Streams","A deep dive into asynchronous programming in Java comparing CompletableFuture and Reactive Streams, with examples and output.","2024-04-15T11:00:00.000Z","post","Choosing the Right Tool for Concurrency in Modern Java","/assets/img/uploads/java-async.png","code",[14,16,17,18,19],"java","asynchronous","reactive","concurrency","jaimedearcos",{"type":22,"children":23,"toc":1853},"root",[24,52,59,69,76,468,476,484,490,777,784,792,798,806,826,834,852,856,862,897,903,1208,1215,1223,1229,1563,1570,1578,1584,1591,1609,1616,1634,1637,1643,1772,1775,1781,1800,1805,1812,1847],{"type":25,"tag":26,"props":27,"children":28},"element","blockquote",{},[29],{"type":25,"tag":30,"props":31,"children":32},"p",{},[33,36,42,44,50],{"type":34,"value":35},"text","Asynchronous programming enables applications to execute non-blocking operations, crucial for performance in modern, concurrent systems. In Java, two powerful tools are commonly used: ",{"type":25,"tag":14,"props":37,"children":39},{"className":38},[],[40],{"type":34,"value":41},"CompletableFuture",{"type":34,"value":43}," and ",{"type":25,"tag":45,"props":46,"children":47},"strong",{},[48],{"type":34,"value":49},"Reactive Streams",{"type":34,"value":51}," (e.g., Project Reactor or RxJava). In this post, we’ll compare both approaches through real code examples and output results.",{"type":25,"tag":53,"props":54,"children":56},"h2",{"id":55},"_1-completablefuture-javas-built-in-promise-api",[57],{"type":34,"value":58},"1. CompletableFuture: Java’s Built-in Promise API",{"type":25,"tag":30,"props":60,"children":61},{},[62,67],{"type":25,"tag":14,"props":63,"children":65},{"className":64},[],[66],{"type":34,"value":41},{"type":34,"value":68}," is a class introduced in Java 8 to write asynchronous, non-blocking code. It's suitable for simple async flows and integrates well with imperative codebases.",{"type":25,"tag":70,"props":71,"children":73},"h3",{"id":72},"example-1-basic-async-execution",[74],{"type":34,"value":75},"Example 1: Basic Async Execution",{"type":25,"tag":77,"props":78,"children":81},"pre",{"code":79,"language":16,"meta":7,"className":80,"style":7},"import java.util.concurrent.CompletableFuture;\n\npublic class CompletableFutureDemo {\n    public static void main(String[] args) {\n        CompletableFuture\u003CString> future = CompletableFuture.supplyAsync(() -> {\n            sleep(1000);\n            return \"Hello from CompletableFuture!\";\n        });\n\n        future.thenAccept(System.out::println);\n        sleep(1500); // wait for completion\n    }\n\n    static void sleep(long millis) {\n        try { Thread.sleep(millis); } catch (InterruptedException e) { }\n    }\n}\n","language-java shiki shiki-themes github-dark github-light",[82],{"type":25,"tag":14,"props":83,"children":84},{"__ignoreMap":7},[85,103,113,138,188,235,259,279,288,296,325,354,363,371,407,451,459],{"type":25,"tag":86,"props":87,"children":90},"span",{"class":88,"line":89},"line",1,[91,97],{"type":25,"tag":86,"props":92,"children":94},{"style":93},"--shiki-default:#F97583;--shiki-light:#D73A49",[95],{"type":34,"value":96},"import",{"type":25,"tag":86,"props":98,"children":100},{"style":99},"--shiki-default:#E1E4E8;--shiki-light:#24292E",[101],{"type":34,"value":102}," java.util.concurrent.CompletableFuture;\n",{"type":25,"tag":86,"props":104,"children":106},{"class":88,"line":105},2,[107],{"type":25,"tag":86,"props":108,"children":110},{"emptyLinePlaceholder":109},true,[111],{"type":34,"value":112},"\n",{"type":25,"tag":86,"props":114,"children":116},{"class":88,"line":115},3,[117,122,127,133],{"type":25,"tag":86,"props":118,"children":119},{"style":93},[120],{"type":34,"value":121},"public",{"type":25,"tag":86,"props":123,"children":124},{"style":93},[125],{"type":34,"value":126}," class",{"type":25,"tag":86,"props":128,"children":130},{"style":129},"--shiki-default:#B392F0;--shiki-light:#6F42C1",[131],{"type":34,"value":132}," CompletableFutureDemo",{"type":25,"tag":86,"props":134,"children":135},{"style":99},[136],{"type":34,"value":137}," {\n",{"type":25,"tag":86,"props":139,"children":141},{"class":88,"line":140},4,[142,147,152,157,162,167,172,177,183],{"type":25,"tag":86,"props":143,"children":144},{"style":93},[145],{"type":34,"value":146},"    public",{"type":25,"tag":86,"props":148,"children":149},{"style":93},[150],{"type":34,"value":151}," static",{"type":25,"tag":86,"props":153,"children":154},{"style":93},[155],{"type":34,"value":156}," void",{"type":25,"tag":86,"props":158,"children":159},{"style":129},[160],{"type":34,"value":161}," main",{"type":25,"tag":86,"props":163,"children":164},{"style":99},[165],{"type":34,"value":166},"(",{"type":25,"tag":86,"props":168,"children":169},{"style":93},[170],{"type":34,"value":171},"String",{"type":25,"tag":86,"props":173,"children":174},{"style":99},[175],{"type":34,"value":176},"[] ",{"type":25,"tag":86,"props":178,"children":180},{"style":179},"--shiki-default:#FFAB70;--shiki-light:#E36209",[181],{"type":34,"value":182},"args",{"type":25,"tag":86,"props":184,"children":185},{"style":99},[186],{"type":34,"value":187},") {\n",{"type":25,"tag":86,"props":189,"children":191},{"class":88,"line":190},5,[192,197,201,206,211,216,221,226,231],{"type":25,"tag":86,"props":193,"children":194},{"style":99},[195],{"type":34,"value":196},"        CompletableFuture\u003C",{"type":25,"tag":86,"props":198,"children":199},{"style":93},[200],{"type":34,"value":171},{"type":25,"tag":86,"props":202,"children":203},{"style":99},[204],{"type":34,"value":205},"> future ",{"type":25,"tag":86,"props":207,"children":208},{"style":93},[209],{"type":34,"value":210},"=",{"type":25,"tag":86,"props":212,"children":213},{"style":99},[214],{"type":34,"value":215}," CompletableFuture.",{"type":25,"tag":86,"props":217,"children":218},{"style":129},[219],{"type":34,"value":220},"supplyAsync",{"type":25,"tag":86,"props":222,"children":223},{"style":99},[224],{"type":34,"value":225},"(() ",{"type":25,"tag":86,"props":227,"children":228},{"style":93},[229],{"type":34,"value":230},"->",{"type":25,"tag":86,"props":232,"children":233},{"style":99},[234],{"type":34,"value":137},{"type":25,"tag":86,"props":236,"children":238},{"class":88,"line":237},6,[239,244,248,254],{"type":25,"tag":86,"props":240,"children":241},{"style":129},[242],{"type":34,"value":243},"            sleep",{"type":25,"tag":86,"props":245,"children":246},{"style":99},[247],{"type":34,"value":166},{"type":25,"tag":86,"props":249,"children":251},{"style":250},"--shiki-default:#79B8FF;--shiki-light:#005CC5",[252],{"type":34,"value":253},"1000",{"type":25,"tag":86,"props":255,"children":256},{"style":99},[257],{"type":34,"value":258},");\n",{"type":25,"tag":86,"props":260,"children":262},{"class":88,"line":261},7,[263,268,274],{"type":25,"tag":86,"props":264,"children":265},{"style":93},[266],{"type":34,"value":267},"            return",{"type":25,"tag":86,"props":269,"children":271},{"style":270},"--shiki-default:#9ECBFF;--shiki-light:#032F62",[272],{"type":34,"value":273}," \"Hello from CompletableFuture!\"",{"type":25,"tag":86,"props":275,"children":276},{"style":99},[277],{"type":34,"value":278},";\n",{"type":25,"tag":86,"props":280,"children":282},{"class":88,"line":281},8,[283],{"type":25,"tag":86,"props":284,"children":285},{"style":99},[286],{"type":34,"value":287},"        });\n",{"type":25,"tag":86,"props":289,"children":291},{"class":88,"line":290},9,[292],{"type":25,"tag":86,"props":293,"children":294},{"emptyLinePlaceholder":109},[295],{"type":34,"value":112},{"type":25,"tag":86,"props":297,"children":299},{"class":88,"line":298},10,[300,305,310,315,320],{"type":25,"tag":86,"props":301,"children":302},{"style":99},[303],{"type":34,"value":304},"        future.",{"type":25,"tag":86,"props":306,"children":307},{"style":129},[308],{"type":34,"value":309},"thenAccept",{"type":25,"tag":86,"props":311,"children":312},{"style":99},[313],{"type":34,"value":314},"(System.out",{"type":25,"tag":86,"props":316,"children":317},{"style":93},[318],{"type":34,"value":319},"::",{"type":25,"tag":86,"props":321,"children":322},{"style":99},[323],{"type":34,"value":324},"println);\n",{"type":25,"tag":86,"props":326,"children":328},{"class":88,"line":327},11,[329,334,338,343,348],{"type":25,"tag":86,"props":330,"children":331},{"style":129},[332],{"type":34,"value":333},"        sleep",{"type":25,"tag":86,"props":335,"children":336},{"style":99},[337],{"type":34,"value":166},{"type":25,"tag":86,"props":339,"children":340},{"style":250},[341],{"type":34,"value":342},"1500",{"type":25,"tag":86,"props":344,"children":345},{"style":99},[346],{"type":34,"value":347},"); ",{"type":25,"tag":86,"props":349,"children":351},{"style":350},"--shiki-default:#6A737D;--shiki-light:#6A737D",[352],{"type":34,"value":353},"// wait for completion\n",{"type":25,"tag":86,"props":355,"children":357},{"class":88,"line":356},12,[358],{"type":25,"tag":86,"props":359,"children":360},{"style":99},[361],{"type":34,"value":362},"    }\n",{"type":25,"tag":86,"props":364,"children":366},{"class":88,"line":365},13,[367],{"type":25,"tag":86,"props":368,"children":369},{"emptyLinePlaceholder":109},[370],{"type":34,"value":112},{"type":25,"tag":86,"props":372,"children":374},{"class":88,"line":373},14,[375,380,384,389,393,398,403],{"type":25,"tag":86,"props":376,"children":377},{"style":93},[378],{"type":34,"value":379},"    static",{"type":25,"tag":86,"props":381,"children":382},{"style":93},[383],{"type":34,"value":156},{"type":25,"tag":86,"props":385,"children":386},{"style":129},[387],{"type":34,"value":388}," sleep",{"type":25,"tag":86,"props":390,"children":391},{"style":99},[392],{"type":34,"value":166},{"type":25,"tag":86,"props":394,"children":395},{"style":93},[396],{"type":34,"value":397},"long",{"type":25,"tag":86,"props":399,"children":400},{"style":179},[401],{"type":34,"value":402}," millis",{"type":25,"tag":86,"props":404,"children":405},{"style":99},[406],{"type":34,"value":187},{"type":25,"tag":86,"props":408,"children":410},{"class":88,"line":409},15,[411,416,421,426,431,436,441,446],{"type":25,"tag":86,"props":412,"children":413},{"style":93},[414],{"type":34,"value":415},"        try",{"type":25,"tag":86,"props":417,"children":418},{"style":99},[419],{"type":34,"value":420}," { Thread.",{"type":25,"tag":86,"props":422,"children":423},{"style":129},[424],{"type":34,"value":425},"sleep",{"type":25,"tag":86,"props":427,"children":428},{"style":99},[429],{"type":34,"value":430},"(millis); } ",{"type":25,"tag":86,"props":432,"children":433},{"style":93},[434],{"type":34,"value":435},"catch",{"type":25,"tag":86,"props":437,"children":438},{"style":99},[439],{"type":34,"value":440}," (InterruptedException ",{"type":25,"tag":86,"props":442,"children":443},{"style":179},[444],{"type":34,"value":445},"e",{"type":25,"tag":86,"props":447,"children":448},{"style":99},[449],{"type":34,"value":450},") { }\n",{"type":25,"tag":86,"props":452,"children":454},{"class":88,"line":453},16,[455],{"type":25,"tag":86,"props":456,"children":457},{"style":99},[458],{"type":34,"value":362},{"type":25,"tag":86,"props":460,"children":462},{"class":88,"line":461},17,[463],{"type":25,"tag":86,"props":464,"children":465},{"style":99},[466],{"type":34,"value":467},"}\n",{"type":25,"tag":30,"props":469,"children":470},{},[471],{"type":25,"tag":45,"props":472,"children":473},{},[474],{"type":34,"value":475},"Output:",{"type":25,"tag":77,"props":477,"children":479},{"code":478},"Hello from CompletableFuture!\n",[480],{"type":25,"tag":14,"props":481,"children":482},{"__ignoreMap":7},[483],{"type":34,"value":478},{"type":25,"tag":70,"props":485,"children":487},{"id":486},"example-2-chaining-and-combining",[488],{"type":34,"value":489},"Example 2: Chaining and Combining",{"type":25,"tag":77,"props":491,"children":493},{"code":492,"language":16,"meta":7,"className":80,"style":7},"import java.util.concurrent.CompletableFuture;\n\npublic class CompletableFutureCombineDemo {\n    public static void main(String[] args) {\n        CompletableFuture\u003CString> greeting = CompletableFuture.supplyAsync(() -> \"Hello\");\n        CompletableFuture\u003CString> name = CompletableFuture.supplyAsync(() -> \"World\");\n\n        CompletableFuture\u003CString> result = greeting.thenCombine(name, (g, n) -> g + \", \" + n);\n        System.out.println(result.join());\n    }\n}\n",[494],{"type":25,"tag":14,"props":495,"children":496},{"__ignoreMap":7},[497,508,515,535,574,619,664,671,735,763,770],{"type":25,"tag":86,"props":498,"children":499},{"class":88,"line":89},[500,504],{"type":25,"tag":86,"props":501,"children":502},{"style":93},[503],{"type":34,"value":96},{"type":25,"tag":86,"props":505,"children":506},{"style":99},[507],{"type":34,"value":102},{"type":25,"tag":86,"props":509,"children":510},{"class":88,"line":105},[511],{"type":25,"tag":86,"props":512,"children":513},{"emptyLinePlaceholder":109},[514],{"type":34,"value":112},{"type":25,"tag":86,"props":516,"children":517},{"class":88,"line":115},[518,522,526,531],{"type":25,"tag":86,"props":519,"children":520},{"style":93},[521],{"type":34,"value":121},{"type":25,"tag":86,"props":523,"children":524},{"style":93},[525],{"type":34,"value":126},{"type":25,"tag":86,"props":527,"children":528},{"style":129},[529],{"type":34,"value":530}," CompletableFutureCombineDemo",{"type":25,"tag":86,"props":532,"children":533},{"style":99},[534],{"type":34,"value":137},{"type":25,"tag":86,"props":536,"children":537},{"class":88,"line":140},[538,542,546,550,554,558,562,566,570],{"type":25,"tag":86,"props":539,"children":540},{"style":93},[541],{"type":34,"value":146},{"type":25,"tag":86,"props":543,"children":544},{"style":93},[545],{"type":34,"value":151},{"type":25,"tag":86,"props":547,"children":548},{"style":93},[549],{"type":34,"value":156},{"type":25,"tag":86,"props":551,"children":552},{"style":129},[553],{"type":34,"value":161},{"type":25,"tag":86,"props":555,"children":556},{"style":99},[557],{"type":34,"value":166},{"type":25,"tag":86,"props":559,"children":560},{"style":93},[561],{"type":34,"value":171},{"type":25,"tag":86,"props":563,"children":564},{"style":99},[565],{"type":34,"value":176},{"type":25,"tag":86,"props":567,"children":568},{"style":179},[569],{"type":34,"value":182},{"type":25,"tag":86,"props":571,"children":572},{"style":99},[573],{"type":34,"value":187},{"type":25,"tag":86,"props":575,"children":576},{"class":88,"line":190},[577,581,585,590,594,598,602,606,610,615],{"type":25,"tag":86,"props":578,"children":579},{"style":99},[580],{"type":34,"value":196},{"type":25,"tag":86,"props":582,"children":583},{"style":93},[584],{"type":34,"value":171},{"type":25,"tag":86,"props":586,"children":587},{"style":99},[588],{"type":34,"value":589},"> greeting ",{"type":25,"tag":86,"props":591,"children":592},{"style":93},[593],{"type":34,"value":210},{"type":25,"tag":86,"props":595,"children":596},{"style":99},[597],{"type":34,"value":215},{"type":25,"tag":86,"props":599,"children":600},{"style":129},[601],{"type":34,"value":220},{"type":25,"tag":86,"props":603,"children":604},{"style":99},[605],{"type":34,"value":225},{"type":25,"tag":86,"props":607,"children":608},{"style":93},[609],{"type":34,"value":230},{"type":25,"tag":86,"props":611,"children":612},{"style":270},[613],{"type":34,"value":614}," \"Hello\"",{"type":25,"tag":86,"props":616,"children":617},{"style":99},[618],{"type":34,"value":258},{"type":25,"tag":86,"props":620,"children":621},{"class":88,"line":237},[622,626,630,635,639,643,647,651,655,660],{"type":25,"tag":86,"props":623,"children":624},{"style":99},[625],{"type":34,"value":196},{"type":25,"tag":86,"props":627,"children":628},{"style":93},[629],{"type":34,"value":171},{"type":25,"tag":86,"props":631,"children":632},{"style":99},[633],{"type":34,"value":634},"> name ",{"type":25,"tag":86,"props":636,"children":637},{"style":93},[638],{"type":34,"value":210},{"type":25,"tag":86,"props":640,"children":641},{"style":99},[642],{"type":34,"value":215},{"type":25,"tag":86,"props":644,"children":645},{"style":129},[646],{"type":34,"value":220},{"type":25,"tag":86,"props":648,"children":649},{"style":99},[650],{"type":34,"value":225},{"type":25,"tag":86,"props":652,"children":653},{"style":93},[654],{"type":34,"value":230},{"type":25,"tag":86,"props":656,"children":657},{"style":270},[658],{"type":34,"value":659}," \"World\"",{"type":25,"tag":86,"props":661,"children":662},{"style":99},[663],{"type":34,"value":258},{"type":25,"tag":86,"props":665,"children":666},{"class":88,"line":261},[667],{"type":25,"tag":86,"props":668,"children":669},{"emptyLinePlaceholder":109},[670],{"type":34,"value":112},{"type":25,"tag":86,"props":672,"children":673},{"class":88,"line":281},[674,678,682,687,691,696,701,706,710,715,720,725,730],{"type":25,"tag":86,"props":675,"children":676},{"style":99},[677],{"type":34,"value":196},{"type":25,"tag":86,"props":679,"children":680},{"style":93},[681],{"type":34,"value":171},{"type":25,"tag":86,"props":683,"children":684},{"style":99},[685],{"type":34,"value":686},"> result ",{"type":25,"tag":86,"props":688,"children":689},{"style":93},[690],{"type":34,"value":210},{"type":25,"tag":86,"props":692,"children":693},{"style":99},[694],{"type":34,"value":695}," greeting.",{"type":25,"tag":86,"props":697,"children":698},{"style":129},[699],{"type":34,"value":700},"thenCombine",{"type":25,"tag":86,"props":702,"children":703},{"style":99},[704],{"type":34,"value":705},"(name, (g, n) ",{"type":25,"tag":86,"props":707,"children":708},{"style":93},[709],{"type":34,"value":230},{"type":25,"tag":86,"props":711,"children":712},{"style":99},[713],{"type":34,"value":714}," g ",{"type":25,"tag":86,"props":716,"children":717},{"style":93},[718],{"type":34,"value":719},"+",{"type":25,"tag":86,"props":721,"children":722},{"style":270},[723],{"type":34,"value":724}," \", \"",{"type":25,"tag":86,"props":726,"children":727},{"style":93},[728],{"type":34,"value":729}," +",{"type":25,"tag":86,"props":731,"children":732},{"style":99},[733],{"type":34,"value":734}," n);\n",{"type":25,"tag":86,"props":736,"children":737},{"class":88,"line":290},[738,743,748,753,758],{"type":25,"tag":86,"props":739,"children":740},{"style":99},[741],{"type":34,"value":742},"        System.out.",{"type":25,"tag":86,"props":744,"children":745},{"style":129},[746],{"type":34,"value":747},"println",{"type":25,"tag":86,"props":749,"children":750},{"style":99},[751],{"type":34,"value":752},"(result.",{"type":25,"tag":86,"props":754,"children":755},{"style":129},[756],{"type":34,"value":757},"join",{"type":25,"tag":86,"props":759,"children":760},{"style":99},[761],{"type":34,"value":762},"());\n",{"type":25,"tag":86,"props":764,"children":765},{"class":88,"line":298},[766],{"type":25,"tag":86,"props":767,"children":768},{"style":99},[769],{"type":34,"value":362},{"type":25,"tag":86,"props":771,"children":772},{"class":88,"line":327},[773],{"type":25,"tag":86,"props":774,"children":775},{"style":99},[776],{"type":34,"value":467},{"type":25,"tag":30,"props":778,"children":779},{},[780],{"type":25,"tag":45,"props":781,"children":782},{},[783],{"type":34,"value":475},{"type":25,"tag":77,"props":785,"children":787},{"code":786},"Hello, World\n",[788],{"type":25,"tag":14,"props":789,"children":790},{"__ignoreMap":7},[791],{"type":34,"value":786},{"type":25,"tag":70,"props":793,"children":795},{"id":794},"pros-and-cons-of-completablefuture",[796],{"type":34,"value":797},"Pros and Cons of CompletableFuture",{"type":25,"tag":30,"props":799,"children":800},{},[801],{"type":25,"tag":45,"props":802,"children":803},{},[804],{"type":34,"value":805},"Pros:",{"type":25,"tag":807,"props":808,"children":809},"ul",{},[810,816,821],{"type":25,"tag":811,"props":812,"children":813},"li",{},[814],{"type":34,"value":815},"Native Java API, no dependencies",{"type":25,"tag":811,"props":817,"children":818},{},[819],{"type":34,"value":820},"Familiar to imperative developers",{"type":25,"tag":811,"props":822,"children":823},{},[824],{"type":34,"value":825},"Easy for linear async flows",{"type":25,"tag":30,"props":827,"children":828},{},[829],{"type":25,"tag":45,"props":830,"children":831},{},[832],{"type":34,"value":833},"Cons:",{"type":25,"tag":807,"props":835,"children":836},{},[837,842,847],{"type":25,"tag":811,"props":838,"children":839},{},[840],{"type":34,"value":841},"Limited operators compared to reactive libraries",{"type":25,"tag":811,"props":843,"children":844},{},[845],{"type":34,"value":846},"Complex error handling in larger flows",{"type":25,"tag":811,"props":848,"children":849},{},[850],{"type":34,"value":851},"Not suitable for high-throughput event streams",{"type":25,"tag":853,"props":854,"children":855},"hr",{},[],{"type":25,"tag":53,"props":857,"children":859},{"id":858},"_2-reactive-streams-declarative-and-event-driven",[860],{"type":34,"value":861},"2. Reactive Streams: Declarative and Event-Driven",{"type":25,"tag":30,"props":863,"children":864},{},[865,867,872,874,880,882,888,890,895],{"type":34,"value":866},"Reactive programming models async execution as a stream of data. With libraries like ",{"type":25,"tag":45,"props":868,"children":869},{},[870],{"type":34,"value":871},"Project Reactor",{"type":34,"value":873}," (",{"type":25,"tag":14,"props":875,"children":877},{"className":876},[],[878],{"type":34,"value":879},"Mono",{"type":34,"value":881},", ",{"type":25,"tag":14,"props":883,"children":885},{"className":884},[],[886],{"type":34,"value":887},"Flux",{"type":34,"value":889},") or ",{"type":25,"tag":45,"props":891,"children":892},{},[893],{"type":34,"value":894},"RxJava",{"type":34,"value":896},", you can build pipelines to transform, filter, and combine async data.",{"type":25,"tag":70,"props":898,"children":900},{"id":899},"example-1-mono-single-async-value",[901],{"type":34,"value":902},"Example 1: Mono (Single Async Value)",{"type":25,"tag":77,"props":904,"children":906},{"code":905,"language":16,"meta":7,"className":80,"style":7},"import reactor.core.publisher.Mono;\nimport java.time.Duration;\n\npublic class ReactorMonoExample {\n    public static void main(String[] args) {\n        Mono.just(\"Hello from Mono!\")\n            .delayElement(Duration.ofMillis(500))\n            .subscribe(System.out::println);\n\n        sleep(1000);\n    }\n\n    static void sleep(long millis) {\n        try { Thread.sleep(millis); } catch (InterruptedException e) { }\n    }\n}\n",[907],{"type":25,"tag":14,"props":908,"children":909},{"__ignoreMap":7},[910,922,934,941,961,1000,1027,1064,1088,1095,1114,1121,1128,1159,1194,1201],{"type":25,"tag":86,"props":911,"children":912},{"class":88,"line":89},[913,917],{"type":25,"tag":86,"props":914,"children":915},{"style":93},[916],{"type":34,"value":96},{"type":25,"tag":86,"props":918,"children":919},{"style":99},[920],{"type":34,"value":921}," reactor.core.publisher.Mono;\n",{"type":25,"tag":86,"props":923,"children":924},{"class":88,"line":105},[925,929],{"type":25,"tag":86,"props":926,"children":927},{"style":93},[928],{"type":34,"value":96},{"type":25,"tag":86,"props":930,"children":931},{"style":99},[932],{"type":34,"value":933}," java.time.Duration;\n",{"type":25,"tag":86,"props":935,"children":936},{"class":88,"line":115},[937],{"type":25,"tag":86,"props":938,"children":939},{"emptyLinePlaceholder":109},[940],{"type":34,"value":112},{"type":25,"tag":86,"props":942,"children":943},{"class":88,"line":140},[944,948,952,957],{"type":25,"tag":86,"props":945,"children":946},{"style":93},[947],{"type":34,"value":121},{"type":25,"tag":86,"props":949,"children":950},{"style":93},[951],{"type":34,"value":126},{"type":25,"tag":86,"props":953,"children":954},{"style":129},[955],{"type":34,"value":956}," ReactorMonoExample",{"type":25,"tag":86,"props":958,"children":959},{"style":99},[960],{"type":34,"value":137},{"type":25,"tag":86,"props":962,"children":963},{"class":88,"line":190},[964,968,972,976,980,984,988,992,996],{"type":25,"tag":86,"props":965,"children":966},{"style":93},[967],{"type":34,"value":146},{"type":25,"tag":86,"props":969,"children":970},{"style":93},[971],{"type":34,"value":151},{"type":25,"tag":86,"props":973,"children":974},{"style":93},[975],{"type":34,"value":156},{"type":25,"tag":86,"props":977,"children":978},{"style":129},[979],{"type":34,"value":161},{"type":25,"tag":86,"props":981,"children":982},{"style":99},[983],{"type":34,"value":166},{"type":25,"tag":86,"props":985,"children":986},{"style":93},[987],{"type":34,"value":171},{"type":25,"tag":86,"props":989,"children":990},{"style":99},[991],{"type":34,"value":176},{"type":25,"tag":86,"props":993,"children":994},{"style":179},[995],{"type":34,"value":182},{"type":25,"tag":86,"props":997,"children":998},{"style":99},[999],{"type":34,"value":187},{"type":25,"tag":86,"props":1001,"children":1002},{"class":88,"line":237},[1003,1008,1013,1017,1022],{"type":25,"tag":86,"props":1004,"children":1005},{"style":99},[1006],{"type":34,"value":1007},"        Mono.",{"type":25,"tag":86,"props":1009,"children":1010},{"style":129},[1011],{"type":34,"value":1012},"just",{"type":25,"tag":86,"props":1014,"children":1015},{"style":99},[1016],{"type":34,"value":166},{"type":25,"tag":86,"props":1018,"children":1019},{"style":270},[1020],{"type":34,"value":1021},"\"Hello from Mono!\"",{"type":25,"tag":86,"props":1023,"children":1024},{"style":99},[1025],{"type":34,"value":1026},")\n",{"type":25,"tag":86,"props":1028,"children":1029},{"class":88,"line":261},[1030,1035,1040,1045,1050,1054,1059],{"type":25,"tag":86,"props":1031,"children":1032},{"style":99},[1033],{"type":34,"value":1034},"            .",{"type":25,"tag":86,"props":1036,"children":1037},{"style":129},[1038],{"type":34,"value":1039},"delayElement",{"type":25,"tag":86,"props":1041,"children":1042},{"style":99},[1043],{"type":34,"value":1044},"(Duration.",{"type":25,"tag":86,"props":1046,"children":1047},{"style":129},[1048],{"type":34,"value":1049},"ofMillis",{"type":25,"tag":86,"props":1051,"children":1052},{"style":99},[1053],{"type":34,"value":166},{"type":25,"tag":86,"props":1055,"children":1056},{"style":250},[1057],{"type":34,"value":1058},"500",{"type":25,"tag":86,"props":1060,"children":1061},{"style":99},[1062],{"type":34,"value":1063},"))\n",{"type":25,"tag":86,"props":1065,"children":1066},{"class":88,"line":281},[1067,1071,1076,1080,1084],{"type":25,"tag":86,"props":1068,"children":1069},{"style":99},[1070],{"type":34,"value":1034},{"type":25,"tag":86,"props":1072,"children":1073},{"style":129},[1074],{"type":34,"value":1075},"subscribe",{"type":25,"tag":86,"props":1077,"children":1078},{"style":99},[1079],{"type":34,"value":314},{"type":25,"tag":86,"props":1081,"children":1082},{"style":93},[1083],{"type":34,"value":319},{"type":25,"tag":86,"props":1085,"children":1086},{"style":99},[1087],{"type":34,"value":324},{"type":25,"tag":86,"props":1089,"children":1090},{"class":88,"line":290},[1091],{"type":25,"tag":86,"props":1092,"children":1093},{"emptyLinePlaceholder":109},[1094],{"type":34,"value":112},{"type":25,"tag":86,"props":1096,"children":1097},{"class":88,"line":298},[1098,1102,1106,1110],{"type":25,"tag":86,"props":1099,"children":1100},{"style":129},[1101],{"type":34,"value":333},{"type":25,"tag":86,"props":1103,"children":1104},{"style":99},[1105],{"type":34,"value":166},{"type":25,"tag":86,"props":1107,"children":1108},{"style":250},[1109],{"type":34,"value":253},{"type":25,"tag":86,"props":1111,"children":1112},{"style":99},[1113],{"type":34,"value":258},{"type":25,"tag":86,"props":1115,"children":1116},{"class":88,"line":327},[1117],{"type":25,"tag":86,"props":1118,"children":1119},{"style":99},[1120],{"type":34,"value":362},{"type":25,"tag":86,"props":1122,"children":1123},{"class":88,"line":356},[1124],{"type":25,"tag":86,"props":1125,"children":1126},{"emptyLinePlaceholder":109},[1127],{"type":34,"value":112},{"type":25,"tag":86,"props":1129,"children":1130},{"class":88,"line":365},[1131,1135,1139,1143,1147,1151,1155],{"type":25,"tag":86,"props":1132,"children":1133},{"style":93},[1134],{"type":34,"value":379},{"type":25,"tag":86,"props":1136,"children":1137},{"style":93},[1138],{"type":34,"value":156},{"type":25,"tag":86,"props":1140,"children":1141},{"style":129},[1142],{"type":34,"value":388},{"type":25,"tag":86,"props":1144,"children":1145},{"style":99},[1146],{"type":34,"value":166},{"type":25,"tag":86,"props":1148,"children":1149},{"style":93},[1150],{"type":34,"value":397},{"type":25,"tag":86,"props":1152,"children":1153},{"style":179},[1154],{"type":34,"value":402},{"type":25,"tag":86,"props":1156,"children":1157},{"style":99},[1158],{"type":34,"value":187},{"type":25,"tag":86,"props":1160,"children":1161},{"class":88,"line":373},[1162,1166,1170,1174,1178,1182,1186,1190],{"type":25,"tag":86,"props":1163,"children":1164},{"style":93},[1165],{"type":34,"value":415},{"type":25,"tag":86,"props":1167,"children":1168},{"style":99},[1169],{"type":34,"value":420},{"type":25,"tag":86,"props":1171,"children":1172},{"style":129},[1173],{"type":34,"value":425},{"type":25,"tag":86,"props":1175,"children":1176},{"style":99},[1177],{"type":34,"value":430},{"type":25,"tag":86,"props":1179,"children":1180},{"style":93},[1181],{"type":34,"value":435},{"type":25,"tag":86,"props":1183,"children":1184},{"style":99},[1185],{"type":34,"value":440},{"type":25,"tag":86,"props":1187,"children":1188},{"style":179},[1189],{"type":34,"value":445},{"type":25,"tag":86,"props":1191,"children":1192},{"style":99},[1193],{"type":34,"value":450},{"type":25,"tag":86,"props":1195,"children":1196},{"class":88,"line":409},[1197],{"type":25,"tag":86,"props":1198,"children":1199},{"style":99},[1200],{"type":34,"value":362},{"type":25,"tag":86,"props":1202,"children":1203},{"class":88,"line":453},[1204],{"type":25,"tag":86,"props":1205,"children":1206},{"style":99},[1207],{"type":34,"value":467},{"type":25,"tag":30,"props":1209,"children":1210},{},[1211],{"type":25,"tag":45,"props":1212,"children":1213},{},[1214],{"type":34,"value":475},{"type":25,"tag":77,"props":1216,"children":1218},{"code":1217},"Hello from Mono!\n",[1219],{"type":25,"tag":14,"props":1220,"children":1221},{"__ignoreMap":7},[1222],{"type":34,"value":1217},{"type":25,"tag":70,"props":1224,"children":1226},{"id":1225},"example-2-flux-multiple-async-events",[1227],{"type":34,"value":1228},"Example 2: Flux (Multiple Async Events)",{"type":25,"tag":77,"props":1230,"children":1232},{"code":1231,"language":16,"meta":7,"className":80,"style":7},"import reactor.core.publisher.Flux;\nimport java.time.Duration;\n\npublic class ReactorFluxExample {\n    public static void main(String[] args) {\n        Flux.interval(Duration.ofMillis(300))\n            .take(5)\n            .map(i -> \"Tick \" + i)\n            .subscribe(System.out::println);\n\n        sleep(2000);\n    }\n\n    static void sleep(long millis) {\n        try { Thread.sleep(millis); } catch (InterruptedException e) { }\n    }\n}\n",[1233],{"type":25,"tag":14,"props":1234,"children":1235},{"__ignoreMap":7},[1236,1248,1259,1266,1286,1325,1359,1384,1419,1442,1449,1469,1476,1483,1514,1549,1556],{"type":25,"tag":86,"props":1237,"children":1238},{"class":88,"line":89},[1239,1243],{"type":25,"tag":86,"props":1240,"children":1241},{"style":93},[1242],{"type":34,"value":96},{"type":25,"tag":86,"props":1244,"children":1245},{"style":99},[1246],{"type":34,"value":1247}," reactor.core.publisher.Flux;\n",{"type":25,"tag":86,"props":1249,"children":1250},{"class":88,"line":105},[1251,1255],{"type":25,"tag":86,"props":1252,"children":1253},{"style":93},[1254],{"type":34,"value":96},{"type":25,"tag":86,"props":1256,"children":1257},{"style":99},[1258],{"type":34,"value":933},{"type":25,"tag":86,"props":1260,"children":1261},{"class":88,"line":115},[1262],{"type":25,"tag":86,"props":1263,"children":1264},{"emptyLinePlaceholder":109},[1265],{"type":34,"value":112},{"type":25,"tag":86,"props":1267,"children":1268},{"class":88,"line":140},[1269,1273,1277,1282],{"type":25,"tag":86,"props":1270,"children":1271},{"style":93},[1272],{"type":34,"value":121},{"type":25,"tag":86,"props":1274,"children":1275},{"style":93},[1276],{"type":34,"value":126},{"type":25,"tag":86,"props":1278,"children":1279},{"style":129},[1280],{"type":34,"value":1281}," ReactorFluxExample",{"type":25,"tag":86,"props":1283,"children":1284},{"style":99},[1285],{"type":34,"value":137},{"type":25,"tag":86,"props":1287,"children":1288},{"class":88,"line":190},[1289,1293,1297,1301,1305,1309,1313,1317,1321],{"type":25,"tag":86,"props":1290,"children":1291},{"style":93},[1292],{"type":34,"value":146},{"type":25,"tag":86,"props":1294,"children":1295},{"style":93},[1296],{"type":34,"value":151},{"type":25,"tag":86,"props":1298,"children":1299},{"style":93},[1300],{"type":34,"value":156},{"type":25,"tag":86,"props":1302,"children":1303},{"style":129},[1304],{"type":34,"value":161},{"type":25,"tag":86,"props":1306,"children":1307},{"style":99},[1308],{"type":34,"value":166},{"type":25,"tag":86,"props":1310,"children":1311},{"style":93},[1312],{"type":34,"value":171},{"type":25,"tag":86,"props":1314,"children":1315},{"style":99},[1316],{"type":34,"value":176},{"type":25,"tag":86,"props":1318,"children":1319},{"style":179},[1320],{"type":34,"value":182},{"type":25,"tag":86,"props":1322,"children":1323},{"style":99},[1324],{"type":34,"value":187},{"type":25,"tag":86,"props":1326,"children":1327},{"class":88,"line":237},[1328,1333,1338,1342,1346,1350,1355],{"type":25,"tag":86,"props":1329,"children":1330},{"style":99},[1331],{"type":34,"value":1332},"        Flux.",{"type":25,"tag":86,"props":1334,"children":1335},{"style":129},[1336],{"type":34,"value":1337},"interval",{"type":25,"tag":86,"props":1339,"children":1340},{"style":99},[1341],{"type":34,"value":1044},{"type":25,"tag":86,"props":1343,"children":1344},{"style":129},[1345],{"type":34,"value":1049},{"type":25,"tag":86,"props":1347,"children":1348},{"style":99},[1349],{"type":34,"value":166},{"type":25,"tag":86,"props":1351,"children":1352},{"style":250},[1353],{"type":34,"value":1354},"300",{"type":25,"tag":86,"props":1356,"children":1357},{"style":99},[1358],{"type":34,"value":1063},{"type":25,"tag":86,"props":1360,"children":1361},{"class":88,"line":261},[1362,1366,1371,1375,1380],{"type":25,"tag":86,"props":1363,"children":1364},{"style":99},[1365],{"type":34,"value":1034},{"type":25,"tag":86,"props":1367,"children":1368},{"style":129},[1369],{"type":34,"value":1370},"take",{"type":25,"tag":86,"props":1372,"children":1373},{"style":99},[1374],{"type":34,"value":166},{"type":25,"tag":86,"props":1376,"children":1377},{"style":250},[1378],{"type":34,"value":1379},"5",{"type":25,"tag":86,"props":1381,"children":1382},{"style":99},[1383],{"type":34,"value":1026},{"type":25,"tag":86,"props":1385,"children":1386},{"class":88,"line":281},[1387,1391,1396,1401,1405,1410,1414],{"type":25,"tag":86,"props":1388,"children":1389},{"style":99},[1390],{"type":34,"value":1034},{"type":25,"tag":86,"props":1392,"children":1393},{"style":129},[1394],{"type":34,"value":1395},"map",{"type":25,"tag":86,"props":1397,"children":1398},{"style":99},[1399],{"type":34,"value":1400},"(i ",{"type":25,"tag":86,"props":1402,"children":1403},{"style":93},[1404],{"type":34,"value":230},{"type":25,"tag":86,"props":1406,"children":1407},{"style":270},[1408],{"type":34,"value":1409}," \"Tick \"",{"type":25,"tag":86,"props":1411,"children":1412},{"style":93},[1413],{"type":34,"value":729},{"type":25,"tag":86,"props":1415,"children":1416},{"style":99},[1417],{"type":34,"value":1418}," i)\n",{"type":25,"tag":86,"props":1420,"children":1421},{"class":88,"line":290},[1422,1426,1430,1434,1438],{"type":25,"tag":86,"props":1423,"children":1424},{"style":99},[1425],{"type":34,"value":1034},{"type":25,"tag":86,"props":1427,"children":1428},{"style":129},[1429],{"type":34,"value":1075},{"type":25,"tag":86,"props":1431,"children":1432},{"style":99},[1433],{"type":34,"value":314},{"type":25,"tag":86,"props":1435,"children":1436},{"style":93},[1437],{"type":34,"value":319},{"type":25,"tag":86,"props":1439,"children":1440},{"style":99},[1441],{"type":34,"value":324},{"type":25,"tag":86,"props":1443,"children":1444},{"class":88,"line":298},[1445],{"type":25,"tag":86,"props":1446,"children":1447},{"emptyLinePlaceholder":109},[1448],{"type":34,"value":112},{"type":25,"tag":86,"props":1450,"children":1451},{"class":88,"line":327},[1452,1456,1460,1465],{"type":25,"tag":86,"props":1453,"children":1454},{"style":129},[1455],{"type":34,"value":333},{"type":25,"tag":86,"props":1457,"children":1458},{"style":99},[1459],{"type":34,"value":166},{"type":25,"tag":86,"props":1461,"children":1462},{"style":250},[1463],{"type":34,"value":1464},"2000",{"type":25,"tag":86,"props":1466,"children":1467},{"style":99},[1468],{"type":34,"value":258},{"type":25,"tag":86,"props":1470,"children":1471},{"class":88,"line":356},[1472],{"type":25,"tag":86,"props":1473,"children":1474},{"style":99},[1475],{"type":34,"value":362},{"type":25,"tag":86,"props":1477,"children":1478},{"class":88,"line":365},[1479],{"type":25,"tag":86,"props":1480,"children":1481},{"emptyLinePlaceholder":109},[1482],{"type":34,"value":112},{"type":25,"tag":86,"props":1484,"children":1485},{"class":88,"line":373},[1486,1490,1494,1498,1502,1506,1510],{"type":25,"tag":86,"props":1487,"children":1488},{"style":93},[1489],{"type":34,"value":379},{"type":25,"tag":86,"props":1491,"children":1492},{"style":93},[1493],{"type":34,"value":156},{"type":25,"tag":86,"props":1495,"children":1496},{"style":129},[1497],{"type":34,"value":388},{"type":25,"tag":86,"props":1499,"children":1500},{"style":99},[1501],{"type":34,"value":166},{"type":25,"tag":86,"props":1503,"children":1504},{"style":93},[1505],{"type":34,"value":397},{"type":25,"tag":86,"props":1507,"children":1508},{"style":179},[1509],{"type":34,"value":402},{"type":25,"tag":86,"props":1511,"children":1512},{"style":99},[1513],{"type":34,"value":187},{"type":25,"tag":86,"props":1515,"children":1516},{"class":88,"line":409},[1517,1521,1525,1529,1533,1537,1541,1545],{"type":25,"tag":86,"props":1518,"children":1519},{"style":93},[1520],{"type":34,"value":415},{"type":25,"tag":86,"props":1522,"children":1523},{"style":99},[1524],{"type":34,"value":420},{"type":25,"tag":86,"props":1526,"children":1527},{"style":129},[1528],{"type":34,"value":425},{"type":25,"tag":86,"props":1530,"children":1531},{"style":99},[1532],{"type":34,"value":430},{"type":25,"tag":86,"props":1534,"children":1535},{"style":93},[1536],{"type":34,"value":435},{"type":25,"tag":86,"props":1538,"children":1539},{"style":99},[1540],{"type":34,"value":440},{"type":25,"tag":86,"props":1542,"children":1543},{"style":179},[1544],{"type":34,"value":445},{"type":25,"tag":86,"props":1546,"children":1547},{"style":99},[1548],{"type":34,"value":450},{"type":25,"tag":86,"props":1550,"children":1551},{"class":88,"line":453},[1552],{"type":25,"tag":86,"props":1553,"children":1554},{"style":99},[1555],{"type":34,"value":362},{"type":25,"tag":86,"props":1557,"children":1558},{"class":88,"line":461},[1559],{"type":25,"tag":86,"props":1560,"children":1561},{"style":99},[1562],{"type":34,"value":467},{"type":25,"tag":30,"props":1564,"children":1565},{},[1566],{"type":25,"tag":45,"props":1567,"children":1568},{},[1569],{"type":34,"value":475},{"type":25,"tag":77,"props":1571,"children":1573},{"code":1572},"Tick 0\nTick 1\nTick 2\nTick 3\nTick 4\n",[1574],{"type":25,"tag":14,"props":1575,"children":1576},{"__ignoreMap":7},[1577],{"type":34,"value":1572},{"type":25,"tag":70,"props":1579,"children":1581},{"id":1580},"pros-and-cons-of-reactive-streams",[1582],{"type":34,"value":1583},"Pros and Cons of Reactive Streams",{"type":25,"tag":30,"props":1585,"children":1586},{},[1587],{"type":25,"tag":45,"props":1588,"children":1589},{},[1590],{"type":34,"value":805},{"type":25,"tag":807,"props":1592,"children":1593},{},[1594,1599,1604],{"type":25,"tag":811,"props":1595,"children":1596},{},[1597],{"type":34,"value":1598},"Rich operator set for complex flows",{"type":25,"tag":811,"props":1600,"children":1601},{},[1602],{"type":34,"value":1603},"Built-in backpressure handling",{"type":25,"tag":811,"props":1605,"children":1606},{},[1607],{"type":34,"value":1608},"Ideal for data streams and event-driven apps",{"type":25,"tag":30,"props":1610,"children":1611},{},[1612],{"type":25,"tag":45,"props":1613,"children":1614},{},[1615],{"type":34,"value":833},{"type":25,"tag":807,"props":1617,"children":1618},{},[1619,1624,1629],{"type":25,"tag":811,"props":1620,"children":1621},{},[1622],{"type":34,"value":1623},"Requires learning new paradigm",{"type":25,"tag":811,"props":1625,"children":1626},{},[1627],{"type":34,"value":1628},"Can be overkill for simple use cases",{"type":25,"tag":811,"props":1630,"children":1631},{},[1632],{"type":34,"value":1633},"More dependencies (Reactor, RxJava)",{"type":25,"tag":853,"props":1635,"children":1636},{},[],{"type":25,"tag":53,"props":1638,"children":1640},{"id":1639},"_3-when-to-use-each",[1641],{"type":34,"value":1642},"3. When to Use Each?",{"type":25,"tag":1644,"props":1645,"children":1646},"table",{},[1647,1669],{"type":25,"tag":1648,"props":1649,"children":1650},"thead",{},[1651],{"type":25,"tag":1652,"props":1653,"children":1654},"tr",{},[1655,1661,1665],{"type":25,"tag":1656,"props":1657,"children":1658},"th",{},[1659],{"type":34,"value":1660},"Use Case",{"type":25,"tag":1656,"props":1662,"children":1663},{},[1664],{"type":34,"value":41},{"type":25,"tag":1656,"props":1666,"children":1667},{},[1668],{"type":34,"value":49},{"type":25,"tag":1670,"props":1671,"children":1672},"tbody",{},[1673,1692,1708,1724,1740,1756],{"type":25,"tag":1652,"props":1674,"children":1675},{},[1676,1682,1687],{"type":25,"tag":1677,"props":1678,"children":1679},"td",{},[1680],{"type":34,"value":1681},"Simple async call",{"type":25,"tag":1677,"props":1683,"children":1684},{},[1685],{"type":34,"value":1686},"✅",{"type":25,"tag":1677,"props":1688,"children":1689},{},[1690],{"type":34,"value":1691},"❌",{"type":25,"tag":1652,"props":1693,"children":1694},{},[1695,1700,1704],{"type":25,"tag":1677,"props":1696,"children":1697},{},[1698],{"type":34,"value":1699},"API call + transform",{"type":25,"tag":1677,"props":1701,"children":1702},{},[1703],{"type":34,"value":1686},{"type":25,"tag":1677,"props":1705,"children":1706},{},[1707],{"type":34,"value":1686},{"type":25,"tag":1652,"props":1709,"children":1710},{},[1711,1716,1720],{"type":25,"tag":1677,"props":1712,"children":1713},{},[1714],{"type":34,"value":1715},"Data pipeline (streaming)",{"type":25,"tag":1677,"props":1717,"children":1718},{},[1719],{"type":34,"value":1691},{"type":25,"tag":1677,"props":1721,"children":1722},{},[1723],{"type":34,"value":1686},{"type":25,"tag":1652,"props":1725,"children":1726},{},[1727,1732,1736],{"type":25,"tag":1677,"props":1728,"children":1729},{},[1730],{"type":34,"value":1731},"Reactive UI/backend",{"type":25,"tag":1677,"props":1733,"children":1734},{},[1735],{"type":34,"value":1691},{"type":25,"tag":1677,"props":1737,"children":1738},{},[1739],{"type":34,"value":1686},{"type":25,"tag":1652,"props":1741,"children":1742},{},[1743,1748,1752],{"type":25,"tag":1677,"props":1744,"children":1745},{},[1746],{"type":34,"value":1747},"Minimal dependencies",{"type":25,"tag":1677,"props":1749,"children":1750},{},[1751],{"type":34,"value":1686},{"type":25,"tag":1677,"props":1753,"children":1754},{},[1755],{"type":34,"value":1691},{"type":25,"tag":1652,"props":1757,"children":1758},{},[1759,1764,1768],{"type":25,"tag":1677,"props":1760,"children":1761},{},[1762],{"type":34,"value":1763},"Advanced composition",{"type":25,"tag":1677,"props":1765,"children":1766},{},[1767],{"type":34,"value":1691},{"type":25,"tag":1677,"props":1769,"children":1770},{},[1771],{"type":34,"value":1686},{"type":25,"tag":853,"props":1773,"children":1774},{},[],{"type":25,"tag":53,"props":1776,"children":1778},{"id":1777},"conclusion",[1779],{"type":34,"value":1780},"Conclusion",{"type":25,"tag":30,"props":1782,"children":1783},{},[1784,1786,1791,1793,1798],{"type":34,"value":1785},"Both ",{"type":25,"tag":14,"props":1787,"children":1789},{"className":1788},[],[1790],{"type":34,"value":41},{"type":34,"value":1792}," and Reactive Streams serve asynchronous needs, but they excel in different areas. For straightforward async calls, ",{"type":25,"tag":14,"props":1794,"children":1796},{"className":1795},[],[1797],{"type":34,"value":41},{"type":34,"value":1799}," is often enough. For complex, event-driven, and high-throughput systems, reactive programming shines.",{"type":25,"tag":30,"props":1801,"children":1802},{},[1803],{"type":34,"value":1804},"By mastering both, you’ll be ready to choose the right tool for every concurrency challenge in modern Java applications.",{"type":25,"tag":1806,"props":1807,"children":1809},"h1",{"id":1808},"further-reading",[1810],{"type":34,"value":1811},"Further Reading",{"type":25,"tag":807,"props":1813,"children":1814},{},[1815,1827,1837],{"type":25,"tag":811,"props":1816,"children":1817},{},[1818],{"type":25,"tag":1819,"props":1820,"children":1824},"a",{"href":1821,"rel":1822},"https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html",[1823],"nofollow",[1825],{"type":34,"value":1826},"CompletableFuture Javadoc",{"type":25,"tag":811,"props":1828,"children":1829},{},[1830],{"type":25,"tag":1819,"props":1831,"children":1834},{"href":1832,"rel":1833},"https://projectreactor.io/docs",[1823],[1835],{"type":34,"value":1836},"Project Reactor Documentation",{"type":25,"tag":811,"props":1838,"children":1839},{},[1840],{"type":25,"tag":1819,"props":1841,"children":1844},{"href":1842,"rel":1843},"https://www.reactivemanifesto.org/",[1823],[1845],{"type":34,"value":1846},"Reactive Manifesto",{"type":25,"tag":1848,"props":1849,"children":1850},"style",{},[1851],{"type":34,"value":1852},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}",{"title":7,"searchDepth":105,"depth":105,"links":1854},[1855,1860,1865,1866],{"id":55,"depth":105,"text":58,"children":1856},[1857,1858,1859],{"id":72,"depth":115,"text":75},{"id":486,"depth":115,"text":489},{"id":794,"depth":115,"text":797},{"id":858,"depth":105,"text":861,"children":1861},[1862,1863,1864],{"id":899,"depth":115,"text":902},{"id":1225,"depth":115,"text":1228},{"id":1580,"depth":115,"text":1583},{"id":1639,"depth":105,"text":1642},{"id":1777,"depth":105,"text":1780},"markdown","content:posts:async-java-completable-vs-reactive.md","content","posts/async-java-completable-vs-reactive.md","posts/async-java-completable-vs-reactive","md",[1874,3274,4174],{"_path":1875,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":1876,"description":1877,"date":1878,"layout":11,"subtitle":1879,"image":1880,"optimized_image":1880,"category":14,"tags":1881,"author":20,"paginate":6,"body":1887,"_type":1867,"_id":3271,"_source":1869,"_file":3272,"_stem":3273,"_extension":1872},"/posts/gpt-sql-integration","Implementa un analizador de consultas en lenguaje natural para bases de datos SQL con GPT","Aprende a implementar un sistema que convierte consultas en lenguaje natural en sentencias SQL usando OpenAI GPT, con un tutorial paso a paso y ejemplos prácticos.","2025-01-15T11:00:00.000Z","Transforma preguntas naturales en consultas SQL automatizadas","/assets/img/uploads/gpt-sql-integration.png",[14,1882,1883,1884,1885,1886],"gpt","openai","sql","ai","nlp",{"type":22,"children":1888,"toc":3260},[1889,1897,1903,1921,1927,1932,1974,1987,2003,2009,2014,2221,2227,2232,2564,2570,2575,2922,2928,2933,2992,2998,3003,3182,3188,3206,3212,3217,3223,3256],{"type":25,"tag":26,"props":1890,"children":1891},{},[1892],{"type":25,"tag":30,"props":1893,"children":1894},{},[1895],{"type":34,"value":1896},"Convertir preguntas naturales en consultas SQL de forma automática simplifica la interacción con bases de datos, permitiendo que usuarios sin conocimientos técnicos extraigan datos relevantes. En este tutorial, aprenderás a implementar esta solución utilizando la API de OpenAI GPT.",{"type":25,"tag":53,"props":1898,"children":1900},{"id":1899},"requisitos-previos",[1901],{"type":34,"value":1902},"Requisitos Previos",{"type":25,"tag":807,"props":1904,"children":1905},{},[1906,1911,1916],{"type":25,"tag":811,"props":1907,"children":1908},{},[1909],{"type":34,"value":1910},"Cuenta y clave API de OpenAI",{"type":25,"tag":811,"props":1912,"children":1913},{},[1914],{"type":34,"value":1915},"Python instalado en tu entorno",{"type":25,"tag":811,"props":1917,"children":1918},{},[1919],{"type":34,"value":1920},"Base de datos SQL (ej.: PostgreSQL, MySQL)",{"type":25,"tag":53,"props":1922,"children":1924},{"id":1923},"paso-1-configuración-del-entorno",[1925],{"type":34,"value":1926},"Paso 1: Configuración del entorno",{"type":25,"tag":30,"props":1928,"children":1929},{},[1930],{"type":34,"value":1931},"Primero, instala las dependencias necesarias:",{"type":25,"tag":77,"props":1933,"children":1937},{"className":1934,"code":1935,"language":1936,"meta":7,"style":7},"language-bash shiki shiki-themes github-dark github-light","pip install openai python-dotenv sqlalchemy psycopg2-binary\n","bash",[1938],{"type":25,"tag":14,"props":1939,"children":1940},{"__ignoreMap":7},[1941],{"type":25,"tag":86,"props":1942,"children":1943},{"class":88,"line":89},[1944,1949,1954,1959,1964,1969],{"type":25,"tag":86,"props":1945,"children":1946},{"style":129},[1947],{"type":34,"value":1948},"pip",{"type":25,"tag":86,"props":1950,"children":1951},{"style":270},[1952],{"type":34,"value":1953}," install",{"type":25,"tag":86,"props":1955,"children":1956},{"style":270},[1957],{"type":34,"value":1958}," openai",{"type":25,"tag":86,"props":1960,"children":1961},{"style":270},[1962],{"type":34,"value":1963}," python-dotenv",{"type":25,"tag":86,"props":1965,"children":1966},{"style":270},[1967],{"type":34,"value":1968}," sqlalchemy",{"type":25,"tag":86,"props":1970,"children":1971},{"style":270},[1972],{"type":34,"value":1973}," psycopg2-binary\n",{"type":25,"tag":30,"props":1975,"children":1976},{},[1977,1979,1985],{"type":34,"value":1978},"Guarda tu clave API en un archivo ",{"type":25,"tag":14,"props":1980,"children":1982},{"className":1981},[],[1983],{"type":34,"value":1984},".env",{"type":34,"value":1986},":",{"type":25,"tag":77,"props":1988,"children":1992},{"className":1989,"code":1990,"language":1991,"meta":7,"style":7},"language-env shiki shiki-themes github-dark github-light","OPENAI_API_KEY='tu-api-key'\n","env",[1993],{"type":25,"tag":14,"props":1994,"children":1995},{"__ignoreMap":7},[1996],{"type":25,"tag":86,"props":1997,"children":1998},{"class":88,"line":89},[1999],{"type":25,"tag":86,"props":2000,"children":2001},{},[2002],{"type":34,"value":1990},{"type":25,"tag":53,"props":2004,"children":2006},{"id":2005},"paso-2-conexión-a-la-base-de-datos",[2007],{"type":34,"value":2008},"Paso 2: Conexión a la base de datos",{"type":25,"tag":30,"props":2010,"children":2011},{},[2012],{"type":34,"value":2013},"Utiliza SQLAlchemy para conectarte a tu base de datos:",{"type":25,"tag":77,"props":2015,"children":2019},{"className":2016,"code":2017,"language":2018,"meta":7,"style":7},"language-python shiki shiki-themes github-dark github-light","from sqlalchemy import create_engine\nfrom sqlalchemy.orm import sessionmaker\nimport os\nfrom dotenv import load_dotenv\n\nload_dotenv()\n\nDATABASE_URL = os.getenv(\"DATABASE_URL\")\nengine = create_engine(DATABASE_URL)\nSession = sessionmaker(bind=engine)\nsession = Session()\n","python",[2020],{"type":25,"tag":14,"props":2021,"children":2022},{"__ignoreMap":7},[2023,2045,2066,2078,2099,2106,2114,2121,2148,2173,2204],{"type":25,"tag":86,"props":2024,"children":2025},{"class":88,"line":89},[2026,2031,2036,2040],{"type":25,"tag":86,"props":2027,"children":2028},{"style":93},[2029],{"type":34,"value":2030},"from",{"type":25,"tag":86,"props":2032,"children":2033},{"style":99},[2034],{"type":34,"value":2035}," sqlalchemy ",{"type":25,"tag":86,"props":2037,"children":2038},{"style":93},[2039],{"type":34,"value":96},{"type":25,"tag":86,"props":2041,"children":2042},{"style":99},[2043],{"type":34,"value":2044}," create_engine\n",{"type":25,"tag":86,"props":2046,"children":2047},{"class":88,"line":105},[2048,2052,2057,2061],{"type":25,"tag":86,"props":2049,"children":2050},{"style":93},[2051],{"type":34,"value":2030},{"type":25,"tag":86,"props":2053,"children":2054},{"style":99},[2055],{"type":34,"value":2056}," sqlalchemy.orm ",{"type":25,"tag":86,"props":2058,"children":2059},{"style":93},[2060],{"type":34,"value":96},{"type":25,"tag":86,"props":2062,"children":2063},{"style":99},[2064],{"type":34,"value":2065}," sessionmaker\n",{"type":25,"tag":86,"props":2067,"children":2068},{"class":88,"line":115},[2069,2073],{"type":25,"tag":86,"props":2070,"children":2071},{"style":93},[2072],{"type":34,"value":96},{"type":25,"tag":86,"props":2074,"children":2075},{"style":99},[2076],{"type":34,"value":2077}," os\n",{"type":25,"tag":86,"props":2079,"children":2080},{"class":88,"line":140},[2081,2085,2090,2094],{"type":25,"tag":86,"props":2082,"children":2083},{"style":93},[2084],{"type":34,"value":2030},{"type":25,"tag":86,"props":2086,"children":2087},{"style":99},[2088],{"type":34,"value":2089}," dotenv ",{"type":25,"tag":86,"props":2091,"children":2092},{"style":93},[2093],{"type":34,"value":96},{"type":25,"tag":86,"props":2095,"children":2096},{"style":99},[2097],{"type":34,"value":2098}," load_dotenv\n",{"type":25,"tag":86,"props":2100,"children":2101},{"class":88,"line":190},[2102],{"type":25,"tag":86,"props":2103,"children":2104},{"emptyLinePlaceholder":109},[2105],{"type":34,"value":112},{"type":25,"tag":86,"props":2107,"children":2108},{"class":88,"line":237},[2109],{"type":25,"tag":86,"props":2110,"children":2111},{"style":99},[2112],{"type":34,"value":2113},"load_dotenv()\n",{"type":25,"tag":86,"props":2115,"children":2116},{"class":88,"line":261},[2117],{"type":25,"tag":86,"props":2118,"children":2119},{"emptyLinePlaceholder":109},[2120],{"type":34,"value":112},{"type":25,"tag":86,"props":2122,"children":2123},{"class":88,"line":281},[2124,2129,2134,2139,2144],{"type":25,"tag":86,"props":2125,"children":2126},{"style":250},[2127],{"type":34,"value":2128},"DATABASE_URL",{"type":25,"tag":86,"props":2130,"children":2131},{"style":93},[2132],{"type":34,"value":2133}," =",{"type":25,"tag":86,"props":2135,"children":2136},{"style":99},[2137],{"type":34,"value":2138}," os.getenv(",{"type":25,"tag":86,"props":2140,"children":2141},{"style":270},[2142],{"type":34,"value":2143},"\"DATABASE_URL\"",{"type":25,"tag":86,"props":2145,"children":2146},{"style":99},[2147],{"type":34,"value":1026},{"type":25,"tag":86,"props":2149,"children":2150},{"class":88,"line":290},[2151,2156,2160,2165,2169],{"type":25,"tag":86,"props":2152,"children":2153},{"style":99},[2154],{"type":34,"value":2155},"engine ",{"type":25,"tag":86,"props":2157,"children":2158},{"style":93},[2159],{"type":34,"value":210},{"type":25,"tag":86,"props":2161,"children":2162},{"style":99},[2163],{"type":34,"value":2164}," create_engine(",{"type":25,"tag":86,"props":2166,"children":2167},{"style":250},[2168],{"type":34,"value":2128},{"type":25,"tag":86,"props":2170,"children":2171},{"style":99},[2172],{"type":34,"value":1026},{"type":25,"tag":86,"props":2174,"children":2175},{"class":88,"line":298},[2176,2181,2185,2190,2195,2199],{"type":25,"tag":86,"props":2177,"children":2178},{"style":99},[2179],{"type":34,"value":2180},"Session ",{"type":25,"tag":86,"props":2182,"children":2183},{"style":93},[2184],{"type":34,"value":210},{"type":25,"tag":86,"props":2186,"children":2187},{"style":99},[2188],{"type":34,"value":2189}," sessionmaker(",{"type":25,"tag":86,"props":2191,"children":2192},{"style":179},[2193],{"type":34,"value":2194},"bind",{"type":25,"tag":86,"props":2196,"children":2197},{"style":93},[2198],{"type":34,"value":210},{"type":25,"tag":86,"props":2200,"children":2201},{"style":99},[2202],{"type":34,"value":2203},"engine)\n",{"type":25,"tag":86,"props":2205,"children":2206},{"class":88,"line":327},[2207,2212,2216],{"type":25,"tag":86,"props":2208,"children":2209},{"style":99},[2210],{"type":34,"value":2211},"session ",{"type":25,"tag":86,"props":2213,"children":2214},{"style":93},[2215],{"type":34,"value":210},{"type":25,"tag":86,"props":2217,"children":2218},{"style":99},[2219],{"type":34,"value":2220}," Session()\n",{"type":25,"tag":53,"props":2222,"children":2224},{"id":2223},"paso-3-obtener-esquema-de-la-base-de-datos",[2225],{"type":34,"value":2226},"Paso 3: Obtener esquema de la base de datos",{"type":25,"tag":30,"props":2228,"children":2229},{},[2230],{"type":34,"value":2231},"Genera una descripción del esquema que será utilizada por GPT:",{"type":25,"tag":77,"props":2233,"children":2235},{"className":2016,"code":2234,"language":2018,"meta":7,"style":7},"from sqlalchemy import inspect\n\ndef get_database_schema(engine):\n    inspector = inspect(engine)\n    schema_description = \"\"\n    for table_name in inspector.get_table_names():\n        schema_description += f\"Table: {table_name}\\n\"\n        for column in inspector.get_columns(table_name):\n            schema_description += f\"- {column['name']} ({column['type']})\\n\"\n        schema_description += \"\\n\"\n    return schema_description\n\nschema_description = get_database_schema(engine)\nprint(schema_description)\n",[2236],{"type":25,"tag":14,"props":2237,"children":2238},{"__ignoreMap":7},[2239,2259,2266,2284,2301,2318,2341,2384,2406,2490,2514,2527,2534,2551],{"type":25,"tag":86,"props":2240,"children":2241},{"class":88,"line":89},[2242,2246,2250,2254],{"type":25,"tag":86,"props":2243,"children":2244},{"style":93},[2245],{"type":34,"value":2030},{"type":25,"tag":86,"props":2247,"children":2248},{"style":99},[2249],{"type":34,"value":2035},{"type":25,"tag":86,"props":2251,"children":2252},{"style":93},[2253],{"type":34,"value":96},{"type":25,"tag":86,"props":2255,"children":2256},{"style":99},[2257],{"type":34,"value":2258}," inspect\n",{"type":25,"tag":86,"props":2260,"children":2261},{"class":88,"line":105},[2262],{"type":25,"tag":86,"props":2263,"children":2264},{"emptyLinePlaceholder":109},[2265],{"type":34,"value":112},{"type":25,"tag":86,"props":2267,"children":2268},{"class":88,"line":115},[2269,2274,2279],{"type":25,"tag":86,"props":2270,"children":2271},{"style":93},[2272],{"type":34,"value":2273},"def",{"type":25,"tag":86,"props":2275,"children":2276},{"style":129},[2277],{"type":34,"value":2278}," get_database_schema",{"type":25,"tag":86,"props":2280,"children":2281},{"style":99},[2282],{"type":34,"value":2283},"(engine):\n",{"type":25,"tag":86,"props":2285,"children":2286},{"class":88,"line":140},[2287,2292,2296],{"type":25,"tag":86,"props":2288,"children":2289},{"style":99},[2290],{"type":34,"value":2291},"    inspector ",{"type":25,"tag":86,"props":2293,"children":2294},{"style":93},[2295],{"type":34,"value":210},{"type":25,"tag":86,"props":2297,"children":2298},{"style":99},[2299],{"type":34,"value":2300}," inspect(engine)\n",{"type":25,"tag":86,"props":2302,"children":2303},{"class":88,"line":190},[2304,2309,2313],{"type":25,"tag":86,"props":2305,"children":2306},{"style":99},[2307],{"type":34,"value":2308},"    schema_description ",{"type":25,"tag":86,"props":2310,"children":2311},{"style":93},[2312],{"type":34,"value":210},{"type":25,"tag":86,"props":2314,"children":2315},{"style":270},[2316],{"type":34,"value":2317}," \"\"\n",{"type":25,"tag":86,"props":2319,"children":2320},{"class":88,"line":237},[2321,2326,2331,2336],{"type":25,"tag":86,"props":2322,"children":2323},{"style":93},[2324],{"type":34,"value":2325},"    for",{"type":25,"tag":86,"props":2327,"children":2328},{"style":99},[2329],{"type":34,"value":2330}," table_name ",{"type":25,"tag":86,"props":2332,"children":2333},{"style":93},[2334],{"type":34,"value":2335},"in",{"type":25,"tag":86,"props":2337,"children":2338},{"style":99},[2339],{"type":34,"value":2340}," inspector.get_table_names():\n",{"type":25,"tag":86,"props":2342,"children":2343},{"class":88,"line":261},[2344,2349,2354,2359,2364,2369,2374,2379],{"type":25,"tag":86,"props":2345,"children":2346},{"style":99},[2347],{"type":34,"value":2348},"        schema_description ",{"type":25,"tag":86,"props":2350,"children":2351},{"style":93},[2352],{"type":34,"value":2353},"+=",{"type":25,"tag":86,"props":2355,"children":2356},{"style":93},[2357],{"type":34,"value":2358}," f",{"type":25,"tag":86,"props":2360,"children":2361},{"style":270},[2362],{"type":34,"value":2363},"\"Table: ",{"type":25,"tag":86,"props":2365,"children":2366},{"style":250},[2367],{"type":34,"value":2368},"{",{"type":25,"tag":86,"props":2370,"children":2371},{"style":99},[2372],{"type":34,"value":2373},"table_name",{"type":25,"tag":86,"props":2375,"children":2376},{"style":250},[2377],{"type":34,"value":2378},"}\\n",{"type":25,"tag":86,"props":2380,"children":2381},{"style":270},[2382],{"type":34,"value":2383},"\"\n",{"type":25,"tag":86,"props":2385,"children":2386},{"class":88,"line":281},[2387,2392,2397,2401],{"type":25,"tag":86,"props":2388,"children":2389},{"style":93},[2390],{"type":34,"value":2391},"        for",{"type":25,"tag":86,"props":2393,"children":2394},{"style":99},[2395],{"type":34,"value":2396}," column ",{"type":25,"tag":86,"props":2398,"children":2399},{"style":93},[2400],{"type":34,"value":2335},{"type":25,"tag":86,"props":2402,"children":2403},{"style":99},[2404],{"type":34,"value":2405}," inspector.get_columns(table_name):\n",{"type":25,"tag":86,"props":2407,"children":2408},{"class":88,"line":290},[2409,2414,2418,2422,2427,2431,2436,2441,2446,2451,2455,2459,2463,2468,2472,2476,2481,2486],{"type":25,"tag":86,"props":2410,"children":2411},{"style":99},[2412],{"type":34,"value":2413},"            schema_description ",{"type":25,"tag":86,"props":2415,"children":2416},{"style":93},[2417],{"type":34,"value":2353},{"type":25,"tag":86,"props":2419,"children":2420},{"style":93},[2421],{"type":34,"value":2358},{"type":25,"tag":86,"props":2423,"children":2424},{"style":270},[2425],{"type":34,"value":2426},"\"- ",{"type":25,"tag":86,"props":2428,"children":2429},{"style":250},[2430],{"type":34,"value":2368},{"type":25,"tag":86,"props":2432,"children":2433},{"style":99},[2434],{"type":34,"value":2435},"column[",{"type":25,"tag":86,"props":2437,"children":2438},{"style":270},[2439],{"type":34,"value":2440},"'name'",{"type":25,"tag":86,"props":2442,"children":2443},{"style":99},[2444],{"type":34,"value":2445},"]",{"type":25,"tag":86,"props":2447,"children":2448},{"style":250},[2449],{"type":34,"value":2450},"}",{"type":25,"tag":86,"props":2452,"children":2453},{"style":270},[2454],{"type":34,"value":873},{"type":25,"tag":86,"props":2456,"children":2457},{"style":250},[2458],{"type":34,"value":2368},{"type":25,"tag":86,"props":2460,"children":2461},{"style":99},[2462],{"type":34,"value":2435},{"type":25,"tag":86,"props":2464,"children":2465},{"style":270},[2466],{"type":34,"value":2467},"'type'",{"type":25,"tag":86,"props":2469,"children":2470},{"style":99},[2471],{"type":34,"value":2445},{"type":25,"tag":86,"props":2473,"children":2474},{"style":250},[2475],{"type":34,"value":2450},{"type":25,"tag":86,"props":2477,"children":2478},{"style":270},[2479],{"type":34,"value":2480},")",{"type":25,"tag":86,"props":2482,"children":2483},{"style":250},[2484],{"type":34,"value":2485},"\\n",{"type":25,"tag":86,"props":2487,"children":2488},{"style":270},[2489],{"type":34,"value":2383},{"type":25,"tag":86,"props":2491,"children":2492},{"class":88,"line":298},[2493,2497,2501,2506,2510],{"type":25,"tag":86,"props":2494,"children":2495},{"style":99},[2496],{"type":34,"value":2348},{"type":25,"tag":86,"props":2498,"children":2499},{"style":93},[2500],{"type":34,"value":2353},{"type":25,"tag":86,"props":2502,"children":2503},{"style":270},[2504],{"type":34,"value":2505}," \"",{"type":25,"tag":86,"props":2507,"children":2508},{"style":250},[2509],{"type":34,"value":2485},{"type":25,"tag":86,"props":2511,"children":2512},{"style":270},[2513],{"type":34,"value":2383},{"type":25,"tag":86,"props":2515,"children":2516},{"class":88,"line":327},[2517,2522],{"type":25,"tag":86,"props":2518,"children":2519},{"style":93},[2520],{"type":34,"value":2521},"    return",{"type":25,"tag":86,"props":2523,"children":2524},{"style":99},[2525],{"type":34,"value":2526}," schema_description\n",{"type":25,"tag":86,"props":2528,"children":2529},{"class":88,"line":356},[2530],{"type":25,"tag":86,"props":2531,"children":2532},{"emptyLinePlaceholder":109},[2533],{"type":34,"value":112},{"type":25,"tag":86,"props":2535,"children":2536},{"class":88,"line":365},[2537,2542,2546],{"type":25,"tag":86,"props":2538,"children":2539},{"style":99},[2540],{"type":34,"value":2541},"schema_description ",{"type":25,"tag":86,"props":2543,"children":2544},{"style":93},[2545],{"type":34,"value":210},{"type":25,"tag":86,"props":2547,"children":2548},{"style":99},[2549],{"type":34,"value":2550}," get_database_schema(engine)\n",{"type":25,"tag":86,"props":2552,"children":2553},{"class":88,"line":373},[2554,2559],{"type":25,"tag":86,"props":2555,"children":2556},{"style":250},[2557],{"type":34,"value":2558},"print",{"type":25,"tag":86,"props":2560,"children":2561},{"style":99},[2562],{"type":34,"value":2563},"(schema_description)\n",{"type":25,"tag":53,"props":2565,"children":2567},{"id":2566},"paso-4-preparar-la-consulta-con-gpt",[2568],{"type":34,"value":2569},"Paso 4: Preparar la consulta con GPT",{"type":25,"tag":30,"props":2571,"children":2572},{},[2573],{"type":34,"value":2574},"Utiliza la API de OpenAI para transformar preguntas en consultas SQL, incluyendo el esquema de la base de datos:",{"type":25,"tag":77,"props":2576,"children":2578},{"className":2016,"code":2577,"language":2018,"meta":7,"style":7},"import openai\nimport os\n\nopenai.api_key = os.getenv(\"OPENAI_API_KEY\")\n\ndef generate_sql(question, schema):\n    response = openai.ChatCompletion.create(\n        model=\"gpt-4\",\n        messages=[\n            {\"role\": \"system\", \"content\": f\"Convierte preguntas en lenguaje natural a consultas SQL. Esquema de la base de datos:\\n{schema}\"},\n            {\"role\": \"user\", \"content\": question}\n        ]\n    )\n    sql_query = response.choices[0].message.content.strip()\n    return sql_query\n\nquery = generate_sql(\"¿Cuántos usuarios se registraron el último mes?\", schema_description)\nprint(query)\n",[2579],{"type":25,"tag":14,"props":2580,"children":2581},{"__ignoreMap":7},[2582,2594,2605,2612,2637,2644,2661,2678,2700,2717,2787,2820,2828,2836,2863,2875,2882,2909],{"type":25,"tag":86,"props":2583,"children":2584},{"class":88,"line":89},[2585,2589],{"type":25,"tag":86,"props":2586,"children":2587},{"style":93},[2588],{"type":34,"value":96},{"type":25,"tag":86,"props":2590,"children":2591},{"style":99},[2592],{"type":34,"value":2593}," openai\n",{"type":25,"tag":86,"props":2595,"children":2596},{"class":88,"line":105},[2597,2601],{"type":25,"tag":86,"props":2598,"children":2599},{"style":93},[2600],{"type":34,"value":96},{"type":25,"tag":86,"props":2602,"children":2603},{"style":99},[2604],{"type":34,"value":2077},{"type":25,"tag":86,"props":2606,"children":2607},{"class":88,"line":115},[2608],{"type":25,"tag":86,"props":2609,"children":2610},{"emptyLinePlaceholder":109},[2611],{"type":34,"value":112},{"type":25,"tag":86,"props":2613,"children":2614},{"class":88,"line":140},[2615,2620,2624,2628,2633],{"type":25,"tag":86,"props":2616,"children":2617},{"style":99},[2618],{"type":34,"value":2619},"openai.api_key ",{"type":25,"tag":86,"props":2621,"children":2622},{"style":93},[2623],{"type":34,"value":210},{"type":25,"tag":86,"props":2625,"children":2626},{"style":99},[2627],{"type":34,"value":2138},{"type":25,"tag":86,"props":2629,"children":2630},{"style":270},[2631],{"type":34,"value":2632},"\"OPENAI_API_KEY\"",{"type":25,"tag":86,"props":2634,"children":2635},{"style":99},[2636],{"type":34,"value":1026},{"type":25,"tag":86,"props":2638,"children":2639},{"class":88,"line":190},[2640],{"type":25,"tag":86,"props":2641,"children":2642},{"emptyLinePlaceholder":109},[2643],{"type":34,"value":112},{"type":25,"tag":86,"props":2645,"children":2646},{"class":88,"line":237},[2647,2651,2656],{"type":25,"tag":86,"props":2648,"children":2649},{"style":93},[2650],{"type":34,"value":2273},{"type":25,"tag":86,"props":2652,"children":2653},{"style":129},[2654],{"type":34,"value":2655}," generate_sql",{"type":25,"tag":86,"props":2657,"children":2658},{"style":99},[2659],{"type":34,"value":2660},"(question, schema):\n",{"type":25,"tag":86,"props":2662,"children":2663},{"class":88,"line":261},[2664,2669,2673],{"type":25,"tag":86,"props":2665,"children":2666},{"style":99},[2667],{"type":34,"value":2668},"    response ",{"type":25,"tag":86,"props":2670,"children":2671},{"style":93},[2672],{"type":34,"value":210},{"type":25,"tag":86,"props":2674,"children":2675},{"style":99},[2676],{"type":34,"value":2677}," openai.ChatCompletion.create(\n",{"type":25,"tag":86,"props":2679,"children":2680},{"class":88,"line":281},[2681,2686,2690,2695],{"type":25,"tag":86,"props":2682,"children":2683},{"style":179},[2684],{"type":34,"value":2685},"        model",{"type":25,"tag":86,"props":2687,"children":2688},{"style":93},[2689],{"type":34,"value":210},{"type":25,"tag":86,"props":2691,"children":2692},{"style":270},[2693],{"type":34,"value":2694},"\"gpt-4\"",{"type":25,"tag":86,"props":2696,"children":2697},{"style":99},[2698],{"type":34,"value":2699},",\n",{"type":25,"tag":86,"props":2701,"children":2702},{"class":88,"line":290},[2703,2708,2712],{"type":25,"tag":86,"props":2704,"children":2705},{"style":179},[2706],{"type":34,"value":2707},"        messages",{"type":25,"tag":86,"props":2709,"children":2710},{"style":93},[2711],{"type":34,"value":210},{"type":25,"tag":86,"props":2713,"children":2714},{"style":99},[2715],{"type":34,"value":2716},"[\n",{"type":25,"tag":86,"props":2718,"children":2719},{"class":88,"line":298},[2720,2725,2730,2735,2740,2744,2749,2753,2758,2763,2768,2773,2777,2782],{"type":25,"tag":86,"props":2721,"children":2722},{"style":99},[2723],{"type":34,"value":2724},"            {",{"type":25,"tag":86,"props":2726,"children":2727},{"style":270},[2728],{"type":34,"value":2729},"\"role\"",{"type":25,"tag":86,"props":2731,"children":2732},{"style":99},[2733],{"type":34,"value":2734},": ",{"type":25,"tag":86,"props":2736,"children":2737},{"style":270},[2738],{"type":34,"value":2739},"\"system\"",{"type":25,"tag":86,"props":2741,"children":2742},{"style":99},[2743],{"type":34,"value":881},{"type":25,"tag":86,"props":2745,"children":2746},{"style":270},[2747],{"type":34,"value":2748},"\"content\"",{"type":25,"tag":86,"props":2750,"children":2751},{"style":99},[2752],{"type":34,"value":2734},{"type":25,"tag":86,"props":2754,"children":2755},{"style":93},[2756],{"type":34,"value":2757},"f",{"type":25,"tag":86,"props":2759,"children":2760},{"style":270},[2761],{"type":34,"value":2762},"\"Convierte preguntas en lenguaje natural a consultas SQL. Esquema de la base de datos:",{"type":25,"tag":86,"props":2764,"children":2765},{"style":250},[2766],{"type":34,"value":2767},"\\n{",{"type":25,"tag":86,"props":2769,"children":2770},{"style":99},[2771],{"type":34,"value":2772},"schema",{"type":25,"tag":86,"props":2774,"children":2775},{"style":250},[2776],{"type":34,"value":2450},{"type":25,"tag":86,"props":2778,"children":2779},{"style":270},[2780],{"type":34,"value":2781},"\"",{"type":25,"tag":86,"props":2783,"children":2784},{"style":99},[2785],{"type":34,"value":2786},"},\n",{"type":25,"tag":86,"props":2788,"children":2789},{"class":88,"line":327},[2790,2794,2798,2802,2807,2811,2815],{"type":25,"tag":86,"props":2791,"children":2792},{"style":99},[2793],{"type":34,"value":2724},{"type":25,"tag":86,"props":2795,"children":2796},{"style":270},[2797],{"type":34,"value":2729},{"type":25,"tag":86,"props":2799,"children":2800},{"style":99},[2801],{"type":34,"value":2734},{"type":25,"tag":86,"props":2803,"children":2804},{"style":270},[2805],{"type":34,"value":2806},"\"user\"",{"type":25,"tag":86,"props":2808,"children":2809},{"style":99},[2810],{"type":34,"value":881},{"type":25,"tag":86,"props":2812,"children":2813},{"style":270},[2814],{"type":34,"value":2748},{"type":25,"tag":86,"props":2816,"children":2817},{"style":99},[2818],{"type":34,"value":2819},": question}\n",{"type":25,"tag":86,"props":2821,"children":2822},{"class":88,"line":356},[2823],{"type":25,"tag":86,"props":2824,"children":2825},{"style":99},[2826],{"type":34,"value":2827},"        ]\n",{"type":25,"tag":86,"props":2829,"children":2830},{"class":88,"line":365},[2831],{"type":25,"tag":86,"props":2832,"children":2833},{"style":99},[2834],{"type":34,"value":2835},"    )\n",{"type":25,"tag":86,"props":2837,"children":2838},{"class":88,"line":373},[2839,2844,2848,2853,2858],{"type":25,"tag":86,"props":2840,"children":2841},{"style":99},[2842],{"type":34,"value":2843},"    sql_query ",{"type":25,"tag":86,"props":2845,"children":2846},{"style":93},[2847],{"type":34,"value":210},{"type":25,"tag":86,"props":2849,"children":2850},{"style":99},[2851],{"type":34,"value":2852}," response.choices[",{"type":25,"tag":86,"props":2854,"children":2855},{"style":250},[2856],{"type":34,"value":2857},"0",{"type":25,"tag":86,"props":2859,"children":2860},{"style":99},[2861],{"type":34,"value":2862},"].message.content.strip()\n",{"type":25,"tag":86,"props":2864,"children":2865},{"class":88,"line":409},[2866,2870],{"type":25,"tag":86,"props":2867,"children":2868},{"style":93},[2869],{"type":34,"value":2521},{"type":25,"tag":86,"props":2871,"children":2872},{"style":99},[2873],{"type":34,"value":2874}," sql_query\n",{"type":25,"tag":86,"props":2876,"children":2877},{"class":88,"line":453},[2878],{"type":25,"tag":86,"props":2879,"children":2880},{"emptyLinePlaceholder":109},[2881],{"type":34,"value":112},{"type":25,"tag":86,"props":2883,"children":2884},{"class":88,"line":461},[2885,2890,2894,2899,2904],{"type":25,"tag":86,"props":2886,"children":2887},{"style":99},[2888],{"type":34,"value":2889},"query ",{"type":25,"tag":86,"props":2891,"children":2892},{"style":93},[2893],{"type":34,"value":210},{"type":25,"tag":86,"props":2895,"children":2896},{"style":99},[2897],{"type":34,"value":2898}," generate_sql(",{"type":25,"tag":86,"props":2900,"children":2901},{"style":270},[2902],{"type":34,"value":2903},"\"¿Cuántos usuarios se registraron el último mes?\"",{"type":25,"tag":86,"props":2905,"children":2906},{"style":99},[2907],{"type":34,"value":2908},", schema_description)\n",{"type":25,"tag":86,"props":2910,"children":2912},{"class":88,"line":2911},18,[2913,2917],{"type":25,"tag":86,"props":2914,"children":2915},{"style":250},[2916],{"type":34,"value":2558},{"type":25,"tag":86,"props":2918,"children":2919},{"style":99},[2920],{"type":34,"value":2921},"(query)\n",{"type":25,"tag":53,"props":2923,"children":2925},{"id":2924},"paso-5-ejecutar-consultas-generadas",[2926],{"type":34,"value":2927},"Paso 5: Ejecutar consultas generadas",{"type":25,"tag":30,"props":2929,"children":2930},{},[2931],{"type":34,"value":2932},"Ejecuta la consulta generada y obtiene resultados:",{"type":25,"tag":77,"props":2934,"children":2936},{"className":2016,"code":2935,"language":2018,"meta":7,"style":7},"result = session.execute(query)\nfor row in result:\n    print(row)\n",[2937],{"type":25,"tag":14,"props":2938,"children":2939},{"__ignoreMap":7},[2940,2957,2979],{"type":25,"tag":86,"props":2941,"children":2942},{"class":88,"line":89},[2943,2948,2952],{"type":25,"tag":86,"props":2944,"children":2945},{"style":99},[2946],{"type":34,"value":2947},"result ",{"type":25,"tag":86,"props":2949,"children":2950},{"style":93},[2951],{"type":34,"value":210},{"type":25,"tag":86,"props":2953,"children":2954},{"style":99},[2955],{"type":34,"value":2956}," session.execute(query)\n",{"type":25,"tag":86,"props":2958,"children":2959},{"class":88,"line":105},[2960,2965,2970,2974],{"type":25,"tag":86,"props":2961,"children":2962},{"style":93},[2963],{"type":34,"value":2964},"for",{"type":25,"tag":86,"props":2966,"children":2967},{"style":99},[2968],{"type":34,"value":2969}," row ",{"type":25,"tag":86,"props":2971,"children":2972},{"style":93},[2973],{"type":34,"value":2335},{"type":25,"tag":86,"props":2975,"children":2976},{"style":99},[2977],{"type":34,"value":2978}," result:\n",{"type":25,"tag":86,"props":2980,"children":2981},{"class":88,"line":115},[2982,2987],{"type":25,"tag":86,"props":2983,"children":2984},{"style":250},[2985],{"type":34,"value":2986},"    print",{"type":25,"tag":86,"props":2988,"children":2989},{"style":99},[2990],{"type":34,"value":2991},"(row)\n",{"type":25,"tag":53,"props":2993,"children":2995},{"id":2994},"paso-6-manejo-de-errores-y-seguridad",[2996],{"type":34,"value":2997},"Paso 6: Manejo de errores y seguridad",{"type":25,"tag":30,"props":2999,"children":3000},{},[3001],{"type":34,"value":3002},"Para evitar problemas con consultas inseguras o errores, siempre valida las consultas generadas por GPT antes de ejecutarlas directamente:",{"type":25,"tag":77,"props":3004,"children":3006},{"className":2016,"code":3005,"language":2018,"meta":7,"style":7},"def execute_safe_query(sql_query):\n    try:\n        result = session.execute(sql_query)\n        return result.fetchall()\n    except Exception as e:\n        print(f\"Error al ejecutar consulta: {e}\")\n        return None\n\nresults = execute_safe_query(query)\nprint(results)\n",[3007],{"type":25,"tag":14,"props":3008,"children":3009},{"__ignoreMap":7},[3010,3027,3040,3057,3070,3093,3134,3146,3153,3170],{"type":25,"tag":86,"props":3011,"children":3012},{"class":88,"line":89},[3013,3017,3022],{"type":25,"tag":86,"props":3014,"children":3015},{"style":93},[3016],{"type":34,"value":2273},{"type":25,"tag":86,"props":3018,"children":3019},{"style":129},[3020],{"type":34,"value":3021}," execute_safe_query",{"type":25,"tag":86,"props":3023,"children":3024},{"style":99},[3025],{"type":34,"value":3026},"(sql_query):\n",{"type":25,"tag":86,"props":3028,"children":3029},{"class":88,"line":105},[3030,3035],{"type":25,"tag":86,"props":3031,"children":3032},{"style":93},[3033],{"type":34,"value":3034},"    try",{"type":25,"tag":86,"props":3036,"children":3037},{"style":99},[3038],{"type":34,"value":3039},":\n",{"type":25,"tag":86,"props":3041,"children":3042},{"class":88,"line":115},[3043,3048,3052],{"type":25,"tag":86,"props":3044,"children":3045},{"style":99},[3046],{"type":34,"value":3047},"        result ",{"type":25,"tag":86,"props":3049,"children":3050},{"style":93},[3051],{"type":34,"value":210},{"type":25,"tag":86,"props":3053,"children":3054},{"style":99},[3055],{"type":34,"value":3056}," session.execute(sql_query)\n",{"type":25,"tag":86,"props":3058,"children":3059},{"class":88,"line":140},[3060,3065],{"type":25,"tag":86,"props":3061,"children":3062},{"style":93},[3063],{"type":34,"value":3064},"        return",{"type":25,"tag":86,"props":3066,"children":3067},{"style":99},[3068],{"type":34,"value":3069}," result.fetchall()\n",{"type":25,"tag":86,"props":3071,"children":3072},{"class":88,"line":190},[3073,3078,3083,3088],{"type":25,"tag":86,"props":3074,"children":3075},{"style":93},[3076],{"type":34,"value":3077},"    except",{"type":25,"tag":86,"props":3079,"children":3080},{"style":250},[3081],{"type":34,"value":3082}," Exception",{"type":25,"tag":86,"props":3084,"children":3085},{"style":93},[3086],{"type":34,"value":3087}," as",{"type":25,"tag":86,"props":3089,"children":3090},{"style":99},[3091],{"type":34,"value":3092}," e:\n",{"type":25,"tag":86,"props":3094,"children":3095},{"class":88,"line":237},[3096,3101,3105,3109,3114,3118,3122,3126,3130],{"type":25,"tag":86,"props":3097,"children":3098},{"style":250},[3099],{"type":34,"value":3100},"        print",{"type":25,"tag":86,"props":3102,"children":3103},{"style":99},[3104],{"type":34,"value":166},{"type":25,"tag":86,"props":3106,"children":3107},{"style":93},[3108],{"type":34,"value":2757},{"type":25,"tag":86,"props":3110,"children":3111},{"style":270},[3112],{"type":34,"value":3113},"\"Error al ejecutar consulta: ",{"type":25,"tag":86,"props":3115,"children":3116},{"style":250},[3117],{"type":34,"value":2368},{"type":25,"tag":86,"props":3119,"children":3120},{"style":99},[3121],{"type":34,"value":445},{"type":25,"tag":86,"props":3123,"children":3124},{"style":250},[3125],{"type":34,"value":2450},{"type":25,"tag":86,"props":3127,"children":3128},{"style":270},[3129],{"type":34,"value":2781},{"type":25,"tag":86,"props":3131,"children":3132},{"style":99},[3133],{"type":34,"value":1026},{"type":25,"tag":86,"props":3135,"children":3136},{"class":88,"line":261},[3137,3141],{"type":25,"tag":86,"props":3138,"children":3139},{"style":93},[3140],{"type":34,"value":3064},{"type":25,"tag":86,"props":3142,"children":3143},{"style":250},[3144],{"type":34,"value":3145}," None\n",{"type":25,"tag":86,"props":3147,"children":3148},{"class":88,"line":281},[3149],{"type":25,"tag":86,"props":3150,"children":3151},{"emptyLinePlaceholder":109},[3152],{"type":34,"value":112},{"type":25,"tag":86,"props":3154,"children":3155},{"class":88,"line":290},[3156,3161,3165],{"type":25,"tag":86,"props":3157,"children":3158},{"style":99},[3159],{"type":34,"value":3160},"results ",{"type":25,"tag":86,"props":3162,"children":3163},{"style":93},[3164],{"type":34,"value":210},{"type":25,"tag":86,"props":3166,"children":3167},{"style":99},[3168],{"type":34,"value":3169}," execute_safe_query(query)\n",{"type":25,"tag":86,"props":3171,"children":3172},{"class":88,"line":298},[3173,3177],{"type":25,"tag":86,"props":3174,"children":3175},{"style":250},[3176],{"type":34,"value":2558},{"type":25,"tag":86,"props":3178,"children":3179},{"style":99},[3180],{"type":34,"value":3181},"(results)\n",{"type":25,"tag":53,"props":3183,"children":3185},{"id":3184},"buenas-prácticas",[3186],{"type":34,"value":3187},"Buenas prácticas",{"type":25,"tag":807,"props":3189,"children":3190},{},[3191,3196,3201],{"type":25,"tag":811,"props":3192,"children":3193},{},[3194],{"type":34,"value":3195},"Siempre revisa o limita el acceso de los usuarios a consultas críticas o sensibles.",{"type":25,"tag":811,"props":3197,"children":3198},{},[3199],{"type":34,"value":3200},"Implementa validaciones adicionales para asegurar la integridad y seguridad de tu base de datos.",{"type":25,"tag":811,"props":3202,"children":3203},{},[3204],{"type":34,"value":3205},"Utiliza tokens y modelos específicos de OpenAI optimizados para tareas SQL.",{"type":25,"tag":53,"props":3207,"children":3209},{"id":3208},"conclusión",[3210],{"type":34,"value":3211},"Conclusión",{"type":25,"tag":30,"props":3213,"children":3214},{},[3215],{"type":34,"value":3216},"Utilizar GPT para transformar consultas en lenguaje natural a SQL facilita enormemente la accesibilidad a los datos. Implementando este sistema, podrás ofrecer una experiencia de usuario más amigable y eficiente.",{"type":25,"tag":1806,"props":3218,"children":3220},{"id":3219},"recursos-adicionales",[3221],{"type":34,"value":3222},"Recursos adicionales",{"type":25,"tag":807,"props":3224,"children":3225},{},[3226,3236,3246],{"type":25,"tag":811,"props":3227,"children":3228},{},[3229],{"type":25,"tag":1819,"props":3230,"children":3233},{"href":3231,"rel":3232},"https://platform.openai.com/docs/api-reference",[1823],[3234],{"type":34,"value":3235},"Documentación API OpenAI",{"type":25,"tag":811,"props":3237,"children":3238},{},[3239],{"type":25,"tag":1819,"props":3240,"children":3243},{"href":3241,"rel":3242},"https://docs.sqlalchemy.org/en/20/",[1823],[3244],{"type":34,"value":3245},"SQLAlchemy ORM Documentation",{"type":25,"tag":811,"props":3247,"children":3248},{},[3249],{"type":25,"tag":1819,"props":3250,"children":3253},{"href":3251,"rel":3252},"https://pypi.org/project/python-dotenv/",[1823],[3254],{"type":34,"value":3255},"Python Dotenv",{"type":25,"tag":1848,"props":3257,"children":3258},{},[3259],{"type":34,"value":1852},{"title":7,"searchDepth":105,"depth":105,"links":3261},[3262,3263,3264,3265,3266,3267,3268,3269,3270],{"id":1899,"depth":105,"text":1902},{"id":1923,"depth":105,"text":1926},{"id":2005,"depth":105,"text":2008},{"id":2223,"depth":105,"text":2226},{"id":2566,"depth":105,"text":2569},{"id":2924,"depth":105,"text":2927},{"id":2994,"depth":105,"text":2997},{"id":3184,"depth":105,"text":3187},{"id":3208,"depth":105,"text":3211},"content:posts:gpt-sql-integration.md","posts/gpt-sql-integration.md","posts/gpt-sql-integration",{"_path":3275,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":3276,"description":3277,"date":3278,"layout":11,"subtitle":3279,"image":3280,"optimized_image":3280,"category":14,"tags":3281,"author":20,"paginate":6,"body":3285,"_type":1867,"_id":4171,"_source":1869,"_file":4172,"_stem":4173,"_extension":1872},"/posts/java-security-best-practices","Java Security Best Practices: Preventing Vulnerabilities and Threats","Explore essential security strategies for Java applications, addressing common vulnerabilities identified by OWASP Top 10 with practical examples.","2024-08-15T11:00:00.000Z","Practical Strategies to Safeguard Your Java Applications","/assets/img/uploads/java-security-best-practices.png",[14,16,3282,3283,3284],"security","owasp","cybersecurity",{"type":22,"children":3286,"toc":4159},[3287,3295,3301,3306,3360,3365,3371,3376,3497,3502,3508,3513,3613,3619,3624,3747,3752,3758,3763,3788,3793,3799,3804,3820,3825,3831,3836,3919,3924,3930,3935,4055,4060,4066,4071,4104,4109,4113,4118,4122,4155],{"type":25,"tag":26,"props":3288,"children":3289},{},[3290],{"type":25,"tag":30,"props":3291,"children":3292},{},[3293],{"type":34,"value":3294},"Security is critical in software development. Java applications, like all software, face numerous potential vulnerabilities. In this article, we will explore essential security best practices, referencing the OWASP Top 10, and providing practical Java examples to help you protect your applications effectively.",{"type":25,"tag":53,"props":3296,"children":3298},{"id":3297},"understanding-owasp-top-10",[3299],{"type":34,"value":3300},"Understanding OWASP Top 10",{"type":25,"tag":30,"props":3302,"children":3303},{},[3304],{"type":34,"value":3305},"The OWASP Top 10 outlines the most critical web application security risks:",{"type":25,"tag":3307,"props":3308,"children":3309},"ol",{},[3310,3315,3320,3325,3330,3335,3340,3345,3350,3355],{"type":25,"tag":811,"props":3311,"children":3312},{},[3313],{"type":34,"value":3314},"Injection",{"type":25,"tag":811,"props":3316,"children":3317},{},[3318],{"type":34,"value":3319},"Broken Authentication",{"type":25,"tag":811,"props":3321,"children":3322},{},[3323],{"type":34,"value":3324},"Sensitive Data Exposure",{"type":25,"tag":811,"props":3326,"children":3327},{},[3328],{"type":34,"value":3329},"XML External Entities (XXE)",{"type":25,"tag":811,"props":3331,"children":3332},{},[3333],{"type":34,"value":3334},"Broken Access Control",{"type":25,"tag":811,"props":3336,"children":3337},{},[3338],{"type":34,"value":3339},"Security Misconfiguration",{"type":25,"tag":811,"props":3341,"children":3342},{},[3343],{"type":34,"value":3344},"Cross-Site Scripting (XSS)",{"type":25,"tag":811,"props":3346,"children":3347},{},[3348],{"type":34,"value":3349},"Insecure Deserialization",{"type":25,"tag":811,"props":3351,"children":3352},{},[3353],{"type":34,"value":3354},"Using Components with Known Vulnerabilities",{"type":25,"tag":811,"props":3356,"children":3357},{},[3358],{"type":34,"value":3359},"Insufficient Logging and Monitoring",{"type":25,"tag":30,"props":3361,"children":3362},{},[3363],{"type":34,"value":3364},"Let's delve into practical strategies and Java implementations for some of these threats.",{"type":25,"tag":53,"props":3366,"children":3368},{"id":3367},"_1-injection-prevention",[3369],{"type":34,"value":3370},"1. Injection Prevention",{"type":25,"tag":30,"props":3372,"children":3373},{},[3374],{"type":34,"value":3375},"Use Prepared Statements and parameterized queries:",{"type":25,"tag":77,"props":3377,"children":3379},{"className":80,"code":3378,"language":16,"meta":7,"style":7},"PreparedStatement stmt = connection.prepareStatement(\"SELECT * FROM users WHERE username=? AND password=?\");\nstmt.setString(1, username);\nstmt.setString(2, password);\nResultSet rs = stmt.executeQuery();\n",[3380],{"type":25,"tag":14,"props":3381,"children":3382},{"__ignoreMap":7},[3383,3418,3445,3470],{"type":25,"tag":86,"props":3384,"children":3385},{"class":88,"line":89},[3386,3391,3395,3400,3405,3409,3414],{"type":25,"tag":86,"props":3387,"children":3388},{"style":99},[3389],{"type":34,"value":3390},"PreparedStatement stmt ",{"type":25,"tag":86,"props":3392,"children":3393},{"style":93},[3394],{"type":34,"value":210},{"type":25,"tag":86,"props":3396,"children":3397},{"style":99},[3398],{"type":34,"value":3399}," connection.",{"type":25,"tag":86,"props":3401,"children":3402},{"style":129},[3403],{"type":34,"value":3404},"prepareStatement",{"type":25,"tag":86,"props":3406,"children":3407},{"style":99},[3408],{"type":34,"value":166},{"type":25,"tag":86,"props":3410,"children":3411},{"style":270},[3412],{"type":34,"value":3413},"\"SELECT * FROM users WHERE username=? AND password=?\"",{"type":25,"tag":86,"props":3415,"children":3416},{"style":99},[3417],{"type":34,"value":258},{"type":25,"tag":86,"props":3419,"children":3420},{"class":88,"line":105},[3421,3426,3431,3435,3440],{"type":25,"tag":86,"props":3422,"children":3423},{"style":99},[3424],{"type":34,"value":3425},"stmt.",{"type":25,"tag":86,"props":3427,"children":3428},{"style":129},[3429],{"type":34,"value":3430},"setString",{"type":25,"tag":86,"props":3432,"children":3433},{"style":99},[3434],{"type":34,"value":166},{"type":25,"tag":86,"props":3436,"children":3437},{"style":250},[3438],{"type":34,"value":3439},"1",{"type":25,"tag":86,"props":3441,"children":3442},{"style":99},[3443],{"type":34,"value":3444},", username);\n",{"type":25,"tag":86,"props":3446,"children":3447},{"class":88,"line":115},[3448,3452,3456,3460,3465],{"type":25,"tag":86,"props":3449,"children":3450},{"style":99},[3451],{"type":34,"value":3425},{"type":25,"tag":86,"props":3453,"children":3454},{"style":129},[3455],{"type":34,"value":3430},{"type":25,"tag":86,"props":3457,"children":3458},{"style":99},[3459],{"type":34,"value":166},{"type":25,"tag":86,"props":3461,"children":3462},{"style":250},[3463],{"type":34,"value":3464},"2",{"type":25,"tag":86,"props":3466,"children":3467},{"style":99},[3468],{"type":34,"value":3469},", password);\n",{"type":25,"tag":86,"props":3471,"children":3472},{"class":88,"line":140},[3473,3478,3482,3487,3492],{"type":25,"tag":86,"props":3474,"children":3475},{"style":99},[3476],{"type":34,"value":3477},"ResultSet rs ",{"type":25,"tag":86,"props":3479,"children":3480},{"style":93},[3481],{"type":34,"value":210},{"type":25,"tag":86,"props":3483,"children":3484},{"style":99},[3485],{"type":34,"value":3486}," stmt.",{"type":25,"tag":86,"props":3488,"children":3489},{"style":129},[3490],{"type":34,"value":3491},"executeQuery",{"type":25,"tag":86,"props":3493,"children":3494},{"style":99},[3495],{"type":34,"value":3496},"();\n",{"type":25,"tag":30,"props":3498,"children":3499},{},[3500],{"type":34,"value":3501},"This approach prevents SQL injection by ensuring that input data is treated as data, not executable code.",{"type":25,"tag":53,"props":3503,"children":3505},{"id":3504},"_2-secure-authentication",[3506],{"type":34,"value":3507},"2. Secure Authentication",{"type":25,"tag":30,"props":3509,"children":3510},{},[3511],{"type":34,"value":3512},"Implement robust authentication using secure password storage (bcrypt or Argon2):",{"type":25,"tag":77,"props":3514,"children":3516},{"className":80,"code":3515,"language":16,"meta":7,"style":7},"import org.springframework.security.crypto.bcrypt.BCrypt;\n\nString hashedPassword = BCrypt.hashpw(password, BCrypt.gensalt());\nif (BCrypt.checkpw(password, hashedPassword)) {\n    // authentication successful\n}\n",[3517],{"type":25,"tag":14,"props":3518,"children":3519},{"__ignoreMap":7},[3520,3532,3539,3575,3598,3606],{"type":25,"tag":86,"props":3521,"children":3522},{"class":88,"line":89},[3523,3527],{"type":25,"tag":86,"props":3524,"children":3525},{"style":93},[3526],{"type":34,"value":96},{"type":25,"tag":86,"props":3528,"children":3529},{"style":99},[3530],{"type":34,"value":3531}," org.springframework.security.crypto.bcrypt.BCrypt;\n",{"type":25,"tag":86,"props":3533,"children":3534},{"class":88,"line":105},[3535],{"type":25,"tag":86,"props":3536,"children":3537},{"emptyLinePlaceholder":109},[3538],{"type":34,"value":112},{"type":25,"tag":86,"props":3540,"children":3541},{"class":88,"line":115},[3542,3547,3551,3556,3561,3566,3571],{"type":25,"tag":86,"props":3543,"children":3544},{"style":99},[3545],{"type":34,"value":3546},"String hashedPassword ",{"type":25,"tag":86,"props":3548,"children":3549},{"style":93},[3550],{"type":34,"value":210},{"type":25,"tag":86,"props":3552,"children":3553},{"style":99},[3554],{"type":34,"value":3555}," BCrypt.",{"type":25,"tag":86,"props":3557,"children":3558},{"style":129},[3559],{"type":34,"value":3560},"hashpw",{"type":25,"tag":86,"props":3562,"children":3563},{"style":99},[3564],{"type":34,"value":3565},"(password, BCrypt.",{"type":25,"tag":86,"props":3567,"children":3568},{"style":129},[3569],{"type":34,"value":3570},"gensalt",{"type":25,"tag":86,"props":3572,"children":3573},{"style":99},[3574],{"type":34,"value":762},{"type":25,"tag":86,"props":3576,"children":3577},{"class":88,"line":140},[3578,3583,3588,3593],{"type":25,"tag":86,"props":3579,"children":3580},{"style":93},[3581],{"type":34,"value":3582},"if",{"type":25,"tag":86,"props":3584,"children":3585},{"style":99},[3586],{"type":34,"value":3587}," (BCrypt.",{"type":25,"tag":86,"props":3589,"children":3590},{"style":129},[3591],{"type":34,"value":3592},"checkpw",{"type":25,"tag":86,"props":3594,"children":3595},{"style":99},[3596],{"type":34,"value":3597},"(password, hashedPassword)) {\n",{"type":25,"tag":86,"props":3599,"children":3600},{"class":88,"line":190},[3601],{"type":25,"tag":86,"props":3602,"children":3603},{"style":350},[3604],{"type":34,"value":3605},"    // authentication successful\n",{"type":25,"tag":86,"props":3607,"children":3608},{"class":88,"line":237},[3609],{"type":25,"tag":86,"props":3610,"children":3611},{"style":99},[3612],{"type":34,"value":467},{"type":25,"tag":53,"props":3614,"children":3616},{"id":3615},"_3-sensitive-data-exposure",[3617],{"type":34,"value":3618},"3. Sensitive Data Exposure",{"type":25,"tag":30,"props":3620,"children":3621},{},[3622],{"type":34,"value":3623},"Use encryption for sensitive data storage:",{"type":25,"tag":77,"props":3625,"children":3627},{"className":80,"code":3626,"language":16,"meta":7,"style":7},"Cipher cipher = Cipher.getInstance(\"AES/GCM/NoPadding\");\nSecretKey key = generateSecretKey();\ncipher.init(Cipher.ENCRYPT_MODE, key);\nbyte[] encryptedData = cipher.doFinal(plainData.getBytes(StandardCharsets.UTF_8));\n",[3628],{"type":25,"tag":14,"props":3629,"children":3630},{"__ignoreMap":7},[3631,3666,3687,3705],{"type":25,"tag":86,"props":3632,"children":3633},{"class":88,"line":89},[3634,3639,3643,3648,3653,3657,3662],{"type":25,"tag":86,"props":3635,"children":3636},{"style":99},[3637],{"type":34,"value":3638},"Cipher cipher ",{"type":25,"tag":86,"props":3640,"children":3641},{"style":93},[3642],{"type":34,"value":210},{"type":25,"tag":86,"props":3644,"children":3645},{"style":99},[3646],{"type":34,"value":3647}," Cipher.",{"type":25,"tag":86,"props":3649,"children":3650},{"style":129},[3651],{"type":34,"value":3652},"getInstance",{"type":25,"tag":86,"props":3654,"children":3655},{"style":99},[3656],{"type":34,"value":166},{"type":25,"tag":86,"props":3658,"children":3659},{"style":270},[3660],{"type":34,"value":3661},"\"AES/GCM/NoPadding\"",{"type":25,"tag":86,"props":3663,"children":3664},{"style":99},[3665],{"type":34,"value":258},{"type":25,"tag":86,"props":3667,"children":3668},{"class":88,"line":105},[3669,3674,3678,3683],{"type":25,"tag":86,"props":3670,"children":3671},{"style":99},[3672],{"type":34,"value":3673},"SecretKey key ",{"type":25,"tag":86,"props":3675,"children":3676},{"style":93},[3677],{"type":34,"value":210},{"type":25,"tag":86,"props":3679,"children":3680},{"style":129},[3681],{"type":34,"value":3682}," generateSecretKey",{"type":25,"tag":86,"props":3684,"children":3685},{"style":99},[3686],{"type":34,"value":3496},{"type":25,"tag":86,"props":3688,"children":3689},{"class":88,"line":115},[3690,3695,3700],{"type":25,"tag":86,"props":3691,"children":3692},{"style":99},[3693],{"type":34,"value":3694},"cipher.",{"type":25,"tag":86,"props":3696,"children":3697},{"style":129},[3698],{"type":34,"value":3699},"init",{"type":25,"tag":86,"props":3701,"children":3702},{"style":99},[3703],{"type":34,"value":3704},"(Cipher.ENCRYPT_MODE, key);\n",{"type":25,"tag":86,"props":3706,"children":3707},{"class":88,"line":140},[3708,3713,3718,3722,3727,3732,3737,3742],{"type":25,"tag":86,"props":3709,"children":3710},{"style":93},[3711],{"type":34,"value":3712},"byte",{"type":25,"tag":86,"props":3714,"children":3715},{"style":99},[3716],{"type":34,"value":3717},"[] encryptedData ",{"type":25,"tag":86,"props":3719,"children":3720},{"style":93},[3721],{"type":34,"value":210},{"type":25,"tag":86,"props":3723,"children":3724},{"style":99},[3725],{"type":34,"value":3726}," cipher.",{"type":25,"tag":86,"props":3728,"children":3729},{"style":129},[3730],{"type":34,"value":3731},"doFinal",{"type":25,"tag":86,"props":3733,"children":3734},{"style":99},[3735],{"type":34,"value":3736},"(plainData.",{"type":25,"tag":86,"props":3738,"children":3739},{"style":129},[3740],{"type":34,"value":3741},"getBytes",{"type":25,"tag":86,"props":3743,"children":3744},{"style":99},[3745],{"type":34,"value":3746},"(StandardCharsets.UTF_8));\n",{"type":25,"tag":30,"props":3748,"children":3749},{},[3750],{"type":34,"value":3751},"Always encrypt data at rest and in transit (use HTTPS).",{"type":25,"tag":53,"props":3753,"children":3755},{"id":3754},"_4-security-misconfiguration",[3756],{"type":34,"value":3757},"4. Security Misconfiguration",{"type":25,"tag":30,"props":3759,"children":3760},{},[3761],{"type":34,"value":3762},"Adopt secure defaults, disable debugging, and avoid detailed error messages:",{"type":25,"tag":77,"props":3764,"children":3768},{"className":3765,"code":3766,"language":3767,"meta":7,"style":7},"language-properties shiki shiki-themes github-dark github-light","server.error.include-stacktrace=never\nserver.error.include-message=never\n","properties",[3769],{"type":25,"tag":14,"props":3770,"children":3771},{"__ignoreMap":7},[3772,3780],{"type":25,"tag":86,"props":3773,"children":3774},{"class":88,"line":89},[3775],{"type":25,"tag":86,"props":3776,"children":3777},{},[3778],{"type":34,"value":3779},"server.error.include-stacktrace=never\n",{"type":25,"tag":86,"props":3781,"children":3782},{"class":88,"line":105},[3783],{"type":25,"tag":86,"props":3784,"children":3785},{},[3786],{"type":34,"value":3787},"server.error.include-message=never\n",{"type":25,"tag":30,"props":3789,"children":3790},{},[3791],{"type":34,"value":3792},"Review and secure your Java application configuration regularly.",{"type":25,"tag":53,"props":3794,"children":3796},{"id":3795},"_5-cross-site-scripting-xss",[3797],{"type":34,"value":3798},"5. Cross-Site Scripting (XSS)",{"type":25,"tag":30,"props":3800,"children":3801},{},[3802],{"type":34,"value":3803},"Utilize proper encoding or frameworks that prevent XSS by default, such as Thymeleaf:",{"type":25,"tag":77,"props":3805,"children":3809},{"className":3806,"code":3807,"language":3808,"meta":7,"style":7},"language-html shiki shiki-themes github-dark github-light","\u003Cp th:text=\"${userInput}\">\u003C/p>\n","html",[3810],{"type":25,"tag":14,"props":3811,"children":3812},{"__ignoreMap":7},[3813],{"type":25,"tag":86,"props":3814,"children":3815},{"class":88,"line":89},[3816],{"type":25,"tag":86,"props":3817,"children":3818},{},[3819],{"type":34,"value":3807},{"type":25,"tag":30,"props":3821,"children":3822},{},[3823],{"type":34,"value":3824},"Avoid directly inserting user inputs into HTML without proper sanitization or encoding.",{"type":25,"tag":53,"props":3826,"children":3828},{"id":3827},"_6-insecure-deserialization",[3829],{"type":34,"value":3830},"6. Insecure Deserialization",{"type":25,"tag":30,"props":3832,"children":3833},{},[3834],{"type":34,"value":3835},"Limit deserialization to trusted sources only:",{"type":25,"tag":77,"props":3837,"children":3839},{"className":80,"code":3838,"language":16,"meta":7,"style":7},"ObjectInputStream ois = new ObjectInputStream(new FileInputStream(\"trusted_data.ser\"));\nMyObject obj = (MyObject) ois.readObject();\n",[3840],{"type":25,"tag":14,"props":3841,"children":3842},{"__ignoreMap":7},[3843,3893],{"type":25,"tag":86,"props":3844,"children":3845},{"class":88,"line":89},[3846,3851,3855,3860,3865,3869,3874,3879,3883,3888],{"type":25,"tag":86,"props":3847,"children":3848},{"style":99},[3849],{"type":34,"value":3850},"ObjectInputStream ois ",{"type":25,"tag":86,"props":3852,"children":3853},{"style":93},[3854],{"type":34,"value":210},{"type":25,"tag":86,"props":3856,"children":3857},{"style":93},[3858],{"type":34,"value":3859}," new",{"type":25,"tag":86,"props":3861,"children":3862},{"style":129},[3863],{"type":34,"value":3864}," ObjectInputStream",{"type":25,"tag":86,"props":3866,"children":3867},{"style":99},[3868],{"type":34,"value":166},{"type":25,"tag":86,"props":3870,"children":3871},{"style":93},[3872],{"type":34,"value":3873},"new",{"type":25,"tag":86,"props":3875,"children":3876},{"style":129},[3877],{"type":34,"value":3878}," FileInputStream",{"type":25,"tag":86,"props":3880,"children":3881},{"style":99},[3882],{"type":34,"value":166},{"type":25,"tag":86,"props":3884,"children":3885},{"style":270},[3886],{"type":34,"value":3887},"\"trusted_data.ser\"",{"type":25,"tag":86,"props":3889,"children":3890},{"style":99},[3891],{"type":34,"value":3892},"));\n",{"type":25,"tag":86,"props":3894,"children":3895},{"class":88,"line":105},[3896,3901,3905,3910,3915],{"type":25,"tag":86,"props":3897,"children":3898},{"style":99},[3899],{"type":34,"value":3900},"MyObject obj ",{"type":25,"tag":86,"props":3902,"children":3903},{"style":93},[3904],{"type":34,"value":210},{"type":25,"tag":86,"props":3906,"children":3907},{"style":99},[3908],{"type":34,"value":3909}," (MyObject) ois.",{"type":25,"tag":86,"props":3911,"children":3912},{"style":129},[3913],{"type":34,"value":3914},"readObject",{"type":25,"tag":86,"props":3916,"children":3917},{"style":99},[3918],{"type":34,"value":3496},{"type":25,"tag":30,"props":3920,"children":3921},{},[3922],{"type":34,"value":3923},"Always validate deserialized data.",{"type":25,"tag":53,"props":3925,"children":3927},{"id":3926},"_7-component-vulnerabilities",[3928],{"type":34,"value":3929},"7. Component Vulnerabilities",{"type":25,"tag":30,"props":3931,"children":3932},{},[3933],{"type":34,"value":3934},"Regularly update libraries and dependencies, and use tools like OWASP Dependency-Check to identify vulnerabilities:",{"type":25,"tag":77,"props":3936,"children":3940},{"className":3937,"code":3938,"language":3939,"meta":7,"style":7},"language-xml shiki shiki-themes github-dark github-light","\u003Cplugin>\n    \u003CgroupId>org.owasp\u003C/groupId>\n    \u003CartifactId>dependency-check-maven\u003C/artifactId>\n    \u003Cversion>9.0.9\u003C/version>\n\u003C/plugin>\n","xml",[3941],{"type":25,"tag":14,"props":3942,"children":3943},{"__ignoreMap":7},[3944,3963,3989,4014,4039],{"type":25,"tag":86,"props":3945,"children":3946},{"class":88,"line":89},[3947,3952,3958],{"type":25,"tag":86,"props":3948,"children":3949},{"style":99},[3950],{"type":34,"value":3951},"\u003C",{"type":25,"tag":86,"props":3953,"children":3955},{"style":3954},"--shiki-default:#85E89D;--shiki-light:#22863A",[3956],{"type":34,"value":3957},"plugin",{"type":25,"tag":86,"props":3959,"children":3960},{"style":99},[3961],{"type":34,"value":3962},">\n",{"type":25,"tag":86,"props":3964,"children":3965},{"class":88,"line":105},[3966,3971,3976,3981,3985],{"type":25,"tag":86,"props":3967,"children":3968},{"style":99},[3969],{"type":34,"value":3970},"    \u003C",{"type":25,"tag":86,"props":3972,"children":3973},{"style":3954},[3974],{"type":34,"value":3975},"groupId",{"type":25,"tag":86,"props":3977,"children":3978},{"style":99},[3979],{"type":34,"value":3980},">org.owasp\u003C/",{"type":25,"tag":86,"props":3982,"children":3983},{"style":3954},[3984],{"type":34,"value":3975},{"type":25,"tag":86,"props":3986,"children":3987},{"style":99},[3988],{"type":34,"value":3962},{"type":25,"tag":86,"props":3990,"children":3991},{"class":88,"line":115},[3992,3996,4001,4006,4010],{"type":25,"tag":86,"props":3993,"children":3994},{"style":99},[3995],{"type":34,"value":3970},{"type":25,"tag":86,"props":3997,"children":3998},{"style":3954},[3999],{"type":34,"value":4000},"artifactId",{"type":25,"tag":86,"props":4002,"children":4003},{"style":99},[4004],{"type":34,"value":4005},">dependency-check-maven\u003C/",{"type":25,"tag":86,"props":4007,"children":4008},{"style":3954},[4009],{"type":34,"value":4000},{"type":25,"tag":86,"props":4011,"children":4012},{"style":99},[4013],{"type":34,"value":3962},{"type":25,"tag":86,"props":4015,"children":4016},{"class":88,"line":140},[4017,4021,4026,4031,4035],{"type":25,"tag":86,"props":4018,"children":4019},{"style":99},[4020],{"type":34,"value":3970},{"type":25,"tag":86,"props":4022,"children":4023},{"style":3954},[4024],{"type":34,"value":4025},"version",{"type":25,"tag":86,"props":4027,"children":4028},{"style":99},[4029],{"type":34,"value":4030},">9.0.9\u003C/",{"type":25,"tag":86,"props":4032,"children":4033},{"style":3954},[4034],{"type":34,"value":4025},{"type":25,"tag":86,"props":4036,"children":4037},{"style":99},[4038],{"type":34,"value":3962},{"type":25,"tag":86,"props":4040,"children":4041},{"class":88,"line":190},[4042,4047,4051],{"type":25,"tag":86,"props":4043,"children":4044},{"style":99},[4045],{"type":34,"value":4046},"\u003C/",{"type":25,"tag":86,"props":4048,"children":4049},{"style":3954},[4050],{"type":34,"value":3957},{"type":25,"tag":86,"props":4052,"children":4053},{"style":99},[4054],{"type":34,"value":3962},{"type":25,"tag":30,"props":4056,"children":4057},{},[4058],{"type":34,"value":4059},"Execute dependency checks regularly in your CI/CD pipeline.",{"type":25,"tag":53,"props":4061,"children":4063},{"id":4062},"_8-logging-and-monitoring",[4064],{"type":34,"value":4065},"8. Logging and Monitoring",{"type":25,"tag":30,"props":4067,"children":4068},{},[4069],{"type":34,"value":4070},"Implement comprehensive logging and monitoring to detect and respond to security incidents:",{"type":25,"tag":77,"props":4072,"children":4074},{"className":80,"code":4073,"language":16,"meta":7,"style":7},"logger.warn(\"Failed login attempt for user: {}\", username);\n",[4075],{"type":25,"tag":14,"props":4076,"children":4077},{"__ignoreMap":7},[4078],{"type":25,"tag":86,"props":4079,"children":4080},{"class":88,"line":89},[4081,4086,4091,4095,4100],{"type":25,"tag":86,"props":4082,"children":4083},{"style":99},[4084],{"type":34,"value":4085},"logger.",{"type":25,"tag":86,"props":4087,"children":4088},{"style":129},[4089],{"type":34,"value":4090},"warn",{"type":25,"tag":86,"props":4092,"children":4093},{"style":99},[4094],{"type":34,"value":166},{"type":25,"tag":86,"props":4096,"children":4097},{"style":270},[4098],{"type":34,"value":4099},"\"Failed login attempt for user: {}\"",{"type":25,"tag":86,"props":4101,"children":4102},{"style":99},[4103],{"type":34,"value":3444},{"type":25,"tag":30,"props":4105,"children":4106},{},[4107],{"type":34,"value":4108},"Aggregate logs centrally, and set up alerts for suspicious activities.",{"type":25,"tag":53,"props":4110,"children":4111},{"id":1777},[4112],{"type":34,"value":1780},{"type":25,"tag":30,"props":4114,"children":4115},{},[4116],{"type":34,"value":4117},"Adopting these best practices can greatly enhance the security posture of your Java applications. Stay proactive by regularly reviewing security measures, updating dependencies, and monitoring your systems. Security is a continuous process, not a one-time setup.",{"type":25,"tag":1806,"props":4119,"children":4120},{"id":1808},[4121],{"type":34,"value":1811},{"type":25,"tag":807,"props":4123,"children":4124},{},[4125,4135,4145],{"type":25,"tag":811,"props":4126,"children":4127},{},[4128],{"type":25,"tag":1819,"props":4129,"children":4132},{"href":4130,"rel":4131},"https://owasp.org/www-project-top-ten/",[1823],[4133],{"type":34,"value":4134},"OWASP Top 10",{"type":25,"tag":811,"props":4136,"children":4137},{},[4138],{"type":25,"tag":1819,"props":4139,"children":4142},{"href":4140,"rel":4141},"https://spring.io/projects/spring-security",[1823],[4143],{"type":34,"value":4144},"Spring Security",{"type":25,"tag":811,"props":4146,"children":4147},{},[4148],{"type":25,"tag":1819,"props":4149,"children":4152},{"href":4150,"rel":4151},"https://owasp.org/www-project-dependency-check/",[1823],[4153],{"type":34,"value":4154},"OWASP Dependency Check",{"type":25,"tag":1848,"props":4156,"children":4157},{},[4158],{"type":34,"value":1852},{"title":7,"searchDepth":105,"depth":105,"links":4160},[4161,4162,4163,4164,4165,4166,4167,4168,4169,4170],{"id":3297,"depth":105,"text":3300},{"id":3367,"depth":105,"text":3370},{"id":3504,"depth":105,"text":3507},{"id":3615,"depth":105,"text":3618},{"id":3754,"depth":105,"text":3757},{"id":3795,"depth":105,"text":3798},{"id":3827,"depth":105,"text":3830},{"id":3926,"depth":105,"text":3929},{"id":4062,"depth":105,"text":4065},{"id":1777,"depth":105,"text":1780},"content:posts:java-security-best-practices.md","posts/java-security-best-practices.md","posts/java-security-best-practices",{"_path":4175,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":4176,"description":4177,"date":4178,"layout":11,"subtitle":4179,"image":4180,"optimized_image":4180,"category":14,"tags":4181,"author":20,"paginate":6,"body":4185,"_type":1867,"_id":4980,"_source":1869,"_file":4981,"_stem":4982,"_extension":1872},"/posts/circuit-breaking-resilience","Circuit Breaking in Distributed Systems","An expert guide to understanding and implementing circuit breakers in distributed systems, with practical Java examples using Resilience4j and best practices.","2024-07-15T11:00:00.000Z","Enhancing Resilience with Circuit Breaker Patterns","/assets/img/uploads/circuit-breaking-resilience.png",[14,16,4182,4183,4184],"resilience","circuit-breaker","distributed-systems",{"type":22,"children":4186,"toc":4968},[4187,4195,4201,4206,4239,4244,4250,4255,4273,4279,4285,4290,4400,4406,4605,4611,4616,4779,4785,4790,4884,4889,4895,4918,4922,4927,4931,4964],{"type":25,"tag":26,"props":4188,"children":4189},{},[4190],{"type":25,"tag":30,"props":4191,"children":4192},{},[4193],{"type":34,"value":4194},"In modern distributed systems, failures are inevitable. The circuit breaker pattern helps maintain system stability by preventing failures from cascading across service boundaries. In this post, we'll dive deep into circuit breakers, explore their importance, and demonstrate practical implementation using Resilience4j in Java.",{"type":25,"tag":53,"props":4196,"children":4198},{"id":4197},"understanding-the-circuit-breaker-pattern",[4199],{"type":34,"value":4200},"Understanding the Circuit Breaker Pattern",{"type":25,"tag":30,"props":4202,"children":4203},{},[4204],{"type":34,"value":4205},"The circuit breaker pattern prevents a service from making repeated calls to an external service that is experiencing issues. It has three main states:",{"type":25,"tag":807,"props":4207,"children":4208},{},[4209,4219,4229],{"type":25,"tag":811,"props":4210,"children":4211},{},[4212,4217],{"type":25,"tag":45,"props":4213,"children":4214},{},[4215],{"type":34,"value":4216},"Closed:",{"type":34,"value":4218}," All requests pass through normally.",{"type":25,"tag":811,"props":4220,"children":4221},{},[4222,4227],{"type":25,"tag":45,"props":4223,"children":4224},{},[4225],{"type":34,"value":4226},"Open:",{"type":34,"value":4228}," Requests fail fast, bypassing the problematic service.",{"type":25,"tag":811,"props":4230,"children":4231},{},[4232,4237],{"type":25,"tag":45,"props":4233,"children":4234},{},[4235],{"type":34,"value":4236},"Half-Open:",{"type":34,"value":4238}," A limited number of requests test if the external service has recovered.",{"type":25,"tag":30,"props":4240,"children":4241},{},[4242],{"type":34,"value":4243},"This mechanism helps improve the resilience and responsiveness of your systems.",{"type":25,"tag":53,"props":4245,"children":4247},{"id":4246},"when-to-use-circuit-breakers",[4248],{"type":34,"value":4249},"When to Use Circuit Breakers",{"type":25,"tag":30,"props":4251,"children":4252},{},[4253],{"type":34,"value":4254},"Circuit breakers are essential when:",{"type":25,"tag":807,"props":4256,"children":4257},{},[4258,4263,4268],{"type":25,"tag":811,"props":4259,"children":4260},{},[4261],{"type":34,"value":4262},"Your system relies on remote calls (microservices architecture, external APIs).",{"type":25,"tag":811,"props":4264,"children":4265},{},[4266],{"type":34,"value":4267},"You need to prevent failure propagation.",{"type":25,"tag":811,"props":4269,"children":4270},{},[4271],{"type":34,"value":4272},"You aim to improve user experience by quickly responding to failures.",{"type":25,"tag":53,"props":4274,"children":4276},{"id":4275},"implementing-circuit-breakers-with-resilience4j",[4277],{"type":34,"value":4278},"Implementing Circuit Breakers with Resilience4j",{"type":25,"tag":70,"props":4280,"children":4282},{"id":4281},"step-1-adding-dependencies",[4283],{"type":34,"value":4284},"Step 1: Adding Dependencies",{"type":25,"tag":30,"props":4286,"children":4287},{},[4288],{"type":34,"value":4289},"Add Resilience4j dependencies to your project (Maven example):",{"type":25,"tag":77,"props":4291,"children":4293},{"className":3937,"code":4292,"language":3939,"meta":7,"style":7},"\u003Cdependency>\n    \u003CgroupId>io.github.resilience4j\u003C/groupId>\n    \u003CartifactId>resilience4j-circuitbreaker\u003C/artifactId>\n    \u003Cversion>2.0.2\u003C/version>\n\u003C/dependency>\n",[4294],{"type":25,"tag":14,"props":4295,"children":4296},{"__ignoreMap":7},[4297,4313,4337,4361,4385],{"type":25,"tag":86,"props":4298,"children":4299},{"class":88,"line":89},[4300,4304,4309],{"type":25,"tag":86,"props":4301,"children":4302},{"style":99},[4303],{"type":34,"value":3951},{"type":25,"tag":86,"props":4305,"children":4306},{"style":3954},[4307],{"type":34,"value":4308},"dependency",{"type":25,"tag":86,"props":4310,"children":4311},{"style":99},[4312],{"type":34,"value":3962},{"type":25,"tag":86,"props":4314,"children":4315},{"class":88,"line":105},[4316,4320,4324,4329,4333],{"type":25,"tag":86,"props":4317,"children":4318},{"style":99},[4319],{"type":34,"value":3970},{"type":25,"tag":86,"props":4321,"children":4322},{"style":3954},[4323],{"type":34,"value":3975},{"type":25,"tag":86,"props":4325,"children":4326},{"style":99},[4327],{"type":34,"value":4328},">io.github.resilience4j\u003C/",{"type":25,"tag":86,"props":4330,"children":4331},{"style":3954},[4332],{"type":34,"value":3975},{"type":25,"tag":86,"props":4334,"children":4335},{"style":99},[4336],{"type":34,"value":3962},{"type":25,"tag":86,"props":4338,"children":4339},{"class":88,"line":115},[4340,4344,4348,4353,4357],{"type":25,"tag":86,"props":4341,"children":4342},{"style":99},[4343],{"type":34,"value":3970},{"type":25,"tag":86,"props":4345,"children":4346},{"style":3954},[4347],{"type":34,"value":4000},{"type":25,"tag":86,"props":4349,"children":4350},{"style":99},[4351],{"type":34,"value":4352},">resilience4j-circuitbreaker\u003C/",{"type":25,"tag":86,"props":4354,"children":4355},{"style":3954},[4356],{"type":34,"value":4000},{"type":25,"tag":86,"props":4358,"children":4359},{"style":99},[4360],{"type":34,"value":3962},{"type":25,"tag":86,"props":4362,"children":4363},{"class":88,"line":140},[4364,4368,4372,4377,4381],{"type":25,"tag":86,"props":4365,"children":4366},{"style":99},[4367],{"type":34,"value":3970},{"type":25,"tag":86,"props":4369,"children":4370},{"style":3954},[4371],{"type":34,"value":4025},{"type":25,"tag":86,"props":4373,"children":4374},{"style":99},[4375],{"type":34,"value":4376},">2.0.2\u003C/",{"type":25,"tag":86,"props":4378,"children":4379},{"style":3954},[4380],{"type":34,"value":4025},{"type":25,"tag":86,"props":4382,"children":4383},{"style":99},[4384],{"type":34,"value":3962},{"type":25,"tag":86,"props":4386,"children":4387},{"class":88,"line":190},[4388,4392,4396],{"type":25,"tag":86,"props":4389,"children":4390},{"style":99},[4391],{"type":34,"value":4046},{"type":25,"tag":86,"props":4393,"children":4394},{"style":3954},[4395],{"type":34,"value":4308},{"type":25,"tag":86,"props":4397,"children":4398},{"style":99},[4399],{"type":34,"value":3962},{"type":25,"tag":70,"props":4401,"children":4403},{"id":4402},"step-2-configuring-circuit-breaker",[4404],{"type":34,"value":4405},"Step 2: Configuring Circuit Breaker",{"type":25,"tag":77,"props":4407,"children":4409},{"className":80,"code":4408,"language":16,"meta":7,"style":7},"CircuitBreakerConfig config = CircuitBreakerConfig.custom()\n    .failureRateThreshold(50)\n    .waitDurationInOpenState(Duration.ofMillis(1000))\n    .permittedNumberOfCallsInHalfOpenState(2)\n    .minimumNumberOfCalls(5)\n    .build();\n\nCircuitBreaker circuitBreaker = CircuitBreaker.of(\"myService\", config);\n",[4410],{"type":25,"tag":14,"props":4411,"children":4412},{"__ignoreMap":7},[4413,4440,4466,4498,4522,4546,4562,4569],{"type":25,"tag":86,"props":4414,"children":4415},{"class":88,"line":89},[4416,4421,4425,4430,4435],{"type":25,"tag":86,"props":4417,"children":4418},{"style":99},[4419],{"type":34,"value":4420},"CircuitBreakerConfig config ",{"type":25,"tag":86,"props":4422,"children":4423},{"style":93},[4424],{"type":34,"value":210},{"type":25,"tag":86,"props":4426,"children":4427},{"style":99},[4428],{"type":34,"value":4429}," CircuitBreakerConfig.",{"type":25,"tag":86,"props":4431,"children":4432},{"style":129},[4433],{"type":34,"value":4434},"custom",{"type":25,"tag":86,"props":4436,"children":4437},{"style":99},[4438],{"type":34,"value":4439},"()\n",{"type":25,"tag":86,"props":4441,"children":4442},{"class":88,"line":105},[4443,4448,4453,4457,4462],{"type":25,"tag":86,"props":4444,"children":4445},{"style":99},[4446],{"type":34,"value":4447},"    .",{"type":25,"tag":86,"props":4449,"children":4450},{"style":129},[4451],{"type":34,"value":4452},"failureRateThreshold",{"type":25,"tag":86,"props":4454,"children":4455},{"style":99},[4456],{"type":34,"value":166},{"type":25,"tag":86,"props":4458,"children":4459},{"style":250},[4460],{"type":34,"value":4461},"50",{"type":25,"tag":86,"props":4463,"children":4464},{"style":99},[4465],{"type":34,"value":1026},{"type":25,"tag":86,"props":4467,"children":4468},{"class":88,"line":115},[4469,4473,4478,4482,4486,4490,4494],{"type":25,"tag":86,"props":4470,"children":4471},{"style":99},[4472],{"type":34,"value":4447},{"type":25,"tag":86,"props":4474,"children":4475},{"style":129},[4476],{"type":34,"value":4477},"waitDurationInOpenState",{"type":25,"tag":86,"props":4479,"children":4480},{"style":99},[4481],{"type":34,"value":1044},{"type":25,"tag":86,"props":4483,"children":4484},{"style":129},[4485],{"type":34,"value":1049},{"type":25,"tag":86,"props":4487,"children":4488},{"style":99},[4489],{"type":34,"value":166},{"type":25,"tag":86,"props":4491,"children":4492},{"style":250},[4493],{"type":34,"value":253},{"type":25,"tag":86,"props":4495,"children":4496},{"style":99},[4497],{"type":34,"value":1063},{"type":25,"tag":86,"props":4499,"children":4500},{"class":88,"line":140},[4501,4505,4510,4514,4518],{"type":25,"tag":86,"props":4502,"children":4503},{"style":99},[4504],{"type":34,"value":4447},{"type":25,"tag":86,"props":4506,"children":4507},{"style":129},[4508],{"type":34,"value":4509},"permittedNumberOfCallsInHalfOpenState",{"type":25,"tag":86,"props":4511,"children":4512},{"style":99},[4513],{"type":34,"value":166},{"type":25,"tag":86,"props":4515,"children":4516},{"style":250},[4517],{"type":34,"value":3464},{"type":25,"tag":86,"props":4519,"children":4520},{"style":99},[4521],{"type":34,"value":1026},{"type":25,"tag":86,"props":4523,"children":4524},{"class":88,"line":190},[4525,4529,4534,4538,4542],{"type":25,"tag":86,"props":4526,"children":4527},{"style":99},[4528],{"type":34,"value":4447},{"type":25,"tag":86,"props":4530,"children":4531},{"style":129},[4532],{"type":34,"value":4533},"minimumNumberOfCalls",{"type":25,"tag":86,"props":4535,"children":4536},{"style":99},[4537],{"type":34,"value":166},{"type":25,"tag":86,"props":4539,"children":4540},{"style":250},[4541],{"type":34,"value":1379},{"type":25,"tag":86,"props":4543,"children":4544},{"style":99},[4545],{"type":34,"value":1026},{"type":25,"tag":86,"props":4547,"children":4548},{"class":88,"line":237},[4549,4553,4558],{"type":25,"tag":86,"props":4550,"children":4551},{"style":99},[4552],{"type":34,"value":4447},{"type":25,"tag":86,"props":4554,"children":4555},{"style":129},[4556],{"type":34,"value":4557},"build",{"type":25,"tag":86,"props":4559,"children":4560},{"style":99},[4561],{"type":34,"value":3496},{"type":25,"tag":86,"props":4563,"children":4564},{"class":88,"line":261},[4565],{"type":25,"tag":86,"props":4566,"children":4567},{"emptyLinePlaceholder":109},[4568],{"type":34,"value":112},{"type":25,"tag":86,"props":4570,"children":4571},{"class":88,"line":281},[4572,4577,4581,4586,4591,4595,4600],{"type":25,"tag":86,"props":4573,"children":4574},{"style":99},[4575],{"type":34,"value":4576},"CircuitBreaker circuitBreaker ",{"type":25,"tag":86,"props":4578,"children":4579},{"style":93},[4580],{"type":34,"value":210},{"type":25,"tag":86,"props":4582,"children":4583},{"style":99},[4584],{"type":34,"value":4585}," CircuitBreaker.",{"type":25,"tag":86,"props":4587,"children":4588},{"style":129},[4589],{"type":34,"value":4590},"of",{"type":25,"tag":86,"props":4592,"children":4593},{"style":99},[4594],{"type":34,"value":166},{"type":25,"tag":86,"props":4596,"children":4597},{"style":270},[4598],{"type":34,"value":4599},"\"myService\"",{"type":25,"tag":86,"props":4601,"children":4602},{"style":99},[4603],{"type":34,"value":4604},", config);\n",{"type":25,"tag":70,"props":4606,"children":4608},{"id":4607},"step-3-using-circuit-breaker",[4609],{"type":34,"value":4610},"Step 3: Using Circuit Breaker",{"type":25,"tag":30,"props":4612,"children":4613},{},[4614],{"type":34,"value":4615},"Wrap service calls using the circuit breaker:",{"type":25,"tag":77,"props":4617,"children":4619},{"className":80,"code":4618,"language":16,"meta":7,"style":7},"Supplier\u003CString> decoratedSupplier = CircuitBreaker.decorateSupplier(circuitBreaker, () -> myService.remoteCall());\n\nTry.ofSupplier(decoratedSupplier)\n    .recover(throwable -> \"Fallback response\")\n    .onSuccess(result -> System.out.println(\"Response: \" + result));\n",[4620],{"type":25,"tag":14,"props":4621,"children":4622},{"__ignoreMap":7},[4623,4676,4683,4701,4731],{"type":25,"tag":86,"props":4624,"children":4625},{"class":88,"line":89},[4626,4631,4635,4640,4644,4648,4653,4658,4662,4667,4672],{"type":25,"tag":86,"props":4627,"children":4628},{"style":99},[4629],{"type":34,"value":4630},"Supplier\u003C",{"type":25,"tag":86,"props":4632,"children":4633},{"style":93},[4634],{"type":34,"value":171},{"type":25,"tag":86,"props":4636,"children":4637},{"style":99},[4638],{"type":34,"value":4639},"> decoratedSupplier ",{"type":25,"tag":86,"props":4641,"children":4642},{"style":93},[4643],{"type":34,"value":210},{"type":25,"tag":86,"props":4645,"children":4646},{"style":99},[4647],{"type":34,"value":4585},{"type":25,"tag":86,"props":4649,"children":4650},{"style":129},[4651],{"type":34,"value":4652},"decorateSupplier",{"type":25,"tag":86,"props":4654,"children":4655},{"style":99},[4656],{"type":34,"value":4657},"(circuitBreaker, () ",{"type":25,"tag":86,"props":4659,"children":4660},{"style":93},[4661],{"type":34,"value":230},{"type":25,"tag":86,"props":4663,"children":4664},{"style":99},[4665],{"type":34,"value":4666}," myService.",{"type":25,"tag":86,"props":4668,"children":4669},{"style":129},[4670],{"type":34,"value":4671},"remoteCall",{"type":25,"tag":86,"props":4673,"children":4674},{"style":99},[4675],{"type":34,"value":762},{"type":25,"tag":86,"props":4677,"children":4678},{"class":88,"line":105},[4679],{"type":25,"tag":86,"props":4680,"children":4681},{"emptyLinePlaceholder":109},[4682],{"type":34,"value":112},{"type":25,"tag":86,"props":4684,"children":4685},{"class":88,"line":115},[4686,4691,4696],{"type":25,"tag":86,"props":4687,"children":4688},{"style":99},[4689],{"type":34,"value":4690},"Try.",{"type":25,"tag":86,"props":4692,"children":4693},{"style":129},[4694],{"type":34,"value":4695},"ofSupplier",{"type":25,"tag":86,"props":4697,"children":4698},{"style":99},[4699],{"type":34,"value":4700},"(decoratedSupplier)\n",{"type":25,"tag":86,"props":4702,"children":4703},{"class":88,"line":140},[4704,4708,4713,4718,4722,4727],{"type":25,"tag":86,"props":4705,"children":4706},{"style":99},[4707],{"type":34,"value":4447},{"type":25,"tag":86,"props":4709,"children":4710},{"style":129},[4711],{"type":34,"value":4712},"recover",{"type":25,"tag":86,"props":4714,"children":4715},{"style":99},[4716],{"type":34,"value":4717},"(throwable ",{"type":25,"tag":86,"props":4719,"children":4720},{"style":93},[4721],{"type":34,"value":230},{"type":25,"tag":86,"props":4723,"children":4724},{"style":270},[4725],{"type":34,"value":4726}," \"Fallback response\"",{"type":25,"tag":86,"props":4728,"children":4729},{"style":99},[4730],{"type":34,"value":1026},{"type":25,"tag":86,"props":4732,"children":4733},{"class":88,"line":190},[4734,4738,4743,4748,4752,4757,4761,4765,4770,4774],{"type":25,"tag":86,"props":4735,"children":4736},{"style":99},[4737],{"type":34,"value":4447},{"type":25,"tag":86,"props":4739,"children":4740},{"style":129},[4741],{"type":34,"value":4742},"onSuccess",{"type":25,"tag":86,"props":4744,"children":4745},{"style":99},[4746],{"type":34,"value":4747},"(result ",{"type":25,"tag":86,"props":4749,"children":4750},{"style":93},[4751],{"type":34,"value":230},{"type":25,"tag":86,"props":4753,"children":4754},{"style":99},[4755],{"type":34,"value":4756}," System.out.",{"type":25,"tag":86,"props":4758,"children":4759},{"style":129},[4760],{"type":34,"value":747},{"type":25,"tag":86,"props":4762,"children":4763},{"style":99},[4764],{"type":34,"value":166},{"type":25,"tag":86,"props":4766,"children":4767},{"style":270},[4768],{"type":34,"value":4769},"\"Response: \"",{"type":25,"tag":86,"props":4771,"children":4772},{"style":93},[4773],{"type":34,"value":729},{"type":25,"tag":86,"props":4775,"children":4776},{"style":99},[4777],{"type":34,"value":4778}," result));\n",{"type":25,"tag":53,"props":4780,"children":4782},{"id":4781},"monitoring-and-metrics",[4783],{"type":34,"value":4784},"Monitoring and Metrics",{"type":25,"tag":30,"props":4786,"children":4787},{},[4788],{"type":34,"value":4789},"Resilience4j provides built-in support for metrics and monitoring:",{"type":25,"tag":77,"props":4791,"children":4793},{"className":80,"code":4792,"language":16,"meta":7,"style":7},"CircuitBreakerRegistry registry = CircuitBreakerRegistry.ofDefaults();\nregistry.getEventPublisher()\n    .onStateTransition(event -> System.out.println(event.getStateTransition()));\n",[4794],{"type":25,"tag":14,"props":4795,"children":4796},{"__ignoreMap":7},[4797,4823,4840],{"type":25,"tag":86,"props":4798,"children":4799},{"class":88,"line":89},[4800,4805,4809,4814,4819],{"type":25,"tag":86,"props":4801,"children":4802},{"style":99},[4803],{"type":34,"value":4804},"CircuitBreakerRegistry registry ",{"type":25,"tag":86,"props":4806,"children":4807},{"style":93},[4808],{"type":34,"value":210},{"type":25,"tag":86,"props":4810,"children":4811},{"style":99},[4812],{"type":34,"value":4813}," CircuitBreakerRegistry.",{"type":25,"tag":86,"props":4815,"children":4816},{"style":129},[4817],{"type":34,"value":4818},"ofDefaults",{"type":25,"tag":86,"props":4820,"children":4821},{"style":99},[4822],{"type":34,"value":3496},{"type":25,"tag":86,"props":4824,"children":4825},{"class":88,"line":105},[4826,4831,4836],{"type":25,"tag":86,"props":4827,"children":4828},{"style":99},[4829],{"type":34,"value":4830},"registry.",{"type":25,"tag":86,"props":4832,"children":4833},{"style":129},[4834],{"type":34,"value":4835},"getEventPublisher",{"type":25,"tag":86,"props":4837,"children":4838},{"style":99},[4839],{"type":34,"value":4439},{"type":25,"tag":86,"props":4841,"children":4842},{"class":88,"line":115},[4843,4847,4852,4857,4861,4865,4869,4874,4879],{"type":25,"tag":86,"props":4844,"children":4845},{"style":99},[4846],{"type":34,"value":4447},{"type":25,"tag":86,"props":4848,"children":4849},{"style":129},[4850],{"type":34,"value":4851},"onStateTransition",{"type":25,"tag":86,"props":4853,"children":4854},{"style":99},[4855],{"type":34,"value":4856},"(event ",{"type":25,"tag":86,"props":4858,"children":4859},{"style":93},[4860],{"type":34,"value":230},{"type":25,"tag":86,"props":4862,"children":4863},{"style":99},[4864],{"type":34,"value":4756},{"type":25,"tag":86,"props":4866,"children":4867},{"style":129},[4868],{"type":34,"value":747},{"type":25,"tag":86,"props":4870,"children":4871},{"style":99},[4872],{"type":34,"value":4873},"(event.",{"type":25,"tag":86,"props":4875,"children":4876},{"style":129},[4877],{"type":34,"value":4878},"getStateTransition",{"type":25,"tag":86,"props":4880,"children":4881},{"style":99},[4882],{"type":34,"value":4883},"()));\n",{"type":25,"tag":30,"props":4885,"children":4886},{},[4887],{"type":34,"value":4888},"Integrate with Prometheus, Grafana, or other observability tools for comprehensive monitoring.",{"type":25,"tag":53,"props":4890,"children":4892},{"id":4891},"best-practices-for-circuit-breaking",[4893],{"type":34,"value":4894},"Best Practices for Circuit Breaking",{"type":25,"tag":807,"props":4896,"children":4897},{},[4898,4903,4908,4913],{"type":25,"tag":811,"props":4899,"children":4900},{},[4901],{"type":34,"value":4902},"Configure sensible thresholds to avoid premature circuit opening.",{"type":25,"tag":811,"props":4904,"children":4905},{},[4906],{"type":34,"value":4907},"Always define fallback mechanisms.",{"type":25,"tag":811,"props":4909,"children":4910},{},[4911],{"type":34,"value":4912},"Regularly monitor circuit breaker states and metrics.",{"type":25,"tag":811,"props":4914,"children":4915},{},[4916],{"type":34,"value":4917},"Test thoroughly to ensure reliability under failure conditions.",{"type":25,"tag":53,"props":4919,"children":4920},{"id":1777},[4921],{"type":34,"value":1780},{"type":25,"tag":30,"props":4923,"children":4924},{},[4925],{"type":34,"value":4926},"Implementing circuit breakers using Resilience4j significantly enhances the resilience of your Java-based distributed systems. This proactive approach ensures your systems gracefully handle failures, maintaining service availability and user satisfaction.",{"type":25,"tag":1806,"props":4928,"children":4929},{"id":1808},[4930],{"type":34,"value":1811},{"type":25,"tag":807,"props":4932,"children":4933},{},[4934,4944,4954],{"type":25,"tag":811,"props":4935,"children":4936},{},[4937],{"type":25,"tag":1819,"props":4938,"children":4941},{"href":4939,"rel":4940},"https://resilience4j.readme.io/docs",[1823],[4942],{"type":34,"value":4943},"Resilience4j Official Documentation",{"type":25,"tag":811,"props":4945,"children":4946},{},[4947],{"type":25,"tag":1819,"props":4948,"children":4951},{"href":4949,"rel":4950},"https://martinfowler.com/bliki/CircuitBreaker.html",[1823],[4952],{"type":34,"value":4953},"Circuit Breaker Pattern by Martin Fowler",{"type":25,"tag":811,"props":4955,"children":4956},{},[4957],{"type":25,"tag":1819,"props":4958,"children":4961},{"href":4959,"rel":4960},"https://microservices.io/patterns/reliability/circuit-breaker.html",[1823],[4962],{"type":34,"value":4963},"Microservices Patterns by Chris Richardson",{"type":25,"tag":1848,"props":4965,"children":4966},{},[4967],{"type":34,"value":1852},{"title":7,"searchDepth":105,"depth":105,"links":4969},[4970,4971,4972,4977,4978,4979],{"id":4197,"depth":105,"text":4200},{"id":4246,"depth":105,"text":4249},{"id":4275,"depth":105,"text":4278,"children":4973},[4974,4975,4976],{"id":4281,"depth":115,"text":4284},{"id":4402,"depth":115,"text":4405},{"id":4607,"depth":115,"text":4610},{"id":4781,"depth":105,"text":4784},{"id":4891,"depth":105,"text":4894},{"id":1777,"depth":105,"text":1780},"content:posts:circuit-breaking-resilience.md","posts/circuit-breaking-resilience.md","posts/circuit-breaking-resilience",[4984,4985,4986,4987,4991,4995,4996,5000,5004,5008,5012,5016,5020,5024,5028,5032,5036,5040,5043,5047,5051],{"_path":1875,"title":1876,"date":1878},{"_path":3275,"title":3276,"date":3278},{"_path":4175,"title":4176,"date":4178},{"_path":4988,"title":4989,"date":4990},"/posts/maven-and-github-actions","Automating Java Builds with Maven and GitHub Actions CI/CD","2024-06-15T11:00:00.000Z",{"_path":4992,"title":4993,"date":4994},"/posts/pattern-matching-sealed-classes-java21","A Guide to Pattern Matching and Sealed Classes in Java 21","2024-05-15T11:00:00.000Z",{"_path":4,"title":8,"date":10},{"_path":4997,"title":4998,"date":4999},"/posts/mastering-concurrency","Mastering Concurrency in Java: Threads, Executors, and Virtual Threads","2024-03-15T11:00:00.000Z",{"_path":5001,"title":5002,"date":5003},"/posts/microservices-mistakes","Common Mistakes When Developing Microservices","2024-02-15T11:00:00.000Z",{"_path":5005,"title":5006,"date":5007},"/posts/tdd-testing","Test-Driven Development (TDD) in Java with JUnit and Mockito","2024-01-15T11:00:00.000Z",{"_path":5009,"title":5010,"date":5011},"/posts/single-table-design","Single Table Design","2023-12-27T11:00:00.000Z",{"_path":5013,"title":5014,"date":5015},"/posts/java-17","Exploring Java 17's New Features","2023-10-08T11:00:00.000Z",{"_path":5017,"title":5018,"date":5019},"/posts/hexagonal-architecture","Introduction to Hexagonal Architecture","2023-10-02 18:00:00",{"_path":5021,"title":5022,"date":5023},"/posts/terraform","Unleashing the Power of Infrastructure as Code (IaC)","2023-09-24 18:00:00",{"_path":5025,"title":5026,"date":5027},"/posts/python-virtual-environments","Python Virtual Environments (venv)","2023-09-17 22:00:00",{"_path":5029,"title":5030,"date":5031},"/posts/api-first-principles","API First principles","2023-09-01 22:15:18",{"_path":5033,"title":5034,"date":5035},"/posts/how-to-configure-ssh-key-based-authentication","How To Configure SSH Key-Based Authentication","2021-02-21 03:46:12",{"_path":5037,"title":5038,"date":5039},"/posts/algorithms-binary-search-tree","Algorithms - Binary Search Tree in kotlin","2020-12-06T11:00:00.000Z",{"_path":5041,"title":5042,"date":5039},"/posts/how-to-create-a-twitter-bot","How to create a Twitter bot",{"_path":5044,"title":5045,"date":5046},"/posts/manage-aws-infrastructure-with-terraform","Bootstrap complete Java application infrastructure in AWS with Terraform","2020-12-02T11:00:00.000Z",{"_path":5048,"title":5049,"date":5050},"/posts/algorithms-working-with-trees","Algorithms - Binary tree traversals in kotlin","2020-11-24T11:00:00.000Z",{"_path":5052,"title":5053,"date":5054},"/posts/playing-with-ocr-libraries","Playing with OCR libraries","2020-11-22T11:00:00.000Z",1790510065745]