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