[{"data":1,"prerenderedAt":3634},["ShallowReactive",2],{"searchBlogPosts":3,"content-\u002Fblog\u002Fspring-async-retry":28},[4,7,10,13,16,19,22,25],{"_path":5,"title":6},"\u002Fblog\u002F2026\u002F03\u002F14\u002Fposthog-observability-tongueflow","How I Used PostHog to Add Observability to My Web App as a Junior DevOps Engineer",{"_path":8,"title":9},"\u002Fblog\u002F2025\u002F10\u002F05\u002Faws-cloud-operations-certification-journey-ssm-lab","AWS Cloud Operations Certification Journey: Mastering Systems Manager",{"_path":11,"title":12},"\u002Fblog\u002F2025\u002F03\u002F14\u002Fansible-setup-configuration","Ansible Setup and Configuration",{"_path":14,"title":15},"\u002Fblog\u002F2025\u002F01\u002F05\u002Fdata-sharing-with-nfs","Data Sharing with NFS: A Complete Guide for System Administrators",{"_path":17,"title":18},"\u002Fblog\u002F2024\u002F05\u002F23\u002Fjava-29th-birth","Java celebrates 29 years of history",{"_path":20,"title":21},"\u002Fblog\u002F2024\u002F03\u002F19\u002Fhow-to-update-to-java21","How to Update to Java 21 Using SDKMAN",{"_path":23,"title":24},"\u002Fblog\u002F2024\u002F02\u002F11\u002Fspring-async-retry","Implementing Asynchronous Retry Mechanism for Email Sending in Spring Applications",{"_path":26,"title":27},"\u002Fblog\u002F2024\u002F01\u002F25\u002Fjdbc-vs-jpa","JDBC vs JPA: Which is Better for Your Application?",{"_path":23,"_dir":29,"_draft":30,"_partial":30,"_locale":31,"title":24,"description":32,"slug":33,"date":34,"published":35,"author":36,"tags":37,"cover":43,"keywords":44,"body":45,"_type":3627,"_id":3628,"_source":3629,"_file":3630,"_stem":3631,"_extension":3632,"sitemap":3633},"11",false,"","Enhance the performance and responsiveness of Spring applications by implementing an asynchronous execution with automatic retry mechanism for sending emails.","spring-async-retry","2024-02-11T16:00:00.000Z",true,"Nidhal Naffati",[38,39,40,41,42],"Spring","Spring Boot","Email","Asynchronous","Retry","spring-async-retry-cover.png","Spring, Spring Boot, Email, Asynchronous, Retry, JavaMailSender, JavaMail, Java, MessagingException, IOException, JavaMailSenderImpl, MimeMessage, MimeMessageHelper",{"type":46,"children":47,"toc":3616},"root",[48,56,61,66,73,78,84,89,96,112,170,183,226,240,284,290,295,367,372,1063,1069,1074,1905,1911,1916,1921,1926,1931,2008,2013,2018,2346,2351,3143,3149,3154,3557,3562,3567,3576,3581,3589,3594,3600,3605,3610],{"type":49,"tag":50,"props":51,"children":52},"element","p",{},[53],{"type":54,"value":55},"text","To enhance the performance and responsiveness of Spring applications, there is often a need to execute code\nasynchronously.",{"type":49,"tag":50,"props":57,"children":58},{},[59],{"type":54,"value":60},"Additionally, handling occasional failures, such as network issues or third-party service unavailability, is crucial for\nbuilding resilient applications.",{"type":49,"tag":50,"props":62,"children":63},{},[64],{"type":54,"value":65},"In this article, we will explore the implementation of an asynchronous execution with an automatic retry mechanism for\nsending emails in a Spring application, leveraging Spring's support for async and retry operations.",{"type":49,"tag":67,"props":68,"children":70},"h2",{"id":69},"example-application-in-spring-boot",[71],{"type":54,"value":72},"Example Application in Spring Boot",{"type":49,"tag":50,"props":74,"children":75},{},[76],{"type":54,"value":77},"Let's consider a scenario where we need to create a microservice that sends emails asynchronously, with the ability to\nautomatically retry in case of transient failures.",{"type":49,"tag":67,"props":79,"children":81},{"id":80},"creating-the-spring-boot-application",[82],{"type":54,"value":83},"Creating the Spring Boot Application",{"type":49,"tag":50,"props":85,"children":86},{},[87],{"type":54,"value":88},"First, we need to create a new Spring Boot application using the Spring Initializr.",{"type":49,"tag":90,"props":91,"children":93},"h3",{"id":92},"_1-adding-dependencies",[94],{"type":54,"value":95},"1. Adding Dependencies",{"type":49,"tag":50,"props":97,"children":98},{},[99,101,110],{"type":54,"value":100},"Then, we’ll need to include\nthe ",{"type":49,"tag":102,"props":103,"children":107},"a",{"href":104,"rel":105},"https:\u002F\u002Fcentral.sonatype.com\u002Fartifact\u002Forg.springframework.boot\u002Fspring-boot-starter-web",[106],"nofollow",[108],{"type":54,"value":109},"spring-boot-starter-web",{"type":54,"value":111},"\nmaven dependency:",{"type":49,"tag":113,"props":114,"children":118},"pre",{"className":115,"code":116,"language":117,"meta":31,"style":31},"language-xml shiki shiki-themes nord github-dark monokai","\n\u003Cdependency>\n    \u003CgroupId>org.springframework.boot\u003C\u002FgroupId>\n    \u003CartifactId>spring-boot-starter-web\u003C\u002FartifactId>\n\u003C\u002Fdependency>\n","xml",[119],{"type":49,"tag":120,"props":121,"children":122},"code",{"__ignoreMap":31},[123,134,143,152,161],{"type":49,"tag":124,"props":125,"children":128},"span",{"class":126,"line":127},"line",1,[129],{"type":49,"tag":124,"props":130,"children":131},{"emptyLinePlaceholder":35},[132],{"type":54,"value":133},"\n",{"type":49,"tag":124,"props":135,"children":137},{"class":126,"line":136},2,[138],{"type":49,"tag":124,"props":139,"children":140},{},[141],{"type":54,"value":142},"\u003Cdependency>\n",{"type":49,"tag":124,"props":144,"children":146},{"class":126,"line":145},3,[147],{"type":49,"tag":124,"props":148,"children":149},{},[150],{"type":54,"value":151},"    \u003CgroupId>org.springframework.boot\u003C\u002FgroupId>\n",{"type":49,"tag":124,"props":153,"children":155},{"class":126,"line":154},4,[156],{"type":49,"tag":124,"props":157,"children":158},{},[159],{"type":54,"value":160},"    \u003CartifactId>spring-boot-starter-web\u003C\u002FartifactId>\n",{"type":49,"tag":124,"props":162,"children":164},{"class":126,"line":163},5,[165],{"type":49,"tag":124,"props":166,"children":167},{},[168],{"type":54,"value":169},"\u003C\u002Fdependency>\n",{"type":49,"tag":50,"props":171,"children":172},{},[173,175,182],{"type":54,"value":174},"Next we need\nthe ",{"type":49,"tag":102,"props":176,"children":179},{"href":177,"rel":178},"https:\u002F\u002Fcentral.sonatype.com\u002Fartifact\u002Forg.springframework.boot\u002Fspring-boot-starter-mail",[106],[180],{"type":54,"value":181},"spring-boot-starter-mail",{"type":54,"value":111},{"type":49,"tag":113,"props":184,"children":186},{"className":115,"code":185,"language":117,"meta":31,"style":31},"\n\u003Cdependency>\n    \u003CgroupId>org.springframework.boot\u003C\u002FgroupId>\n    \u003CartifactId>spring-boot-starter-mail\u003C\u002FartifactId>\n\u003C\u002Fdependency>\n",[187],{"type":49,"tag":120,"props":188,"children":189},{"__ignoreMap":31},[190,197,204,211,219],{"type":49,"tag":124,"props":191,"children":192},{"class":126,"line":127},[193],{"type":49,"tag":124,"props":194,"children":195},{"emptyLinePlaceholder":35},[196],{"type":54,"value":133},{"type":49,"tag":124,"props":198,"children":199},{"class":126,"line":136},[200],{"type":49,"tag":124,"props":201,"children":202},{},[203],{"type":54,"value":142},{"type":49,"tag":124,"props":205,"children":206},{"class":126,"line":145},[207],{"type":49,"tag":124,"props":208,"children":209},{},[210],{"type":54,"value":151},{"type":49,"tag":124,"props":212,"children":213},{"class":126,"line":154},[214],{"type":49,"tag":124,"props":215,"children":216},{},[217],{"type":54,"value":218},"    \u003CartifactId>spring-boot-starter-mail\u003C\u002FartifactId>\n",{"type":49,"tag":124,"props":220,"children":221},{"class":126,"line":163},[222],{"type":49,"tag":124,"props":223,"children":224},{},[225],{"type":54,"value":169},{"type":49,"tag":50,"props":227,"children":228},{},[229,231,238],{"type":54,"value":230},"Finally, we need to include\nthe ",{"type":49,"tag":102,"props":232,"children":235},{"href":233,"rel":234},"https:\u002F\u002Fcentral.sonatype.com\u002Fartifact\u002Forg.springframework.retry\u002Fspring-retry",[106],[236],{"type":54,"value":237},"spring-retry",{"type":54,"value":239}," dependency",{"type":49,"tag":113,"props":241,"children":243},{"className":115,"code":242,"language":117,"meta":31,"style":31},"\n\u003Cdependency>\n    \u003CgroupId>org.springframework.retry\u003C\u002FgroupId>\n    \u003CartifactId>spring-retry\u003C\u002FartifactId>\n\u003C\u002Fdependency>\n",[244],{"type":49,"tag":120,"props":245,"children":246},{"__ignoreMap":31},[247,254,261,269,277],{"type":49,"tag":124,"props":248,"children":249},{"class":126,"line":127},[250],{"type":49,"tag":124,"props":251,"children":252},{"emptyLinePlaceholder":35},[253],{"type":54,"value":133},{"type":49,"tag":124,"props":255,"children":256},{"class":126,"line":136},[257],{"type":49,"tag":124,"props":258,"children":259},{},[260],{"type":54,"value":142},{"type":49,"tag":124,"props":262,"children":263},{"class":126,"line":145},[264],{"type":49,"tag":124,"props":265,"children":266},{},[267],{"type":54,"value":268},"    \u003CgroupId>org.springframework.retry\u003C\u002FgroupId>\n",{"type":49,"tag":124,"props":270,"children":271},{"class":126,"line":154},[272],{"type":49,"tag":124,"props":273,"children":274},{},[275],{"type":54,"value":276},"    \u003CartifactId>spring-retry\u003C\u002FartifactId>\n",{"type":49,"tag":124,"props":278,"children":279},{"class":126,"line":163},[280],{"type":49,"tag":124,"props":281,"children":282},{},[283],{"type":54,"value":169},{"type":49,"tag":90,"props":285,"children":287},{"id":286},"_2-configuring-the-email-properties",[288],{"type":54,"value":289},"2. Configuring the Email Properties",{"type":49,"tag":50,"props":291,"children":292},{},[293],{"type":54,"value":294},"Next, we need to configure the email properties in the application.yaml file:",{"type":49,"tag":113,"props":296,"children":300},{"className":297,"code":298,"language":299,"meta":31,"style":31},"language-yaml shiki shiki-themes nord github-dark monokai","spring:\n  mail:\n    username: ${MAIL_USERNAME}\n    password: ${MAIL_PASSWORD}\n","yaml",[301],{"type":49,"tag":120,"props":302,"children":303},{"__ignoreMap":31},[304,319,331,350],{"type":49,"tag":124,"props":305,"children":306},{"class":126,"line":127},[307,313],{"type":49,"tag":124,"props":308,"children":310},{"style":309},"--shiki-default:#8FBCBB;--shiki-dark:#85E89D;--shiki-sepia:#F92672",[311],{"type":54,"value":312},"spring",{"type":49,"tag":124,"props":314,"children":316},{"style":315},"--shiki-default:#ECEFF4;--shiki-dark:#E1E4E8;--shiki-sepia:#F8F8F2",[317],{"type":54,"value":318},":\n",{"type":49,"tag":124,"props":320,"children":321},{"class":126,"line":136},[322,327],{"type":49,"tag":124,"props":323,"children":324},{"style":309},[325],{"type":54,"value":326},"  mail",{"type":49,"tag":124,"props":328,"children":329},{"style":315},[330],{"type":54,"value":318},{"type":49,"tag":124,"props":332,"children":333},{"class":126,"line":145},[334,339,344],{"type":49,"tag":124,"props":335,"children":336},{"style":309},[337],{"type":54,"value":338},"    username",{"type":49,"tag":124,"props":340,"children":341},{"style":315},[342],{"type":54,"value":343},":",{"type":49,"tag":124,"props":345,"children":347},{"style":346},"--shiki-default:#A3BE8C;--shiki-dark:#9ECBFF;--shiki-sepia:#E6DB74",[348],{"type":54,"value":349}," ${MAIL_USERNAME}\n",{"type":49,"tag":124,"props":351,"children":352},{"class":126,"line":154},[353,358,362],{"type":49,"tag":124,"props":354,"children":355},{"style":309},[356],{"type":54,"value":357},"    password",{"type":49,"tag":124,"props":359,"children":360},{"style":315},[361],{"type":54,"value":343},{"type":49,"tag":124,"props":363,"children":364},{"style":346},[365],{"type":54,"value":366}," ${MAIL_PASSWORD}\n",{"type":49,"tag":50,"props":368,"children":369},{},[370],{"type":54,"value":371},"Now, we need to create a configuration class to configure the JavaMailSender bean, which will be used to send emails.",{"type":49,"tag":113,"props":373,"children":377},{"className":374,"code":375,"language":376,"meta":31,"style":31},"language-java shiki shiki-themes nord github-dark monokai","@Configuration\npublic class AppConfiguration {\n\n    @Value(\"${spring.mail.username}\")\n    String username;\n\n    @Value(\"${spring.mail.password}\")\n    String password;\n\n    @Bean\n    public JavaMailSender javaMailSender() {\n\n        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();\n        mailSender.setHost(\"smtp.gmail.com\");\n        mailSender.setPort(587);\n\n        mailSender.setUsername(username);\n        mailSender.setPassword(password);\n\n        Properties props = mailSender.getJavaMailProperties();\n        props.put(\"mail.transport.protocol\", \"smtp\");\n        props.put(\"mail.smtp.auth\", \"true\");\n        props.put(\"mail.smtp.starttls.enable\", \"true\");\n\n        return mailSender;\n    }\n}\n","java",[378],{"type":49,"tag":120,"props":379,"children":380},{"__ignoreMap":31},[381,395,420,427,465,486,494,527,544,552,565,594,602,639,684,719,727,762,796,804,843,905,963,1020,1028,1045,1054],{"type":49,"tag":124,"props":382,"children":383},{"class":126,"line":127},[384,389],{"type":49,"tag":124,"props":385,"children":386},{"style":315},[387],{"type":54,"value":388},"@",{"type":49,"tag":124,"props":390,"children":392},{"style":391},"--shiki-default:#D08770;--shiki-default-font-style:inherit;--shiki-dark:#F97583;--shiki-dark-font-style:inherit;--shiki-sepia:#66D9EF;--shiki-sepia-font-style:italic",[393],{"type":54,"value":394},"Configuration\n",{"type":49,"tag":124,"props":396,"children":397},{"class":126,"line":136},[398,404,409,415],{"type":49,"tag":124,"props":399,"children":401},{"style":400},"--shiki-default:#81A1C1;--shiki-dark:#F97583;--shiki-sepia:#F92672",[402],{"type":54,"value":403},"public",{"type":49,"tag":124,"props":405,"children":406},{"style":400},[407],{"type":54,"value":408}," class",{"type":49,"tag":124,"props":410,"children":412},{"style":411},"--shiki-default:#8FBCBB;--shiki-default-text-decoration:inherit;--shiki-dark:#B392F0;--shiki-dark-text-decoration:inherit;--shiki-sepia:#A6E22E;--shiki-sepia-text-decoration:underline",[413],{"type":54,"value":414}," AppConfiguration",{"type":49,"tag":124,"props":416,"children":417},{"style":315},[418],{"type":54,"value":419}," {\n",{"type":49,"tag":124,"props":421,"children":422},{"class":126,"line":145},[423],{"type":49,"tag":124,"props":424,"children":425},{"emptyLinePlaceholder":35},[426],{"type":54,"value":133},{"type":49,"tag":124,"props":428,"children":429},{"class":126,"line":154},[430,435,440,445,451,456,460],{"type":49,"tag":124,"props":431,"children":432},{"style":315},[433],{"type":54,"value":434},"    @",{"type":49,"tag":124,"props":436,"children":437},{"style":391},[438],{"type":54,"value":439},"Value",{"type":49,"tag":124,"props":441,"children":442},{"style":315},[443],{"type":54,"value":444},"(",{"type":49,"tag":124,"props":446,"children":448},{"style":447},"--shiki-default:#ECEFF4;--shiki-dark:#9ECBFF;--shiki-sepia:#E6DB74",[449],{"type":54,"value":450},"\"",{"type":49,"tag":124,"props":452,"children":453},{"style":346},[454],{"type":54,"value":455},"${spring.mail.username}",{"type":49,"tag":124,"props":457,"children":458},{"style":447},[459],{"type":54,"value":450},{"type":49,"tag":124,"props":461,"children":462},{"style":315},[463],{"type":54,"value":464},")\n",{"type":49,"tag":124,"props":466,"children":467},{"class":126,"line":163},[468,474,480],{"type":49,"tag":124,"props":469,"children":471},{"style":470},"--shiki-default:#8FBCBB;--shiki-default-font-style:inherit;--shiki-dark:#E1E4E8;--shiki-dark-font-style:inherit;--shiki-sepia:#66D9EF;--shiki-sepia-font-style:italic",[472],{"type":54,"value":473},"    String",{"type":49,"tag":124,"props":475,"children":477},{"style":476},"--shiki-default:#D8DEE9;--shiki-dark:#E1E4E8;--shiki-sepia:#F8F8F2",[478],{"type":54,"value":479}," username",{"type":49,"tag":124,"props":481,"children":483},{"style":482},"--shiki-default:#81A1C1;--shiki-dark:#E1E4E8;--shiki-sepia:#F8F8F2",[484],{"type":54,"value":485},";\n",{"type":49,"tag":124,"props":487,"children":489},{"class":126,"line":488},6,[490],{"type":49,"tag":124,"props":491,"children":492},{"emptyLinePlaceholder":35},[493],{"type":54,"value":133},{"type":49,"tag":124,"props":495,"children":497},{"class":126,"line":496},7,[498,502,506,510,514,519,523],{"type":49,"tag":124,"props":499,"children":500},{"style":315},[501],{"type":54,"value":434},{"type":49,"tag":124,"props":503,"children":504},{"style":391},[505],{"type":54,"value":439},{"type":49,"tag":124,"props":507,"children":508},{"style":315},[509],{"type":54,"value":444},{"type":49,"tag":124,"props":511,"children":512},{"style":447},[513],{"type":54,"value":450},{"type":49,"tag":124,"props":515,"children":516},{"style":346},[517],{"type":54,"value":518},"${spring.mail.password}",{"type":49,"tag":124,"props":520,"children":521},{"style":447},[522],{"type":54,"value":450},{"type":49,"tag":124,"props":524,"children":525},{"style":315},[526],{"type":54,"value":464},{"type":49,"tag":124,"props":528,"children":530},{"class":126,"line":529},8,[531,535,540],{"type":49,"tag":124,"props":532,"children":533},{"style":470},[534],{"type":54,"value":473},{"type":49,"tag":124,"props":536,"children":537},{"style":476},[538],{"type":54,"value":539}," password",{"type":49,"tag":124,"props":541,"children":542},{"style":482},[543],{"type":54,"value":485},{"type":49,"tag":124,"props":545,"children":547},{"class":126,"line":546},9,[548],{"type":49,"tag":124,"props":549,"children":550},{"emptyLinePlaceholder":35},[551],{"type":54,"value":133},{"type":49,"tag":124,"props":553,"children":555},{"class":126,"line":554},10,[556,560],{"type":49,"tag":124,"props":557,"children":558},{"style":315},[559],{"type":54,"value":434},{"type":49,"tag":124,"props":561,"children":562},{"style":391},[563],{"type":54,"value":564},"Bean\n",{"type":49,"tag":124,"props":566,"children":568},{"class":126,"line":567},11,[569,574,579,585,590],{"type":49,"tag":124,"props":570,"children":571},{"style":400},[572],{"type":54,"value":573},"    public",{"type":49,"tag":124,"props":575,"children":576},{"style":470},[577],{"type":54,"value":578}," JavaMailSender",{"type":49,"tag":124,"props":580,"children":582},{"style":581},"--shiki-default:#88C0D0;--shiki-dark:#B392F0;--shiki-sepia:#A6E22E",[583],{"type":54,"value":584}," javaMailSender",{"type":49,"tag":124,"props":586,"children":587},{"style":315},[588],{"type":54,"value":589},"()",{"type":49,"tag":124,"props":591,"children":592},{"style":315},[593],{"type":54,"value":419},{"type":49,"tag":124,"props":595,"children":597},{"class":126,"line":596},12,[598],{"type":49,"tag":124,"props":599,"children":600},{"emptyLinePlaceholder":35},[601],{"type":54,"value":133},{"type":49,"tag":124,"props":603,"children":605},{"class":126,"line":604},13,[606,611,616,621,626,631,635],{"type":49,"tag":124,"props":607,"children":608},{"style":470},[609],{"type":54,"value":610},"        JavaMailSenderImpl",{"type":49,"tag":124,"props":612,"children":613},{"style":476},[614],{"type":54,"value":615}," mailSender",{"type":49,"tag":124,"props":617,"children":618},{"style":400},[619],{"type":54,"value":620}," =",{"type":49,"tag":124,"props":622,"children":623},{"style":400},[624],{"type":54,"value":625}," new",{"type":49,"tag":124,"props":627,"children":628},{"style":581},[629],{"type":54,"value":630}," JavaMailSenderImpl",{"type":49,"tag":124,"props":632,"children":633},{"style":315},[634],{"type":54,"value":589},{"type":49,"tag":124,"props":636,"children":637},{"style":482},[638],{"type":54,"value":485},{"type":49,"tag":124,"props":640,"children":642},{"class":126,"line":641},14,[643,648,653,658,662,666,671,675,680],{"type":49,"tag":124,"props":644,"children":645},{"style":476},[646],{"type":54,"value":647},"        mailSender",{"type":49,"tag":124,"props":649,"children":650},{"style":315},[651],{"type":54,"value":652},".",{"type":49,"tag":124,"props":654,"children":655},{"style":581},[656],{"type":54,"value":657},"setHost",{"type":49,"tag":124,"props":659,"children":660},{"style":315},[661],{"type":54,"value":444},{"type":49,"tag":124,"props":663,"children":664},{"style":447},[665],{"type":54,"value":450},{"type":49,"tag":124,"props":667,"children":668},{"style":346},[669],{"type":54,"value":670},"smtp.gmail.com",{"type":49,"tag":124,"props":672,"children":673},{"style":447},[674],{"type":54,"value":450},{"type":49,"tag":124,"props":676,"children":677},{"style":315},[678],{"type":54,"value":679},")",{"type":49,"tag":124,"props":681,"children":682},{"style":482},[683],{"type":54,"value":485},{"type":49,"tag":124,"props":685,"children":687},{"class":126,"line":686},15,[688,692,696,701,705,711,715],{"type":49,"tag":124,"props":689,"children":690},{"style":476},[691],{"type":54,"value":647},{"type":49,"tag":124,"props":693,"children":694},{"style":315},[695],{"type":54,"value":652},{"type":49,"tag":124,"props":697,"children":698},{"style":581},[699],{"type":54,"value":700},"setPort",{"type":49,"tag":124,"props":702,"children":703},{"style":315},[704],{"type":54,"value":444},{"type":49,"tag":124,"props":706,"children":708},{"style":707},"--shiki-default:#B48EAD;--shiki-dark:#79B8FF;--shiki-sepia:#AE81FF",[709],{"type":54,"value":710},"587",{"type":49,"tag":124,"props":712,"children":713},{"style":315},[714],{"type":54,"value":679},{"type":49,"tag":124,"props":716,"children":717},{"style":482},[718],{"type":54,"value":485},{"type":49,"tag":124,"props":720,"children":722},{"class":126,"line":721},16,[723],{"type":49,"tag":124,"props":724,"children":725},{"emptyLinePlaceholder":35},[726],{"type":54,"value":133},{"type":49,"tag":124,"props":728,"children":730},{"class":126,"line":729},17,[731,735,739,744,748,754,758],{"type":49,"tag":124,"props":732,"children":733},{"style":476},[734],{"type":54,"value":647},{"type":49,"tag":124,"props":736,"children":737},{"style":315},[738],{"type":54,"value":652},{"type":49,"tag":124,"props":740,"children":741},{"style":581},[742],{"type":54,"value":743},"setUsername",{"type":49,"tag":124,"props":745,"children":746},{"style":315},[747],{"type":54,"value":444},{"type":49,"tag":124,"props":749,"children":751},{"style":750},"--shiki-default:#D8DEE9FF;--shiki-dark:#E1E4E8;--shiki-sepia:#F8F8F2",[752],{"type":54,"value":753},"username",{"type":49,"tag":124,"props":755,"children":756},{"style":315},[757],{"type":54,"value":679},{"type":49,"tag":124,"props":759,"children":760},{"style":482},[761],{"type":54,"value":485},{"type":49,"tag":124,"props":763,"children":765},{"class":126,"line":764},18,[766,770,774,779,783,788,792],{"type":49,"tag":124,"props":767,"children":768},{"style":476},[769],{"type":54,"value":647},{"type":49,"tag":124,"props":771,"children":772},{"style":315},[773],{"type":54,"value":652},{"type":49,"tag":124,"props":775,"children":776},{"style":581},[777],{"type":54,"value":778},"setPassword",{"type":49,"tag":124,"props":780,"children":781},{"style":315},[782],{"type":54,"value":444},{"type":49,"tag":124,"props":784,"children":785},{"style":750},[786],{"type":54,"value":787},"password",{"type":49,"tag":124,"props":789,"children":790},{"style":315},[791],{"type":54,"value":679},{"type":49,"tag":124,"props":793,"children":794},{"style":482},[795],{"type":54,"value":485},{"type":49,"tag":124,"props":797,"children":799},{"class":126,"line":798},19,[800],{"type":49,"tag":124,"props":801,"children":802},{"emptyLinePlaceholder":35},[803],{"type":54,"value":133},{"type":49,"tag":124,"props":805,"children":807},{"class":126,"line":806},20,[808,813,818,822,826,830,835,839],{"type":49,"tag":124,"props":809,"children":810},{"style":470},[811],{"type":54,"value":812},"        Properties",{"type":49,"tag":124,"props":814,"children":815},{"style":476},[816],{"type":54,"value":817}," props",{"type":49,"tag":124,"props":819,"children":820},{"style":400},[821],{"type":54,"value":620},{"type":49,"tag":124,"props":823,"children":824},{"style":476},[825],{"type":54,"value":615},{"type":49,"tag":124,"props":827,"children":828},{"style":315},[829],{"type":54,"value":652},{"type":49,"tag":124,"props":831,"children":832},{"style":581},[833],{"type":54,"value":834},"getJavaMailProperties",{"type":49,"tag":124,"props":836,"children":837},{"style":315},[838],{"type":54,"value":589},{"type":49,"tag":124,"props":840,"children":841},{"style":482},[842],{"type":54,"value":485},{"type":49,"tag":124,"props":844,"children":846},{"class":126,"line":845},21,[847,852,856,861,865,869,874,878,883,888,893,897,901],{"type":49,"tag":124,"props":848,"children":849},{"style":476},[850],{"type":54,"value":851},"        props",{"type":49,"tag":124,"props":853,"children":854},{"style":315},[855],{"type":54,"value":652},{"type":49,"tag":124,"props":857,"children":858},{"style":581},[859],{"type":54,"value":860},"put",{"type":49,"tag":124,"props":862,"children":863},{"style":315},[864],{"type":54,"value":444},{"type":49,"tag":124,"props":866,"children":867},{"style":447},[868],{"type":54,"value":450},{"type":49,"tag":124,"props":870,"children":871},{"style":346},[872],{"type":54,"value":873},"mail.transport.protocol",{"type":49,"tag":124,"props":875,"children":876},{"style":447},[877],{"type":54,"value":450},{"type":49,"tag":124,"props":879,"children":880},{"style":315},[881],{"type":54,"value":882},",",{"type":49,"tag":124,"props":884,"children":885},{"style":447},[886],{"type":54,"value":887}," \"",{"type":49,"tag":124,"props":889,"children":890},{"style":346},[891],{"type":54,"value":892},"smtp",{"type":49,"tag":124,"props":894,"children":895},{"style":447},[896],{"type":54,"value":450},{"type":49,"tag":124,"props":898,"children":899},{"style":315},[900],{"type":54,"value":679},{"type":49,"tag":124,"props":902,"children":903},{"style":482},[904],{"type":54,"value":485},{"type":49,"tag":124,"props":906,"children":908},{"class":126,"line":907},22,[909,913,917,921,925,929,934,938,942,946,951,955,959],{"type":49,"tag":124,"props":910,"children":911},{"style":476},[912],{"type":54,"value":851},{"type":49,"tag":124,"props":914,"children":915},{"style":315},[916],{"type":54,"value":652},{"type":49,"tag":124,"props":918,"children":919},{"style":581},[920],{"type":54,"value":860},{"type":49,"tag":124,"props":922,"children":923},{"style":315},[924],{"type":54,"value":444},{"type":49,"tag":124,"props":926,"children":927},{"style":447},[928],{"type":54,"value":450},{"type":49,"tag":124,"props":930,"children":931},{"style":346},[932],{"type":54,"value":933},"mail.smtp.auth",{"type":49,"tag":124,"props":935,"children":936},{"style":447},[937],{"type":54,"value":450},{"type":49,"tag":124,"props":939,"children":940},{"style":315},[941],{"type":54,"value":882},{"type":49,"tag":124,"props":943,"children":944},{"style":447},[945],{"type":54,"value":887},{"type":49,"tag":124,"props":947,"children":948},{"style":346},[949],{"type":54,"value":950},"true",{"type":49,"tag":124,"props":952,"children":953},{"style":447},[954],{"type":54,"value":450},{"type":49,"tag":124,"props":956,"children":957},{"style":315},[958],{"type":54,"value":679},{"type":49,"tag":124,"props":960,"children":961},{"style":482},[962],{"type":54,"value":485},{"type":49,"tag":124,"props":964,"children":966},{"class":126,"line":965},23,[967,971,975,979,983,987,992,996,1000,1004,1008,1012,1016],{"type":49,"tag":124,"props":968,"children":969},{"style":476},[970],{"type":54,"value":851},{"type":49,"tag":124,"props":972,"children":973},{"style":315},[974],{"type":54,"value":652},{"type":49,"tag":124,"props":976,"children":977},{"style":581},[978],{"type":54,"value":860},{"type":49,"tag":124,"props":980,"children":981},{"style":315},[982],{"type":54,"value":444},{"type":49,"tag":124,"props":984,"children":985},{"style":447},[986],{"type":54,"value":450},{"type":49,"tag":124,"props":988,"children":989},{"style":346},[990],{"type":54,"value":991},"mail.smtp.starttls.enable",{"type":49,"tag":124,"props":993,"children":994},{"style":447},[995],{"type":54,"value":450},{"type":49,"tag":124,"props":997,"children":998},{"style":315},[999],{"type":54,"value":882},{"type":49,"tag":124,"props":1001,"children":1002},{"style":447},[1003],{"type":54,"value":887},{"type":49,"tag":124,"props":1005,"children":1006},{"style":346},[1007],{"type":54,"value":950},{"type":49,"tag":124,"props":1009,"children":1010},{"style":447},[1011],{"type":54,"value":450},{"type":49,"tag":124,"props":1013,"children":1014},{"style":315},[1015],{"type":54,"value":679},{"type":49,"tag":124,"props":1017,"children":1018},{"style":482},[1019],{"type":54,"value":485},{"type":49,"tag":124,"props":1021,"children":1023},{"class":126,"line":1022},24,[1024],{"type":49,"tag":124,"props":1025,"children":1026},{"emptyLinePlaceholder":35},[1027],{"type":54,"value":133},{"type":49,"tag":124,"props":1029,"children":1031},{"class":126,"line":1030},25,[1032,1037,1041],{"type":49,"tag":124,"props":1033,"children":1034},{"style":400},[1035],{"type":54,"value":1036},"        return",{"type":49,"tag":124,"props":1038,"children":1039},{"style":750},[1040],{"type":54,"value":615},{"type":49,"tag":124,"props":1042,"children":1043},{"style":482},[1044],{"type":54,"value":485},{"type":49,"tag":124,"props":1046,"children":1048},{"class":126,"line":1047},26,[1049],{"type":49,"tag":124,"props":1050,"children":1051},{"style":315},[1052],{"type":54,"value":1053},"    }\n",{"type":49,"tag":124,"props":1055,"children":1057},{"class":126,"line":1056},27,[1058],{"type":49,"tag":124,"props":1059,"children":1060},{"style":315},[1061],{"type":54,"value":1062},"}\n",{"type":49,"tag":90,"props":1064,"children":1066},{"id":1065},"_3-implementing-the-emailservice",[1067],{"type":54,"value":1068},"3. Implementing the EmailService",{"type":49,"tag":50,"props":1070,"children":1071},{},[1072],{"type":54,"value":1073},"Now, let's implement the EmailService class, which will be responsible for sending emails:",{"type":49,"tag":113,"props":1075,"children":1077},{"className":374,"code":1076,"language":376,"meta":31,"style":31},"@Service\npublic class EmailService {\n\n    private static final Logger logger = LoggerFactory.getLogger(EmailService.class);\n\n    private final JavaMailSender javaMailSender;\n\n    public EmailService(JavaMailSender javaMailSender) {\n        this.javaMailSender = javaMailSender;\n    }\n\n    public String sendEmail(String to, String subject, String body) throws MessagingException, IOException {\n        logger.info(\"Trying to send email to {}\", to);\n\n        String senderName = \"Asynchronous Email Service\";\n        String from = \"nidhalnaffati@gmail.com\";\n\n        MimeMessage message = javaMailSender.createMimeMessage();\n        MimeMessageHelper helper = new MimeMessageHelper(message, \"UTF-8\");\n\n        helper.setFrom(from, senderName);\n        helper.setTo(to);\n        helper.setSubject(subject);\n        helper.setText(body);\n\n        javaMailSender.send(message);\n        logger.info(\"Email sent\");\n\n        return \"Email sent to \" + to;\n    }\n}\n\n",[1078],{"type":49,"tag":120,"props":1079,"children":1080},{"__ignoreMap":31},[1081,1093,1113,1120,1192,1199,1222,1229,1262,1292,1299,1306,1390,1440,1447,1481,1514,1521,1559,1619,1626,1668,1701,1734,1767,1774,1807,1847,1855,1889,1897],{"type":49,"tag":124,"props":1082,"children":1083},{"class":126,"line":127},[1084,1088],{"type":49,"tag":124,"props":1085,"children":1086},{"style":315},[1087],{"type":54,"value":388},{"type":49,"tag":124,"props":1089,"children":1090},{"style":391},[1091],{"type":54,"value":1092},"Service\n",{"type":49,"tag":124,"props":1094,"children":1095},{"class":126,"line":136},[1096,1100,1104,1109],{"type":49,"tag":124,"props":1097,"children":1098},{"style":400},[1099],{"type":54,"value":403},{"type":49,"tag":124,"props":1101,"children":1102},{"style":400},[1103],{"type":54,"value":408},{"type":49,"tag":124,"props":1105,"children":1106},{"style":411},[1107],{"type":54,"value":1108}," EmailService",{"type":49,"tag":124,"props":1110,"children":1111},{"style":315},[1112],{"type":54,"value":419},{"type":49,"tag":124,"props":1114,"children":1115},{"class":126,"line":145},[1116],{"type":49,"tag":124,"props":1117,"children":1118},{"emptyLinePlaceholder":35},[1119],{"type":54,"value":133},{"type":49,"tag":124,"props":1121,"children":1122},{"class":126,"line":154},[1123,1128,1133,1138,1143,1148,1152,1157,1161,1166,1170,1175,1179,1184,1188],{"type":49,"tag":124,"props":1124,"children":1125},{"style":400},[1126],{"type":54,"value":1127},"    private",{"type":49,"tag":124,"props":1129,"children":1130},{"style":400},[1131],{"type":54,"value":1132}," static",{"type":49,"tag":124,"props":1134,"children":1135},{"style":400},[1136],{"type":54,"value":1137}," final",{"type":49,"tag":124,"props":1139,"children":1140},{"style":470},[1141],{"type":54,"value":1142}," Logger",{"type":49,"tag":124,"props":1144,"children":1145},{"style":476},[1146],{"type":54,"value":1147}," logger",{"type":49,"tag":124,"props":1149,"children":1150},{"style":400},[1151],{"type":54,"value":620},{"type":49,"tag":124,"props":1153,"children":1154},{"style":476},[1155],{"type":54,"value":1156}," LoggerFactory",{"type":49,"tag":124,"props":1158,"children":1159},{"style":315},[1160],{"type":54,"value":652},{"type":49,"tag":124,"props":1162,"children":1163},{"style":581},[1164],{"type":54,"value":1165},"getLogger",{"type":49,"tag":124,"props":1167,"children":1168},{"style":315},[1169],{"type":54,"value":444},{"type":49,"tag":124,"props":1171,"children":1172},{"style":476},[1173],{"type":54,"value":1174},"EmailService",{"type":49,"tag":124,"props":1176,"children":1177},{"style":315},[1178],{"type":54,"value":652},{"type":49,"tag":124,"props":1180,"children":1181},{"style":476},[1182],{"type":54,"value":1183},"class",{"type":49,"tag":124,"props":1185,"children":1186},{"style":315},[1187],{"type":54,"value":679},{"type":49,"tag":124,"props":1189,"children":1190},{"style":482},[1191],{"type":54,"value":485},{"type":49,"tag":124,"props":1193,"children":1194},{"class":126,"line":163},[1195],{"type":49,"tag":124,"props":1196,"children":1197},{"emptyLinePlaceholder":35},[1198],{"type":54,"value":133},{"type":49,"tag":124,"props":1200,"children":1201},{"class":126,"line":488},[1202,1206,1210,1214,1218],{"type":49,"tag":124,"props":1203,"children":1204},{"style":400},[1205],{"type":54,"value":1127},{"type":49,"tag":124,"props":1207,"children":1208},{"style":400},[1209],{"type":54,"value":1137},{"type":49,"tag":124,"props":1211,"children":1212},{"style":470},[1213],{"type":54,"value":578},{"type":49,"tag":124,"props":1215,"children":1216},{"style":476},[1217],{"type":54,"value":584},{"type":49,"tag":124,"props":1219,"children":1220},{"style":482},[1221],{"type":54,"value":485},{"type":49,"tag":124,"props":1223,"children":1224},{"class":126,"line":496},[1225],{"type":49,"tag":124,"props":1226,"children":1227},{"emptyLinePlaceholder":35},[1228],{"type":54,"value":133},{"type":49,"tag":124,"props":1230,"children":1231},{"class":126,"line":529},[1232,1236,1240,1244,1249,1254,1258],{"type":49,"tag":124,"props":1233,"children":1234},{"style":400},[1235],{"type":54,"value":573},{"type":49,"tag":124,"props":1237,"children":1238},{"style":581},[1239],{"type":54,"value":1108},{"type":49,"tag":124,"props":1241,"children":1242},{"style":315},[1243],{"type":54,"value":444},{"type":49,"tag":124,"props":1245,"children":1246},{"style":470},[1247],{"type":54,"value":1248},"JavaMailSender",{"type":49,"tag":124,"props":1250,"children":1252},{"style":1251},"--shiki-default:#D8DEE9;--shiki-default-font-style:inherit;--shiki-dark:#FFAB70;--shiki-dark-font-style:inherit;--shiki-sepia:#FD971F;--shiki-sepia-font-style:italic",[1253],{"type":54,"value":584},{"type":49,"tag":124,"props":1255,"children":1256},{"style":315},[1257],{"type":54,"value":679},{"type":49,"tag":124,"props":1259,"children":1260},{"style":315},[1261],{"type":54,"value":419},{"type":49,"tag":124,"props":1263,"children":1264},{"class":126,"line":546},[1265,1271,1275,1280,1284,1288],{"type":49,"tag":124,"props":1266,"children":1268},{"style":1267},"--shiki-default:#81A1C1;--shiki-dark:#79B8FF;--shiki-sepia:#FD971F",[1269],{"type":54,"value":1270},"        this",{"type":49,"tag":124,"props":1272,"children":1273},{"style":315},[1274],{"type":54,"value":652},{"type":49,"tag":124,"props":1276,"children":1277},{"style":476},[1278],{"type":54,"value":1279},"javaMailSender",{"type":49,"tag":124,"props":1281,"children":1282},{"style":400},[1283],{"type":54,"value":620},{"type":49,"tag":124,"props":1285,"children":1286},{"style":750},[1287],{"type":54,"value":584},{"type":49,"tag":124,"props":1289,"children":1290},{"style":482},[1291],{"type":54,"value":485},{"type":49,"tag":124,"props":1293,"children":1294},{"class":126,"line":554},[1295],{"type":49,"tag":124,"props":1296,"children":1297},{"style":315},[1298],{"type":54,"value":1053},{"type":49,"tag":124,"props":1300,"children":1301},{"class":126,"line":567},[1302],{"type":49,"tag":124,"props":1303,"children":1304},{"emptyLinePlaceholder":35},[1305],{"type":54,"value":133},{"type":49,"tag":124,"props":1307,"children":1308},{"class":126,"line":596},[1309,1313,1318,1323,1327,1332,1337,1341,1345,1350,1354,1358,1363,1367,1372,1377,1381,1386],{"type":49,"tag":124,"props":1310,"children":1311},{"style":400},[1312],{"type":54,"value":573},{"type":49,"tag":124,"props":1314,"children":1315},{"style":470},[1316],{"type":54,"value":1317}," String",{"type":49,"tag":124,"props":1319,"children":1320},{"style":581},[1321],{"type":54,"value":1322}," sendEmail",{"type":49,"tag":124,"props":1324,"children":1325},{"style":315},[1326],{"type":54,"value":444},{"type":49,"tag":124,"props":1328,"children":1329},{"style":470},[1330],{"type":54,"value":1331},"String",{"type":49,"tag":124,"props":1333,"children":1334},{"style":1251},[1335],{"type":54,"value":1336}," to",{"type":49,"tag":124,"props":1338,"children":1339},{"style":315},[1340],{"type":54,"value":882},{"type":49,"tag":124,"props":1342,"children":1343},{"style":470},[1344],{"type":54,"value":1317},{"type":49,"tag":124,"props":1346,"children":1347},{"style":1251},[1348],{"type":54,"value":1349}," subject",{"type":49,"tag":124,"props":1351,"children":1352},{"style":315},[1353],{"type":54,"value":882},{"type":49,"tag":124,"props":1355,"children":1356},{"style":470},[1357],{"type":54,"value":1317},{"type":49,"tag":124,"props":1359,"children":1360},{"style":1251},[1361],{"type":54,"value":1362}," body",{"type":49,"tag":124,"props":1364,"children":1365},{"style":315},[1366],{"type":54,"value":679},{"type":49,"tag":124,"props":1368,"children":1369},{"style":400},[1370],{"type":54,"value":1371}," throws",{"type":49,"tag":124,"props":1373,"children":1374},{"style":470},[1375],{"type":54,"value":1376}," MessagingException",{"type":49,"tag":124,"props":1378,"children":1379},{"style":315},[1380],{"type":54,"value":882},{"type":49,"tag":124,"props":1382,"children":1383},{"style":470},[1384],{"type":54,"value":1385}," IOException",{"type":49,"tag":124,"props":1387,"children":1388},{"style":315},[1389],{"type":54,"value":419},{"type":49,"tag":124,"props":1391,"children":1392},{"class":126,"line":604},[1393,1398,1402,1407,1411,1415,1420,1424,1428,1432,1436],{"type":49,"tag":124,"props":1394,"children":1395},{"style":476},[1396],{"type":54,"value":1397},"        logger",{"type":49,"tag":124,"props":1399,"children":1400},{"style":315},[1401],{"type":54,"value":652},{"type":49,"tag":124,"props":1403,"children":1404},{"style":581},[1405],{"type":54,"value":1406},"info",{"type":49,"tag":124,"props":1408,"children":1409},{"style":315},[1410],{"type":54,"value":444},{"type":49,"tag":124,"props":1412,"children":1413},{"style":447},[1414],{"type":54,"value":450},{"type":49,"tag":124,"props":1416,"children":1417},{"style":346},[1418],{"type":54,"value":1419},"Trying to send email to {}",{"type":49,"tag":124,"props":1421,"children":1422},{"style":447},[1423],{"type":54,"value":450},{"type":49,"tag":124,"props":1425,"children":1426},{"style":315},[1427],{"type":54,"value":882},{"type":49,"tag":124,"props":1429,"children":1430},{"style":750},[1431],{"type":54,"value":1336},{"type":49,"tag":124,"props":1433,"children":1434},{"style":315},[1435],{"type":54,"value":679},{"type":49,"tag":124,"props":1437,"children":1438},{"style":482},[1439],{"type":54,"value":485},{"type":49,"tag":124,"props":1441,"children":1442},{"class":126,"line":641},[1443],{"type":49,"tag":124,"props":1444,"children":1445},{"emptyLinePlaceholder":35},[1446],{"type":54,"value":133},{"type":49,"tag":124,"props":1448,"children":1449},{"class":126,"line":686},[1450,1455,1460,1464,1468,1473,1477],{"type":49,"tag":124,"props":1451,"children":1452},{"style":470},[1453],{"type":54,"value":1454},"        String",{"type":49,"tag":124,"props":1456,"children":1457},{"style":476},[1458],{"type":54,"value":1459}," senderName",{"type":49,"tag":124,"props":1461,"children":1462},{"style":400},[1463],{"type":54,"value":620},{"type":49,"tag":124,"props":1465,"children":1466},{"style":447},[1467],{"type":54,"value":887},{"type":49,"tag":124,"props":1469,"children":1470},{"style":346},[1471],{"type":54,"value":1472},"Asynchronous Email Service",{"type":49,"tag":124,"props":1474,"children":1475},{"style":447},[1476],{"type":54,"value":450},{"type":49,"tag":124,"props":1478,"children":1479},{"style":482},[1480],{"type":54,"value":485},{"type":49,"tag":124,"props":1482,"children":1483},{"class":126,"line":721},[1484,1488,1493,1497,1501,1506,1510],{"type":49,"tag":124,"props":1485,"children":1486},{"style":470},[1487],{"type":54,"value":1454},{"type":49,"tag":124,"props":1489,"children":1490},{"style":476},[1491],{"type":54,"value":1492}," from",{"type":49,"tag":124,"props":1494,"children":1495},{"style":400},[1496],{"type":54,"value":620},{"type":49,"tag":124,"props":1498,"children":1499},{"style":447},[1500],{"type":54,"value":887},{"type":49,"tag":124,"props":1502,"children":1503},{"style":346},[1504],{"type":54,"value":1505},"nidhalnaffati@gmail.com",{"type":49,"tag":124,"props":1507,"children":1508},{"style":447},[1509],{"type":54,"value":450},{"type":49,"tag":124,"props":1511,"children":1512},{"style":482},[1513],{"type":54,"value":485},{"type":49,"tag":124,"props":1515,"children":1516},{"class":126,"line":729},[1517],{"type":49,"tag":124,"props":1518,"children":1519},{"emptyLinePlaceholder":35},[1520],{"type":54,"value":133},{"type":49,"tag":124,"props":1522,"children":1523},{"class":126,"line":764},[1524,1529,1534,1538,1542,1546,1551,1555],{"type":49,"tag":124,"props":1525,"children":1526},{"style":470},[1527],{"type":54,"value":1528},"        MimeMessage",{"type":49,"tag":124,"props":1530,"children":1531},{"style":476},[1532],{"type":54,"value":1533}," message",{"type":49,"tag":124,"props":1535,"children":1536},{"style":400},[1537],{"type":54,"value":620},{"type":49,"tag":124,"props":1539,"children":1540},{"style":476},[1541],{"type":54,"value":584},{"type":49,"tag":124,"props":1543,"children":1544},{"style":315},[1545],{"type":54,"value":652},{"type":49,"tag":124,"props":1547,"children":1548},{"style":581},[1549],{"type":54,"value":1550},"createMimeMessage",{"type":49,"tag":124,"props":1552,"children":1553},{"style":315},[1554],{"type":54,"value":589},{"type":49,"tag":124,"props":1556,"children":1557},{"style":482},[1558],{"type":54,"value":485},{"type":49,"tag":124,"props":1560,"children":1561},{"class":126,"line":798},[1562,1567,1572,1576,1580,1585,1589,1594,1598,1602,1607,1611,1615],{"type":49,"tag":124,"props":1563,"children":1564},{"style":470},[1565],{"type":54,"value":1566},"        MimeMessageHelper",{"type":49,"tag":124,"props":1568,"children":1569},{"style":476},[1570],{"type":54,"value":1571}," helper",{"type":49,"tag":124,"props":1573,"children":1574},{"style":400},[1575],{"type":54,"value":620},{"type":49,"tag":124,"props":1577,"children":1578},{"style":400},[1579],{"type":54,"value":625},{"type":49,"tag":124,"props":1581,"children":1582},{"style":581},[1583],{"type":54,"value":1584}," MimeMessageHelper",{"type":49,"tag":124,"props":1586,"children":1587},{"style":315},[1588],{"type":54,"value":444},{"type":49,"tag":124,"props":1590,"children":1591},{"style":750},[1592],{"type":54,"value":1593},"message",{"type":49,"tag":124,"props":1595,"children":1596},{"style":315},[1597],{"type":54,"value":882},{"type":49,"tag":124,"props":1599,"children":1600},{"style":447},[1601],{"type":54,"value":887},{"type":49,"tag":124,"props":1603,"children":1604},{"style":346},[1605],{"type":54,"value":1606},"UTF-8",{"type":49,"tag":124,"props":1608,"children":1609},{"style":447},[1610],{"type":54,"value":450},{"type":49,"tag":124,"props":1612,"children":1613},{"style":315},[1614],{"type":54,"value":679},{"type":49,"tag":124,"props":1616,"children":1617},{"style":482},[1618],{"type":54,"value":485},{"type":49,"tag":124,"props":1620,"children":1621},{"class":126,"line":806},[1622],{"type":49,"tag":124,"props":1623,"children":1624},{"emptyLinePlaceholder":35},[1625],{"type":54,"value":133},{"type":49,"tag":124,"props":1627,"children":1628},{"class":126,"line":845},[1629,1634,1638,1643,1647,1652,1656,1660,1664],{"type":49,"tag":124,"props":1630,"children":1631},{"style":476},[1632],{"type":54,"value":1633},"        helper",{"type":49,"tag":124,"props":1635,"children":1636},{"style":315},[1637],{"type":54,"value":652},{"type":49,"tag":124,"props":1639,"children":1640},{"style":581},[1641],{"type":54,"value":1642},"setFrom",{"type":49,"tag":124,"props":1644,"children":1645},{"style":315},[1646],{"type":54,"value":444},{"type":49,"tag":124,"props":1648,"children":1649},{"style":750},[1650],{"type":54,"value":1651},"from",{"type":49,"tag":124,"props":1653,"children":1654},{"style":315},[1655],{"type":54,"value":882},{"type":49,"tag":124,"props":1657,"children":1658},{"style":750},[1659],{"type":54,"value":1459},{"type":49,"tag":124,"props":1661,"children":1662},{"style":315},[1663],{"type":54,"value":679},{"type":49,"tag":124,"props":1665,"children":1666},{"style":482},[1667],{"type":54,"value":485},{"type":49,"tag":124,"props":1669,"children":1670},{"class":126,"line":907},[1671,1675,1679,1684,1688,1693,1697],{"type":49,"tag":124,"props":1672,"children":1673},{"style":476},[1674],{"type":54,"value":1633},{"type":49,"tag":124,"props":1676,"children":1677},{"style":315},[1678],{"type":54,"value":652},{"type":49,"tag":124,"props":1680,"children":1681},{"style":581},[1682],{"type":54,"value":1683},"setTo",{"type":49,"tag":124,"props":1685,"children":1686},{"style":315},[1687],{"type":54,"value":444},{"type":49,"tag":124,"props":1689,"children":1690},{"style":750},[1691],{"type":54,"value":1692},"to",{"type":49,"tag":124,"props":1694,"children":1695},{"style":315},[1696],{"type":54,"value":679},{"type":49,"tag":124,"props":1698,"children":1699},{"style":482},[1700],{"type":54,"value":485},{"type":49,"tag":124,"props":1702,"children":1703},{"class":126,"line":965},[1704,1708,1712,1717,1721,1726,1730],{"type":49,"tag":124,"props":1705,"children":1706},{"style":476},[1707],{"type":54,"value":1633},{"type":49,"tag":124,"props":1709,"children":1710},{"style":315},[1711],{"type":54,"value":652},{"type":49,"tag":124,"props":1713,"children":1714},{"style":581},[1715],{"type":54,"value":1716},"setSubject",{"type":49,"tag":124,"props":1718,"children":1719},{"style":315},[1720],{"type":54,"value":444},{"type":49,"tag":124,"props":1722,"children":1723},{"style":750},[1724],{"type":54,"value":1725},"subject",{"type":49,"tag":124,"props":1727,"children":1728},{"style":315},[1729],{"type":54,"value":679},{"type":49,"tag":124,"props":1731,"children":1732},{"style":482},[1733],{"type":54,"value":485},{"type":49,"tag":124,"props":1735,"children":1736},{"class":126,"line":1022},[1737,1741,1745,1750,1754,1759,1763],{"type":49,"tag":124,"props":1738,"children":1739},{"style":476},[1740],{"type":54,"value":1633},{"type":49,"tag":124,"props":1742,"children":1743},{"style":315},[1744],{"type":54,"value":652},{"type":49,"tag":124,"props":1746,"children":1747},{"style":581},[1748],{"type":54,"value":1749},"setText",{"type":49,"tag":124,"props":1751,"children":1752},{"style":315},[1753],{"type":54,"value":444},{"type":49,"tag":124,"props":1755,"children":1756},{"style":750},[1757],{"type":54,"value":1758},"body",{"type":49,"tag":124,"props":1760,"children":1761},{"style":315},[1762],{"type":54,"value":679},{"type":49,"tag":124,"props":1764,"children":1765},{"style":482},[1766],{"type":54,"value":485},{"type":49,"tag":124,"props":1768,"children":1769},{"class":126,"line":1030},[1770],{"type":49,"tag":124,"props":1771,"children":1772},{"emptyLinePlaceholder":35},[1773],{"type":54,"value":133},{"type":49,"tag":124,"props":1775,"children":1776},{"class":126,"line":1047},[1777,1782,1786,1791,1795,1799,1803],{"type":49,"tag":124,"props":1778,"children":1779},{"style":476},[1780],{"type":54,"value":1781},"        javaMailSender",{"type":49,"tag":124,"props":1783,"children":1784},{"style":315},[1785],{"type":54,"value":652},{"type":49,"tag":124,"props":1787,"children":1788},{"style":581},[1789],{"type":54,"value":1790},"send",{"type":49,"tag":124,"props":1792,"children":1793},{"style":315},[1794],{"type":54,"value":444},{"type":49,"tag":124,"props":1796,"children":1797},{"style":750},[1798],{"type":54,"value":1593},{"type":49,"tag":124,"props":1800,"children":1801},{"style":315},[1802],{"type":54,"value":679},{"type":49,"tag":124,"props":1804,"children":1805},{"style":482},[1806],{"type":54,"value":485},{"type":49,"tag":124,"props":1808,"children":1809},{"class":126,"line":1056},[1810,1814,1818,1822,1826,1830,1835,1839,1843],{"type":49,"tag":124,"props":1811,"children":1812},{"style":476},[1813],{"type":54,"value":1397},{"type":49,"tag":124,"props":1815,"children":1816},{"style":315},[1817],{"type":54,"value":652},{"type":49,"tag":124,"props":1819,"children":1820},{"style":581},[1821],{"type":54,"value":1406},{"type":49,"tag":124,"props":1823,"children":1824},{"style":315},[1825],{"type":54,"value":444},{"type":49,"tag":124,"props":1827,"children":1828},{"style":447},[1829],{"type":54,"value":450},{"type":49,"tag":124,"props":1831,"children":1832},{"style":346},[1833],{"type":54,"value":1834},"Email sent",{"type":49,"tag":124,"props":1836,"children":1837},{"style":447},[1838],{"type":54,"value":450},{"type":49,"tag":124,"props":1840,"children":1841},{"style":315},[1842],{"type":54,"value":679},{"type":49,"tag":124,"props":1844,"children":1845},{"style":482},[1846],{"type":54,"value":485},{"type":49,"tag":124,"props":1848,"children":1850},{"class":126,"line":1849},28,[1851],{"type":49,"tag":124,"props":1852,"children":1853},{"emptyLinePlaceholder":35},[1854],{"type":54,"value":133},{"type":49,"tag":124,"props":1856,"children":1858},{"class":126,"line":1857},29,[1859,1863,1867,1872,1876,1881,1885],{"type":49,"tag":124,"props":1860,"children":1861},{"style":400},[1862],{"type":54,"value":1036},{"type":49,"tag":124,"props":1864,"children":1865},{"style":447},[1866],{"type":54,"value":887},{"type":49,"tag":124,"props":1868,"children":1869},{"style":346},[1870],{"type":54,"value":1871},"Email sent to ",{"type":49,"tag":124,"props":1873,"children":1874},{"style":447},[1875],{"type":54,"value":450},{"type":49,"tag":124,"props":1877,"children":1878},{"style":400},[1879],{"type":54,"value":1880}," +",{"type":49,"tag":124,"props":1882,"children":1883},{"style":750},[1884],{"type":54,"value":1336},{"type":49,"tag":124,"props":1886,"children":1887},{"style":482},[1888],{"type":54,"value":485},{"type":49,"tag":124,"props":1890,"children":1892},{"class":126,"line":1891},30,[1893],{"type":49,"tag":124,"props":1894,"children":1895},{"style":315},[1896],{"type":54,"value":1053},{"type":49,"tag":124,"props":1898,"children":1900},{"class":126,"line":1899},31,[1901],{"type":49,"tag":124,"props":1902,"children":1903},{"style":315},[1904],{"type":54,"value":1062},{"type":49,"tag":90,"props":1906,"children":1908},{"id":1907},"_4-implementing-asynchronous-execution-with-retry",[1909],{"type":54,"value":1910},"4. Implementing Asynchronous Execution With Retry",{"type":49,"tag":50,"props":1912,"children":1913},{},[1914],{"type":54,"value":1915},"To achieve asynchronous execution with retry for the email sending process, follow these steps:",{"type":49,"tag":50,"props":1917,"children":1918},{},[1919],{"type":54,"value":1920},"First, we need to add the @EnableAsync and @EnableRetry annotations to a configuration class to enable asynchronous\nexecution and retry operations in the Spring Boot application.",{"type":49,"tag":50,"props":1922,"children":1923},{},[1924],{"type":54,"value":1925},"We already have the AppConfiguration class, so we can add these annotations to it.",{"type":49,"tag":50,"props":1927,"children":1928},{},[1929],{"type":54,"value":1930},"So it will look like this:",{"type":49,"tag":113,"props":1932,"children":1934},{"className":374,"code":1933,"language":376,"meta":31,"style":31},"@EnableAsync\n@EnableRetry\n@Configuration\npublic class AppConfiguration {\n    \u002F\u002F same code as before\n}\n",[1935],{"type":49,"tag":120,"props":1936,"children":1937},{"__ignoreMap":31},[1938,1950,1962,1973,1992,2001],{"type":49,"tag":124,"props":1939,"children":1940},{"class":126,"line":127},[1941,1945],{"type":49,"tag":124,"props":1942,"children":1943},{"style":315},[1944],{"type":54,"value":388},{"type":49,"tag":124,"props":1946,"children":1947},{"style":391},[1948],{"type":54,"value":1949},"EnableAsync\n",{"type":49,"tag":124,"props":1951,"children":1952},{"class":126,"line":136},[1953,1957],{"type":49,"tag":124,"props":1954,"children":1955},{"style":315},[1956],{"type":54,"value":388},{"type":49,"tag":124,"props":1958,"children":1959},{"style":391},[1960],{"type":54,"value":1961},"EnableRetry\n",{"type":49,"tag":124,"props":1963,"children":1964},{"class":126,"line":145},[1965,1969],{"type":49,"tag":124,"props":1966,"children":1967},{"style":315},[1968],{"type":54,"value":388},{"type":49,"tag":124,"props":1970,"children":1971},{"style":391},[1972],{"type":54,"value":394},{"type":49,"tag":124,"props":1974,"children":1975},{"class":126,"line":154},[1976,1980,1984,1988],{"type":49,"tag":124,"props":1977,"children":1978},{"style":400},[1979],{"type":54,"value":403},{"type":49,"tag":124,"props":1981,"children":1982},{"style":400},[1983],{"type":54,"value":408},{"type":49,"tag":124,"props":1985,"children":1986},{"style":411},[1987],{"type":54,"value":414},{"type":49,"tag":124,"props":1989,"children":1990},{"style":315},[1991],{"type":54,"value":419},{"type":49,"tag":124,"props":1993,"children":1994},{"class":126,"line":163},[1995],{"type":49,"tag":124,"props":1996,"children":1998},{"style":1997},"--shiki-default:#616E88;--shiki-dark:#6A737D;--shiki-sepia:#88846F",[1999],{"type":54,"value":2000},"    \u002F\u002F same code as before\n",{"type":49,"tag":124,"props":2002,"children":2003},{"class":126,"line":488},[2004],{"type":49,"tag":124,"props":2005,"children":2006},{"style":315},[2007],{"type":54,"value":1062},{"type":49,"tag":50,"props":2009,"children":2010},{},[2011],{"type":54,"value":2012},"Next, we need to modify the EmailService class to execute the sendEmail method asynchronously and to retry the execution\nin case of a failure.",{"type":49,"tag":50,"props":2014,"children":2015},{},[2016],{"type":54,"value":2017},"But before that I want to create a function to simulate the failure of the email sending process, so we can test the\nretry mechanism.",{"type":49,"tag":113,"props":2019,"children":2021},{"className":374,"code":2020,"language":376,"meta":31,"style":31},"public void simulateRandomFailure() throws MessagingException {\n        \u002F\u002F generate a random number between 1 and 6\n        int random = (int) (Math.random() * 6 + 1);\n\n        logger.info(\"Random number: {}\", random);\n\n        if (random \u003C 5) { \u002F\u002F 4 out of 6 chances to fail\n            logger.error(\"Simulating a random failure\");\n            throw new MessagingException(\"Failed to send email\");\n        }\n} \n",[2022],{"type":49,"tag":120,"props":2023,"children":2024},{"__ignoreMap":31},[2025,2057,2065,2145,2152,2200,2207,2248,2290,2331,2339],{"type":49,"tag":124,"props":2026,"children":2027},{"class":126,"line":127},[2028,2032,2038,2043,2047,2052],{"type":49,"tag":124,"props":2029,"children":2030},{"style":400},[2031],{"type":54,"value":403},{"type":49,"tag":124,"props":2033,"children":2035},{"style":2034},"--shiki-default:#81A1C1;--shiki-default-font-style:inherit;--shiki-dark:#F97583;--shiki-dark-font-style:inherit;--shiki-sepia:#66D9EF;--shiki-sepia-font-style:italic",[2036],{"type":54,"value":2037}," void",{"type":49,"tag":124,"props":2039,"children":2040},{"style":581},[2041],{"type":54,"value":2042}," simulateRandomFailure",{"type":49,"tag":124,"props":2044,"children":2045},{"style":315},[2046],{"type":54,"value":589},{"type":49,"tag":124,"props":2048,"children":2049},{"style":750},[2050],{"type":54,"value":2051}," throws MessagingException ",{"type":49,"tag":124,"props":2053,"children":2054},{"style":315},[2055],{"type":54,"value":2056},"{\n",{"type":49,"tag":124,"props":2058,"children":2059},{"class":126,"line":136},[2060],{"type":49,"tag":124,"props":2061,"children":2062},{"style":1997},[2063],{"type":54,"value":2064},"        \u002F\u002F generate a random number between 1 and 6\n",{"type":49,"tag":124,"props":2066,"children":2067},{"class":126,"line":145},[2068,2073,2078,2082,2087,2092,2096,2100,2105,2109,2114,2118,2123,2128,2132,2137,2141],{"type":49,"tag":124,"props":2069,"children":2070},{"style":2034},[2071],{"type":54,"value":2072},"        int",{"type":49,"tag":124,"props":2074,"children":2075},{"style":476},[2076],{"type":54,"value":2077}," random",{"type":49,"tag":124,"props":2079,"children":2080},{"style":400},[2081],{"type":54,"value":620},{"type":49,"tag":124,"props":2083,"children":2084},{"style":315},[2085],{"type":54,"value":2086}," (",{"type":49,"tag":124,"props":2088,"children":2089},{"style":2034},[2090],{"type":54,"value":2091},"int",{"type":49,"tag":124,"props":2093,"children":2094},{"style":315},[2095],{"type":54,"value":679},{"type":49,"tag":124,"props":2097,"children":2098},{"style":315},[2099],{"type":54,"value":2086},{"type":49,"tag":124,"props":2101,"children":2102},{"style":476},[2103],{"type":54,"value":2104},"Math",{"type":49,"tag":124,"props":2106,"children":2107},{"style":315},[2108],{"type":54,"value":652},{"type":49,"tag":124,"props":2110,"children":2111},{"style":581},[2112],{"type":54,"value":2113},"random",{"type":49,"tag":124,"props":2115,"children":2116},{"style":315},[2117],{"type":54,"value":589},{"type":49,"tag":124,"props":2119,"children":2120},{"style":400},[2121],{"type":54,"value":2122}," *",{"type":49,"tag":124,"props":2124,"children":2125},{"style":707},[2126],{"type":54,"value":2127}," 6",{"type":49,"tag":124,"props":2129,"children":2130},{"style":400},[2131],{"type":54,"value":1880},{"type":49,"tag":124,"props":2133,"children":2134},{"style":707},[2135],{"type":54,"value":2136}," 1",{"type":49,"tag":124,"props":2138,"children":2139},{"style":315},[2140],{"type":54,"value":679},{"type":49,"tag":124,"props":2142,"children":2143},{"style":482},[2144],{"type":54,"value":485},{"type":49,"tag":124,"props":2146,"children":2147},{"class":126,"line":154},[2148],{"type":49,"tag":124,"props":2149,"children":2150},{"emptyLinePlaceholder":35},[2151],{"type":54,"value":133},{"type":49,"tag":124,"props":2153,"children":2154},{"class":126,"line":163},[2155,2159,2163,2167,2171,2175,2180,2184,2188,2192,2196],{"type":49,"tag":124,"props":2156,"children":2157},{"style":476},[2158],{"type":54,"value":1397},{"type":49,"tag":124,"props":2160,"children":2161},{"style":315},[2162],{"type":54,"value":652},{"type":49,"tag":124,"props":2164,"children":2165},{"style":581},[2166],{"type":54,"value":1406},{"type":49,"tag":124,"props":2168,"children":2169},{"style":315},[2170],{"type":54,"value":444},{"type":49,"tag":124,"props":2172,"children":2173},{"style":447},[2174],{"type":54,"value":450},{"type":49,"tag":124,"props":2176,"children":2177},{"style":346},[2178],{"type":54,"value":2179},"Random number: {}",{"type":49,"tag":124,"props":2181,"children":2182},{"style":447},[2183],{"type":54,"value":450},{"type":49,"tag":124,"props":2185,"children":2186},{"style":315},[2187],{"type":54,"value":882},{"type":49,"tag":124,"props":2189,"children":2190},{"style":750},[2191],{"type":54,"value":2077},{"type":49,"tag":124,"props":2193,"children":2194},{"style":315},[2195],{"type":54,"value":679},{"type":49,"tag":124,"props":2197,"children":2198},{"style":482},[2199],{"type":54,"value":485},{"type":49,"tag":124,"props":2201,"children":2202},{"class":126,"line":488},[2203],{"type":49,"tag":124,"props":2204,"children":2205},{"emptyLinePlaceholder":35},[2206],{"type":54,"value":133},{"type":49,"tag":124,"props":2208,"children":2209},{"class":126,"line":496},[2210,2215,2219,2224,2229,2234,2238,2243],{"type":49,"tag":124,"props":2211,"children":2212},{"style":400},[2213],{"type":54,"value":2214},"        if",{"type":49,"tag":124,"props":2216,"children":2217},{"style":315},[2218],{"type":54,"value":2086},{"type":49,"tag":124,"props":2220,"children":2221},{"style":750},[2222],{"type":54,"value":2223},"random ",{"type":49,"tag":124,"props":2225,"children":2226},{"style":400},[2227],{"type":54,"value":2228},"\u003C",{"type":49,"tag":124,"props":2230,"children":2231},{"style":707},[2232],{"type":54,"value":2233}," 5",{"type":49,"tag":124,"props":2235,"children":2236},{"style":315},[2237],{"type":54,"value":679},{"type":49,"tag":124,"props":2239,"children":2240},{"style":315},[2241],{"type":54,"value":2242}," {",{"type":49,"tag":124,"props":2244,"children":2245},{"style":1997},[2246],{"type":54,"value":2247}," \u002F\u002F 4 out of 6 chances to fail\n",{"type":49,"tag":124,"props":2249,"children":2250},{"class":126,"line":529},[2251,2256,2260,2265,2269,2273,2278,2282,2286],{"type":49,"tag":124,"props":2252,"children":2253},{"style":476},[2254],{"type":54,"value":2255},"            logger",{"type":49,"tag":124,"props":2257,"children":2258},{"style":315},[2259],{"type":54,"value":652},{"type":49,"tag":124,"props":2261,"children":2262},{"style":581},[2263],{"type":54,"value":2264},"error",{"type":49,"tag":124,"props":2266,"children":2267},{"style":315},[2268],{"type":54,"value":444},{"type":49,"tag":124,"props":2270,"children":2271},{"style":447},[2272],{"type":54,"value":450},{"type":49,"tag":124,"props":2274,"children":2275},{"style":346},[2276],{"type":54,"value":2277},"Simulating a random failure",{"type":49,"tag":124,"props":2279,"children":2280},{"style":447},[2281],{"type":54,"value":450},{"type":49,"tag":124,"props":2283,"children":2284},{"style":315},[2285],{"type":54,"value":679},{"type":49,"tag":124,"props":2287,"children":2288},{"style":482},[2289],{"type":54,"value":485},{"type":49,"tag":124,"props":2291,"children":2292},{"class":126,"line":546},[2293,2298,2302,2306,2310,2314,2319,2323,2327],{"type":49,"tag":124,"props":2294,"children":2295},{"style":400},[2296],{"type":54,"value":2297},"            throw",{"type":49,"tag":124,"props":2299,"children":2300},{"style":400},[2301],{"type":54,"value":625},{"type":49,"tag":124,"props":2303,"children":2304},{"style":581},[2305],{"type":54,"value":1376},{"type":49,"tag":124,"props":2307,"children":2308},{"style":315},[2309],{"type":54,"value":444},{"type":49,"tag":124,"props":2311,"children":2312},{"style":447},[2313],{"type":54,"value":450},{"type":49,"tag":124,"props":2315,"children":2316},{"style":346},[2317],{"type":54,"value":2318},"Failed to send email",{"type":49,"tag":124,"props":2320,"children":2321},{"style":447},[2322],{"type":54,"value":450},{"type":49,"tag":124,"props":2324,"children":2325},{"style":315},[2326],{"type":54,"value":679},{"type":49,"tag":124,"props":2328,"children":2329},{"style":482},[2330],{"type":54,"value":485},{"type":49,"tag":124,"props":2332,"children":2333},{"class":126,"line":554},[2334],{"type":49,"tag":124,"props":2335,"children":2336},{"style":315},[2337],{"type":54,"value":2338},"        }\n",{"type":49,"tag":124,"props":2340,"children":2341},{"class":126,"line":567},[2342],{"type":49,"tag":124,"props":2343,"children":2344},{"style":315},[2345],{"type":54,"value":1062},{"type":49,"tag":50,"props":2347,"children":2348},{},[2349],{"type":54,"value":2350},"Now we can modify the EmailService class to execute the sendEmail method asynchronously and to retry the execution in\ncase\nof MessagingException, with a maximum of 4 attempts and a delay of 3 seconds between each attempt.",{"type":49,"tag":113,"props":2352,"children":2354},{"className":374,"code":2353,"language":376,"meta":31,"style":31},"@Service\npublic class EmailService {\n\n    private static final Logger logger = LoggerFactory.getLogger(EmailService.class);\n\n    private final JavaMailSender javaMailSender;\n\n    public EmailService(JavaMailSender javaMailSender) {\n        this.javaMailSender = javaMailSender;\n    }\n\n    @Retryable(\n        retryFor = MessagingException.class, \u002F\u002F specify the exception to retry\n        maxAttempts = 4, \u002F\u002F default is 3\n        backoff = @Backoff(delay = 3000) \u002F\u002F set the backoff delay to 3 seconds\n    )\n    public String sendEmailWithRetry(String to, String subject, String body) throws MessagingException, IOException {\n        simulateRandomFailure();\n\n        return sendEmail(to, subject, body);\n    }\n    \n    @Recover\n    public String handleMessagingException(MessagingException e) {\n        logger.error(\"Max attempts reached. Failed to send email after 4 attempts.\");\n        logger.error(\"Error message: {}\", e.getMessage());\n\n        return \"Max attempts reached. Failed to send email\";\n    }\n    \n    public String sendEmail(String to, String subject, String body) throws MessagingException, IOException {\n        \u002F\u002F same code as before\n    }\n",[2355],{"type":49,"tag":120,"props":2356,"children":2357},{"__ignoreMap":31},[2358,2369,2388,2395,2458,2465,2488,2495,2526,2553,2560,2567,2584,2618,2644,2693,2701,2777,2793,2800,2843,2850,2858,2870,2908,2948,3006,3013,3037,3044,3051,3126,3135],{"type":49,"tag":124,"props":2359,"children":2360},{"class":126,"line":127},[2361,2365],{"type":49,"tag":124,"props":2362,"children":2363},{"style":315},[2364],{"type":54,"value":388},{"type":49,"tag":124,"props":2366,"children":2367},{"style":391},[2368],{"type":54,"value":1092},{"type":49,"tag":124,"props":2370,"children":2371},{"class":126,"line":136},[2372,2376,2380,2384],{"type":49,"tag":124,"props":2373,"children":2374},{"style":400},[2375],{"type":54,"value":403},{"type":49,"tag":124,"props":2377,"children":2378},{"style":400},[2379],{"type":54,"value":408},{"type":49,"tag":124,"props":2381,"children":2382},{"style":411},[2383],{"type":54,"value":1108},{"type":49,"tag":124,"props":2385,"children":2386},{"style":315},[2387],{"type":54,"value":419},{"type":49,"tag":124,"props":2389,"children":2390},{"class":126,"line":145},[2391],{"type":49,"tag":124,"props":2392,"children":2393},{"emptyLinePlaceholder":35},[2394],{"type":54,"value":133},{"type":49,"tag":124,"props":2396,"children":2397},{"class":126,"line":154},[2398,2402,2406,2410,2414,2418,2422,2426,2430,2434,2438,2442,2446,2450,2454],{"type":49,"tag":124,"props":2399,"children":2400},{"style":400},[2401],{"type":54,"value":1127},{"type":49,"tag":124,"props":2403,"children":2404},{"style":400},[2405],{"type":54,"value":1132},{"type":49,"tag":124,"props":2407,"children":2408},{"style":400},[2409],{"type":54,"value":1137},{"type":49,"tag":124,"props":2411,"children":2412},{"style":470},[2413],{"type":54,"value":1142},{"type":49,"tag":124,"props":2415,"children":2416},{"style":476},[2417],{"type":54,"value":1147},{"type":49,"tag":124,"props":2419,"children":2420},{"style":400},[2421],{"type":54,"value":620},{"type":49,"tag":124,"props":2423,"children":2424},{"style":476},[2425],{"type":54,"value":1156},{"type":49,"tag":124,"props":2427,"children":2428},{"style":315},[2429],{"type":54,"value":652},{"type":49,"tag":124,"props":2431,"children":2432},{"style":581},[2433],{"type":54,"value":1165},{"type":49,"tag":124,"props":2435,"children":2436},{"style":315},[2437],{"type":54,"value":444},{"type":49,"tag":124,"props":2439,"children":2440},{"style":476},[2441],{"type":54,"value":1174},{"type":49,"tag":124,"props":2443,"children":2444},{"style":315},[2445],{"type":54,"value":652},{"type":49,"tag":124,"props":2447,"children":2448},{"style":476},[2449],{"type":54,"value":1183},{"type":49,"tag":124,"props":2451,"children":2452},{"style":315},[2453],{"type":54,"value":679},{"type":49,"tag":124,"props":2455,"children":2456},{"style":482},[2457],{"type":54,"value":485},{"type":49,"tag":124,"props":2459,"children":2460},{"class":126,"line":163},[2461],{"type":49,"tag":124,"props":2462,"children":2463},{"emptyLinePlaceholder":35},[2464],{"type":54,"value":133},{"type":49,"tag":124,"props":2466,"children":2467},{"class":126,"line":488},[2468,2472,2476,2480,2484],{"type":49,"tag":124,"props":2469,"children":2470},{"style":400},[2471],{"type":54,"value":1127},{"type":49,"tag":124,"props":2473,"children":2474},{"style":400},[2475],{"type":54,"value":1137},{"type":49,"tag":124,"props":2477,"children":2478},{"style":470},[2479],{"type":54,"value":578},{"type":49,"tag":124,"props":2481,"children":2482},{"style":476},[2483],{"type":54,"value":584},{"type":49,"tag":124,"props":2485,"children":2486},{"style":482},[2487],{"type":54,"value":485},{"type":49,"tag":124,"props":2489,"children":2490},{"class":126,"line":496},[2491],{"type":49,"tag":124,"props":2492,"children":2493},{"emptyLinePlaceholder":35},[2494],{"type":54,"value":133},{"type":49,"tag":124,"props":2496,"children":2497},{"class":126,"line":529},[2498,2502,2506,2510,2514,2518,2522],{"type":49,"tag":124,"props":2499,"children":2500},{"style":400},[2501],{"type":54,"value":573},{"type":49,"tag":124,"props":2503,"children":2504},{"style":581},[2505],{"type":54,"value":1108},{"type":49,"tag":124,"props":2507,"children":2508},{"style":315},[2509],{"type":54,"value":444},{"type":49,"tag":124,"props":2511,"children":2512},{"style":470},[2513],{"type":54,"value":1248},{"type":49,"tag":124,"props":2515,"children":2516},{"style":1251},[2517],{"type":54,"value":584},{"type":49,"tag":124,"props":2519,"children":2520},{"style":315},[2521],{"type":54,"value":679},{"type":49,"tag":124,"props":2523,"children":2524},{"style":315},[2525],{"type":54,"value":419},{"type":49,"tag":124,"props":2527,"children":2528},{"class":126,"line":546},[2529,2533,2537,2541,2545,2549],{"type":49,"tag":124,"props":2530,"children":2531},{"style":1267},[2532],{"type":54,"value":1270},{"type":49,"tag":124,"props":2534,"children":2535},{"style":315},[2536],{"type":54,"value":652},{"type":49,"tag":124,"props":2538,"children":2539},{"style":476},[2540],{"type":54,"value":1279},{"type":49,"tag":124,"props":2542,"children":2543},{"style":400},[2544],{"type":54,"value":620},{"type":49,"tag":124,"props":2546,"children":2547},{"style":750},[2548],{"type":54,"value":584},{"type":49,"tag":124,"props":2550,"children":2551},{"style":482},[2552],{"type":54,"value":485},{"type":49,"tag":124,"props":2554,"children":2555},{"class":126,"line":554},[2556],{"type":49,"tag":124,"props":2557,"children":2558},{"style":315},[2559],{"type":54,"value":1053},{"type":49,"tag":124,"props":2561,"children":2562},{"class":126,"line":567},[2563],{"type":49,"tag":124,"props":2564,"children":2565},{"emptyLinePlaceholder":35},[2566],{"type":54,"value":133},{"type":49,"tag":124,"props":2568,"children":2569},{"class":126,"line":596},[2570,2574,2579],{"type":49,"tag":124,"props":2571,"children":2572},{"style":315},[2573],{"type":54,"value":434},{"type":49,"tag":124,"props":2575,"children":2576},{"style":391},[2577],{"type":54,"value":2578},"Retryable",{"type":49,"tag":124,"props":2580,"children":2581},{"style":315},[2582],{"type":54,"value":2583},"(\n",{"type":49,"tag":124,"props":2585,"children":2586},{"class":126,"line":604},[2587,2593,2597,2601,2605,2609,2613],{"type":49,"tag":124,"props":2588,"children":2590},{"style":2589},"--shiki-default:#D8DEE9;--shiki-dark:#79B8FF;--shiki-sepia:#AE81FF",[2591],{"type":54,"value":2592},"        retryFor",{"type":49,"tag":124,"props":2594,"children":2595},{"style":400},[2596],{"type":54,"value":620},{"type":49,"tag":124,"props":2598,"children":2599},{"style":476},[2600],{"type":54,"value":1376},{"type":49,"tag":124,"props":2602,"children":2603},{"style":315},[2604],{"type":54,"value":652},{"type":49,"tag":124,"props":2606,"children":2607},{"style":476},[2608],{"type":54,"value":1183},{"type":49,"tag":124,"props":2610,"children":2611},{"style":315},[2612],{"type":54,"value":882},{"type":49,"tag":124,"props":2614,"children":2615},{"style":1997},[2616],{"type":54,"value":2617}," \u002F\u002F specify the exception to retry\n",{"type":49,"tag":124,"props":2619,"children":2620},{"class":126,"line":641},[2621,2626,2630,2635,2639],{"type":49,"tag":124,"props":2622,"children":2623},{"style":2589},[2624],{"type":54,"value":2625},"        maxAttempts",{"type":49,"tag":124,"props":2627,"children":2628},{"style":400},[2629],{"type":54,"value":620},{"type":49,"tag":124,"props":2631,"children":2632},{"style":707},[2633],{"type":54,"value":2634}," 4",{"type":49,"tag":124,"props":2636,"children":2637},{"style":315},[2638],{"type":54,"value":882},{"type":49,"tag":124,"props":2640,"children":2641},{"style":1997},[2642],{"type":54,"value":2643}," \u002F\u002F default is 3\n",{"type":49,"tag":124,"props":2645,"children":2646},{"class":126,"line":686},[2647,2652,2656,2661,2666,2670,2675,2679,2684,2688],{"type":49,"tag":124,"props":2648,"children":2649},{"style":2589},[2650],{"type":54,"value":2651},"        backoff",{"type":49,"tag":124,"props":2653,"children":2654},{"style":400},[2655],{"type":54,"value":620},{"type":49,"tag":124,"props":2657,"children":2658},{"style":315},[2659],{"type":54,"value":2660}," @",{"type":49,"tag":124,"props":2662,"children":2663},{"style":391},[2664],{"type":54,"value":2665},"Backoff",{"type":49,"tag":124,"props":2667,"children":2668},{"style":315},[2669],{"type":54,"value":444},{"type":49,"tag":124,"props":2671,"children":2672},{"style":2589},[2673],{"type":54,"value":2674},"delay",{"type":49,"tag":124,"props":2676,"children":2677},{"style":400},[2678],{"type":54,"value":620},{"type":49,"tag":124,"props":2680,"children":2681},{"style":707},[2682],{"type":54,"value":2683}," 3000",{"type":49,"tag":124,"props":2685,"children":2686},{"style":315},[2687],{"type":54,"value":679},{"type":49,"tag":124,"props":2689,"children":2690},{"style":1997},[2691],{"type":54,"value":2692}," \u002F\u002F set the backoff delay to 3 seconds\n",{"type":49,"tag":124,"props":2694,"children":2695},{"class":126,"line":721},[2696],{"type":49,"tag":124,"props":2697,"children":2698},{"style":315},[2699],{"type":54,"value":2700},"    )\n",{"type":49,"tag":124,"props":2702,"children":2703},{"class":126,"line":729},[2704,2708,2712,2717,2721,2725,2729,2733,2737,2741,2745,2749,2753,2757,2761,2765,2769,2773],{"type":49,"tag":124,"props":2705,"children":2706},{"style":400},[2707],{"type":54,"value":573},{"type":49,"tag":124,"props":2709,"children":2710},{"style":470},[2711],{"type":54,"value":1317},{"type":49,"tag":124,"props":2713,"children":2714},{"style":581},[2715],{"type":54,"value":2716}," sendEmailWithRetry",{"type":49,"tag":124,"props":2718,"children":2719},{"style":315},[2720],{"type":54,"value":444},{"type":49,"tag":124,"props":2722,"children":2723},{"style":470},[2724],{"type":54,"value":1331},{"type":49,"tag":124,"props":2726,"children":2727},{"style":1251},[2728],{"type":54,"value":1336},{"type":49,"tag":124,"props":2730,"children":2731},{"style":315},[2732],{"type":54,"value":882},{"type":49,"tag":124,"props":2734,"children":2735},{"style":470},[2736],{"type":54,"value":1317},{"type":49,"tag":124,"props":2738,"children":2739},{"style":1251},[2740],{"type":54,"value":1349},{"type":49,"tag":124,"props":2742,"children":2743},{"style":315},[2744],{"type":54,"value":882},{"type":49,"tag":124,"props":2746,"children":2747},{"style":470},[2748],{"type":54,"value":1317},{"type":49,"tag":124,"props":2750,"children":2751},{"style":1251},[2752],{"type":54,"value":1362},{"type":49,"tag":124,"props":2754,"children":2755},{"style":315},[2756],{"type":54,"value":679},{"type":49,"tag":124,"props":2758,"children":2759},{"style":400},[2760],{"type":54,"value":1371},{"type":49,"tag":124,"props":2762,"children":2763},{"style":470},[2764],{"type":54,"value":1376},{"type":49,"tag":124,"props":2766,"children":2767},{"style":315},[2768],{"type":54,"value":882},{"type":49,"tag":124,"props":2770,"children":2771},{"style":470},[2772],{"type":54,"value":1385},{"type":49,"tag":124,"props":2774,"children":2775},{"style":315},[2776],{"type":54,"value":419},{"type":49,"tag":124,"props":2778,"children":2779},{"class":126,"line":764},[2780,2785,2789],{"type":49,"tag":124,"props":2781,"children":2782},{"style":581},[2783],{"type":54,"value":2784},"        simulateRandomFailure",{"type":49,"tag":124,"props":2786,"children":2787},{"style":315},[2788],{"type":54,"value":589},{"type":49,"tag":124,"props":2790,"children":2791},{"style":482},[2792],{"type":54,"value":485},{"type":49,"tag":124,"props":2794,"children":2795},{"class":126,"line":798},[2796],{"type":49,"tag":124,"props":2797,"children":2798},{"emptyLinePlaceholder":35},[2799],{"type":54,"value":133},{"type":49,"tag":124,"props":2801,"children":2802},{"class":126,"line":806},[2803,2807,2811,2815,2819,2823,2827,2831,2835,2839],{"type":49,"tag":124,"props":2804,"children":2805},{"style":400},[2806],{"type":54,"value":1036},{"type":49,"tag":124,"props":2808,"children":2809},{"style":581},[2810],{"type":54,"value":1322},{"type":49,"tag":124,"props":2812,"children":2813},{"style":315},[2814],{"type":54,"value":444},{"type":49,"tag":124,"props":2816,"children":2817},{"style":750},[2818],{"type":54,"value":1692},{"type":49,"tag":124,"props":2820,"children":2821},{"style":315},[2822],{"type":54,"value":882},{"type":49,"tag":124,"props":2824,"children":2825},{"style":750},[2826],{"type":54,"value":1349},{"type":49,"tag":124,"props":2828,"children":2829},{"style":315},[2830],{"type":54,"value":882},{"type":49,"tag":124,"props":2832,"children":2833},{"style":750},[2834],{"type":54,"value":1362},{"type":49,"tag":124,"props":2836,"children":2837},{"style":315},[2838],{"type":54,"value":679},{"type":49,"tag":124,"props":2840,"children":2841},{"style":482},[2842],{"type":54,"value":485},{"type":49,"tag":124,"props":2844,"children":2845},{"class":126,"line":845},[2846],{"type":49,"tag":124,"props":2847,"children":2848},{"style":315},[2849],{"type":54,"value":1053},{"type":49,"tag":124,"props":2851,"children":2852},{"class":126,"line":907},[2853],{"type":49,"tag":124,"props":2854,"children":2855},{"style":750},[2856],{"type":54,"value":2857},"    \n",{"type":49,"tag":124,"props":2859,"children":2860},{"class":126,"line":965},[2861,2865],{"type":49,"tag":124,"props":2862,"children":2863},{"style":315},[2864],{"type":54,"value":434},{"type":49,"tag":124,"props":2866,"children":2867},{"style":391},[2868],{"type":54,"value":2869},"Recover\n",{"type":49,"tag":124,"props":2871,"children":2872},{"class":126,"line":1022},[2873,2877,2881,2886,2890,2895,2900,2904],{"type":49,"tag":124,"props":2874,"children":2875},{"style":400},[2876],{"type":54,"value":573},{"type":49,"tag":124,"props":2878,"children":2879},{"style":470},[2880],{"type":54,"value":1317},{"type":49,"tag":124,"props":2882,"children":2883},{"style":581},[2884],{"type":54,"value":2885}," handleMessagingException",{"type":49,"tag":124,"props":2887,"children":2888},{"style":315},[2889],{"type":54,"value":444},{"type":49,"tag":124,"props":2891,"children":2892},{"style":470},[2893],{"type":54,"value":2894},"MessagingException",{"type":49,"tag":124,"props":2896,"children":2897},{"style":1251},[2898],{"type":54,"value":2899}," e",{"type":49,"tag":124,"props":2901,"children":2902},{"style":315},[2903],{"type":54,"value":679},{"type":49,"tag":124,"props":2905,"children":2906},{"style":315},[2907],{"type":54,"value":419},{"type":49,"tag":124,"props":2909,"children":2910},{"class":126,"line":1030},[2911,2915,2919,2923,2927,2931,2936,2940,2944],{"type":49,"tag":124,"props":2912,"children":2913},{"style":476},[2914],{"type":54,"value":1397},{"type":49,"tag":124,"props":2916,"children":2917},{"style":315},[2918],{"type":54,"value":652},{"type":49,"tag":124,"props":2920,"children":2921},{"style":581},[2922],{"type":54,"value":2264},{"type":49,"tag":124,"props":2924,"children":2925},{"style":315},[2926],{"type":54,"value":444},{"type":49,"tag":124,"props":2928,"children":2929},{"style":447},[2930],{"type":54,"value":450},{"type":49,"tag":124,"props":2932,"children":2933},{"style":346},[2934],{"type":54,"value":2935},"Max attempts reached. Failed to send email after 4 attempts.",{"type":49,"tag":124,"props":2937,"children":2938},{"style":447},[2939],{"type":54,"value":450},{"type":49,"tag":124,"props":2941,"children":2942},{"style":315},[2943],{"type":54,"value":679},{"type":49,"tag":124,"props":2945,"children":2946},{"style":482},[2947],{"type":54,"value":485},{"type":49,"tag":124,"props":2949,"children":2950},{"class":126,"line":1047},[2951,2955,2959,2963,2967,2971,2976,2980,2984,2988,2992,2997,3002],{"type":49,"tag":124,"props":2952,"children":2953},{"style":476},[2954],{"type":54,"value":1397},{"type":49,"tag":124,"props":2956,"children":2957},{"style":315},[2958],{"type":54,"value":652},{"type":49,"tag":124,"props":2960,"children":2961},{"style":581},[2962],{"type":54,"value":2264},{"type":49,"tag":124,"props":2964,"children":2965},{"style":315},[2966],{"type":54,"value":444},{"type":49,"tag":124,"props":2968,"children":2969},{"style":447},[2970],{"type":54,"value":450},{"type":49,"tag":124,"props":2972,"children":2973},{"style":346},[2974],{"type":54,"value":2975},"Error message: {}",{"type":49,"tag":124,"props":2977,"children":2978},{"style":447},[2979],{"type":54,"value":450},{"type":49,"tag":124,"props":2981,"children":2982},{"style":315},[2983],{"type":54,"value":882},{"type":49,"tag":124,"props":2985,"children":2986},{"style":476},[2987],{"type":54,"value":2899},{"type":49,"tag":124,"props":2989,"children":2990},{"style":315},[2991],{"type":54,"value":652},{"type":49,"tag":124,"props":2993,"children":2994},{"style":581},[2995],{"type":54,"value":2996},"getMessage",{"type":49,"tag":124,"props":2998,"children":2999},{"style":315},[3000],{"type":54,"value":3001},"())",{"type":49,"tag":124,"props":3003,"children":3004},{"style":482},[3005],{"type":54,"value":485},{"type":49,"tag":124,"props":3007,"children":3008},{"class":126,"line":1056},[3009],{"type":49,"tag":124,"props":3010,"children":3011},{"emptyLinePlaceholder":35},[3012],{"type":54,"value":133},{"type":49,"tag":124,"props":3014,"children":3015},{"class":126,"line":1849},[3016,3020,3024,3029,3033],{"type":49,"tag":124,"props":3017,"children":3018},{"style":400},[3019],{"type":54,"value":1036},{"type":49,"tag":124,"props":3021,"children":3022},{"style":447},[3023],{"type":54,"value":887},{"type":49,"tag":124,"props":3025,"children":3026},{"style":346},[3027],{"type":54,"value":3028},"Max attempts reached. Failed to send email",{"type":49,"tag":124,"props":3030,"children":3031},{"style":447},[3032],{"type":54,"value":450},{"type":49,"tag":124,"props":3034,"children":3035},{"style":482},[3036],{"type":54,"value":485},{"type":49,"tag":124,"props":3038,"children":3039},{"class":126,"line":1857},[3040],{"type":49,"tag":124,"props":3041,"children":3042},{"style":315},[3043],{"type":54,"value":1053},{"type":49,"tag":124,"props":3045,"children":3046},{"class":126,"line":1891},[3047],{"type":49,"tag":124,"props":3048,"children":3049},{"style":750},[3050],{"type":54,"value":2857},{"type":49,"tag":124,"props":3052,"children":3053},{"class":126,"line":1899},[3054,3058,3062,3066,3070,3074,3078,3082,3086,3090,3094,3098,3102,3106,3110,3114,3118,3122],{"type":49,"tag":124,"props":3055,"children":3056},{"style":400},[3057],{"type":54,"value":573},{"type":49,"tag":124,"props":3059,"children":3060},{"style":470},[3061],{"type":54,"value":1317},{"type":49,"tag":124,"props":3063,"children":3064},{"style":581},[3065],{"type":54,"value":1322},{"type":49,"tag":124,"props":3067,"children":3068},{"style":315},[3069],{"type":54,"value":444},{"type":49,"tag":124,"props":3071,"children":3072},{"style":470},[3073],{"type":54,"value":1331},{"type":49,"tag":124,"props":3075,"children":3076},{"style":1251},[3077],{"type":54,"value":1336},{"type":49,"tag":124,"props":3079,"children":3080},{"style":315},[3081],{"type":54,"value":882},{"type":49,"tag":124,"props":3083,"children":3084},{"style":470},[3085],{"type":54,"value":1317},{"type":49,"tag":124,"props":3087,"children":3088},{"style":1251},[3089],{"type":54,"value":1349},{"type":49,"tag":124,"props":3091,"children":3092},{"style":315},[3093],{"type":54,"value":882},{"type":49,"tag":124,"props":3095,"children":3096},{"style":470},[3097],{"type":54,"value":1317},{"type":49,"tag":124,"props":3099,"children":3100},{"style":1251},[3101],{"type":54,"value":1362},{"type":49,"tag":124,"props":3103,"children":3104},{"style":315},[3105],{"type":54,"value":679},{"type":49,"tag":124,"props":3107,"children":3108},{"style":400},[3109],{"type":54,"value":1371},{"type":49,"tag":124,"props":3111,"children":3112},{"style":470},[3113],{"type":54,"value":1376},{"type":49,"tag":124,"props":3115,"children":3116},{"style":315},[3117],{"type":54,"value":882},{"type":49,"tag":124,"props":3119,"children":3120},{"style":470},[3121],{"type":54,"value":1385},{"type":49,"tag":124,"props":3123,"children":3124},{"style":315},[3125],{"type":54,"value":419},{"type":49,"tag":124,"props":3127,"children":3129},{"class":126,"line":3128},32,[3130],{"type":49,"tag":124,"props":3131,"children":3132},{"style":1997},[3133],{"type":54,"value":3134},"        \u002F\u002F same code as before\n",{"type":49,"tag":124,"props":3136,"children":3138},{"class":126,"line":3137},33,[3139],{"type":49,"tag":124,"props":3140,"children":3141},{"style":315},[3142],{"type":54,"value":1053},{"type":49,"tag":90,"props":3144,"children":3146},{"id":3145},"_5-creating-a-rest-controller",[3147],{"type":54,"value":3148},"5. Creating a REST Controller",{"type":49,"tag":50,"props":3150,"children":3151},{},[3152],{"type":54,"value":3153},"Finally, to test the retry mechanism, we can create a REST controller to expose an endpoint to send emails:",{"type":49,"tag":113,"props":3155,"children":3157},{"className":374,"code":3156,"language":376,"meta":31,"style":31},"@RestController\npublic class EmailController {\n    private final EmailService emailService;\n\n    public EmailController(EmailService emailService) {\n        this.emailService = emailService;\n    }\n\n    static String to = \"nidhalnaffati@gmail.com\";\n    static String subject = \"Asynchronous Email\";\n    static String body = \"Hello, this is an asynchronous email\";\n\n\n    @GetMapping(\"\u002Fsend-email\")\n    public String sendEmail() throws MessagingException, IOException {\n        return emailService.sendEmailWithRetry(to, subject, body);\n    }\n}\n",[3158],{"type":49,"tag":120,"props":3159,"children":3160},{"__ignoreMap":31},[3161,3173,3193,3217,3224,3255,3283,3290,3297,3333,3369,3405,3412,3419,3452,3491,3543,3550],{"type":49,"tag":124,"props":3162,"children":3163},{"class":126,"line":127},[3164,3168],{"type":49,"tag":124,"props":3165,"children":3166},{"style":315},[3167],{"type":54,"value":388},{"type":49,"tag":124,"props":3169,"children":3170},{"style":391},[3171],{"type":54,"value":3172},"RestController\n",{"type":49,"tag":124,"props":3174,"children":3175},{"class":126,"line":136},[3176,3180,3184,3189],{"type":49,"tag":124,"props":3177,"children":3178},{"style":400},[3179],{"type":54,"value":403},{"type":49,"tag":124,"props":3181,"children":3182},{"style":400},[3183],{"type":54,"value":408},{"type":49,"tag":124,"props":3185,"children":3186},{"style":411},[3187],{"type":54,"value":3188}," EmailController",{"type":49,"tag":124,"props":3190,"children":3191},{"style":315},[3192],{"type":54,"value":419},{"type":49,"tag":124,"props":3194,"children":3195},{"class":126,"line":145},[3196,3200,3204,3208,3213],{"type":49,"tag":124,"props":3197,"children":3198},{"style":400},[3199],{"type":54,"value":1127},{"type":49,"tag":124,"props":3201,"children":3202},{"style":400},[3203],{"type":54,"value":1137},{"type":49,"tag":124,"props":3205,"children":3206},{"style":470},[3207],{"type":54,"value":1108},{"type":49,"tag":124,"props":3209,"children":3210},{"style":476},[3211],{"type":54,"value":3212}," emailService",{"type":49,"tag":124,"props":3214,"children":3215},{"style":482},[3216],{"type":54,"value":485},{"type":49,"tag":124,"props":3218,"children":3219},{"class":126,"line":154},[3220],{"type":49,"tag":124,"props":3221,"children":3222},{"emptyLinePlaceholder":35},[3223],{"type":54,"value":133},{"type":49,"tag":124,"props":3225,"children":3226},{"class":126,"line":163},[3227,3231,3235,3239,3243,3247,3251],{"type":49,"tag":124,"props":3228,"children":3229},{"style":400},[3230],{"type":54,"value":573},{"type":49,"tag":124,"props":3232,"children":3233},{"style":581},[3234],{"type":54,"value":3188},{"type":49,"tag":124,"props":3236,"children":3237},{"style":315},[3238],{"type":54,"value":444},{"type":49,"tag":124,"props":3240,"children":3241},{"style":470},[3242],{"type":54,"value":1174},{"type":49,"tag":124,"props":3244,"children":3245},{"style":1251},[3246],{"type":54,"value":3212},{"type":49,"tag":124,"props":3248,"children":3249},{"style":315},[3250],{"type":54,"value":679},{"type":49,"tag":124,"props":3252,"children":3253},{"style":315},[3254],{"type":54,"value":419},{"type":49,"tag":124,"props":3256,"children":3257},{"class":126,"line":488},[3258,3262,3266,3271,3275,3279],{"type":49,"tag":124,"props":3259,"children":3260},{"style":1267},[3261],{"type":54,"value":1270},{"type":49,"tag":124,"props":3263,"children":3264},{"style":315},[3265],{"type":54,"value":652},{"type":49,"tag":124,"props":3267,"children":3268},{"style":476},[3269],{"type":54,"value":3270},"emailService",{"type":49,"tag":124,"props":3272,"children":3273},{"style":400},[3274],{"type":54,"value":620},{"type":49,"tag":124,"props":3276,"children":3277},{"style":750},[3278],{"type":54,"value":3212},{"type":49,"tag":124,"props":3280,"children":3281},{"style":482},[3282],{"type":54,"value":485},{"type":49,"tag":124,"props":3284,"children":3285},{"class":126,"line":496},[3286],{"type":49,"tag":124,"props":3287,"children":3288},{"style":315},[3289],{"type":54,"value":1053},{"type":49,"tag":124,"props":3291,"children":3292},{"class":126,"line":529},[3293],{"type":49,"tag":124,"props":3294,"children":3295},{"emptyLinePlaceholder":35},[3296],{"type":54,"value":133},{"type":49,"tag":124,"props":3298,"children":3299},{"class":126,"line":546},[3300,3305,3309,3313,3317,3321,3325,3329],{"type":49,"tag":124,"props":3301,"children":3302},{"style":400},[3303],{"type":54,"value":3304},"    static",{"type":49,"tag":124,"props":3306,"children":3307},{"style":470},[3308],{"type":54,"value":1317},{"type":49,"tag":124,"props":3310,"children":3311},{"style":476},[3312],{"type":54,"value":1336},{"type":49,"tag":124,"props":3314,"children":3315},{"style":400},[3316],{"type":54,"value":620},{"type":49,"tag":124,"props":3318,"children":3319},{"style":447},[3320],{"type":54,"value":887},{"type":49,"tag":124,"props":3322,"children":3323},{"style":346},[3324],{"type":54,"value":1505},{"type":49,"tag":124,"props":3326,"children":3327},{"style":447},[3328],{"type":54,"value":450},{"type":49,"tag":124,"props":3330,"children":3331},{"style":482},[3332],{"type":54,"value":485},{"type":49,"tag":124,"props":3334,"children":3335},{"class":126,"line":554},[3336,3340,3344,3348,3352,3356,3361,3365],{"type":49,"tag":124,"props":3337,"children":3338},{"style":400},[3339],{"type":54,"value":3304},{"type":49,"tag":124,"props":3341,"children":3342},{"style":470},[3343],{"type":54,"value":1317},{"type":49,"tag":124,"props":3345,"children":3346},{"style":476},[3347],{"type":54,"value":1349},{"type":49,"tag":124,"props":3349,"children":3350},{"style":400},[3351],{"type":54,"value":620},{"type":49,"tag":124,"props":3353,"children":3354},{"style":447},[3355],{"type":54,"value":887},{"type":49,"tag":124,"props":3357,"children":3358},{"style":346},[3359],{"type":54,"value":3360},"Asynchronous Email",{"type":49,"tag":124,"props":3362,"children":3363},{"style":447},[3364],{"type":54,"value":450},{"type":49,"tag":124,"props":3366,"children":3367},{"style":482},[3368],{"type":54,"value":485},{"type":49,"tag":124,"props":3370,"children":3371},{"class":126,"line":567},[3372,3376,3380,3384,3388,3392,3397,3401],{"type":49,"tag":124,"props":3373,"children":3374},{"style":400},[3375],{"type":54,"value":3304},{"type":49,"tag":124,"props":3377,"children":3378},{"style":470},[3379],{"type":54,"value":1317},{"type":49,"tag":124,"props":3381,"children":3382},{"style":476},[3383],{"type":54,"value":1362},{"type":49,"tag":124,"props":3385,"children":3386},{"style":400},[3387],{"type":54,"value":620},{"type":49,"tag":124,"props":3389,"children":3390},{"style":447},[3391],{"type":54,"value":887},{"type":49,"tag":124,"props":3393,"children":3394},{"style":346},[3395],{"type":54,"value":3396},"Hello, this is an asynchronous email",{"type":49,"tag":124,"props":3398,"children":3399},{"style":447},[3400],{"type":54,"value":450},{"type":49,"tag":124,"props":3402,"children":3403},{"style":482},[3404],{"type":54,"value":485},{"type":49,"tag":124,"props":3406,"children":3407},{"class":126,"line":596},[3408],{"type":49,"tag":124,"props":3409,"children":3410},{"emptyLinePlaceholder":35},[3411],{"type":54,"value":133},{"type":49,"tag":124,"props":3413,"children":3414},{"class":126,"line":604},[3415],{"type":49,"tag":124,"props":3416,"children":3417},{"emptyLinePlaceholder":35},[3418],{"type":54,"value":133},{"type":49,"tag":124,"props":3420,"children":3421},{"class":126,"line":641},[3422,3426,3431,3435,3439,3444,3448],{"type":49,"tag":124,"props":3423,"children":3424},{"style":315},[3425],{"type":54,"value":434},{"type":49,"tag":124,"props":3427,"children":3428},{"style":391},[3429],{"type":54,"value":3430},"GetMapping",{"type":49,"tag":124,"props":3432,"children":3433},{"style":315},[3434],{"type":54,"value":444},{"type":49,"tag":124,"props":3436,"children":3437},{"style":447},[3438],{"type":54,"value":450},{"type":49,"tag":124,"props":3440,"children":3441},{"style":346},[3442],{"type":54,"value":3443},"\u002Fsend-email",{"type":49,"tag":124,"props":3445,"children":3446},{"style":447},[3447],{"type":54,"value":450},{"type":49,"tag":124,"props":3449,"children":3450},{"style":315},[3451],{"type":54,"value":464},{"type":49,"tag":124,"props":3453,"children":3454},{"class":126,"line":686},[3455,3459,3463,3467,3471,3475,3479,3483,3487],{"type":49,"tag":124,"props":3456,"children":3457},{"style":400},[3458],{"type":54,"value":573},{"type":49,"tag":124,"props":3460,"children":3461},{"style":470},[3462],{"type":54,"value":1317},{"type":49,"tag":124,"props":3464,"children":3465},{"style":581},[3466],{"type":54,"value":1322},{"type":49,"tag":124,"props":3468,"children":3469},{"style":315},[3470],{"type":54,"value":589},{"type":49,"tag":124,"props":3472,"children":3473},{"style":400},[3474],{"type":54,"value":1371},{"type":49,"tag":124,"props":3476,"children":3477},{"style":470},[3478],{"type":54,"value":1376},{"type":49,"tag":124,"props":3480,"children":3481},{"style":315},[3482],{"type":54,"value":882},{"type":49,"tag":124,"props":3484,"children":3485},{"style":470},[3486],{"type":54,"value":1385},{"type":49,"tag":124,"props":3488,"children":3489},{"style":315},[3490],{"type":54,"value":419},{"type":49,"tag":124,"props":3492,"children":3493},{"class":126,"line":721},[3494,3498,3502,3506,3511,3515,3519,3523,3527,3531,3535,3539],{"type":49,"tag":124,"props":3495,"children":3496},{"style":400},[3497],{"type":54,"value":1036},{"type":49,"tag":124,"props":3499,"children":3500},{"style":476},[3501],{"type":54,"value":3212},{"type":49,"tag":124,"props":3503,"children":3504},{"style":315},[3505],{"type":54,"value":652},{"type":49,"tag":124,"props":3507,"children":3508},{"style":581},[3509],{"type":54,"value":3510},"sendEmailWithRetry",{"type":49,"tag":124,"props":3512,"children":3513},{"style":315},[3514],{"type":54,"value":444},{"type":49,"tag":124,"props":3516,"children":3517},{"style":750},[3518],{"type":54,"value":1692},{"type":49,"tag":124,"props":3520,"children":3521},{"style":315},[3522],{"type":54,"value":882},{"type":49,"tag":124,"props":3524,"children":3525},{"style":750},[3526],{"type":54,"value":1349},{"type":49,"tag":124,"props":3528,"children":3529},{"style":315},[3530],{"type":54,"value":882},{"type":49,"tag":124,"props":3532,"children":3533},{"style":750},[3534],{"type":54,"value":1362},{"type":49,"tag":124,"props":3536,"children":3537},{"style":315},[3538],{"type":54,"value":679},{"type":49,"tag":124,"props":3540,"children":3541},{"style":482},[3542],{"type":54,"value":485},{"type":49,"tag":124,"props":3544,"children":3545},{"class":126,"line":729},[3546],{"type":49,"tag":124,"props":3547,"children":3548},{"style":315},[3549],{"type":54,"value":1053},{"type":49,"tag":124,"props":3551,"children":3552},{"class":126,"line":764},[3553],{"type":49,"tag":124,"props":3554,"children":3555},{"style":315},[3556],{"type":54,"value":1062},{"type":49,"tag":50,"props":3558,"children":3559},{},[3560],{"type":54,"value":3561},"Now, we can run the application and send an email using the \u002Fsend-email endpoint.",{"type":49,"tag":50,"props":3563,"children":3564},{},[3565],{"type":54,"value":3566},"As you can see in the following images the email sending process failed at the first attempt, then it was retried one\nmore time and it succeeded.",{"type":49,"tag":50,"props":3568,"children":3569},{},[3570],{"type":49,"tag":3571,"props":3572,"children":3575},"img",{"alt":3573,"src":3574},"screenshot-1","\u002Fimages\u002Fblog\u002F2024\u002F02\u002F11\u002Fscreenshot-1.png",[],{"type":49,"tag":50,"props":3577,"children":3578},{},[3579],{"type":54,"value":3580},"I have executed the \u002Fsend-email endpoint multiple times till I got the following result:",{"type":49,"tag":50,"props":3582,"children":3583},{},[3584],{"type":49,"tag":3571,"props":3585,"children":3588},{"alt":3586,"src":3587},"screenshot-2","\u002Fimages\u002Fblog\u002F2024\u002F02\u002F11\u002Fscreenshot-2.png",[],{"type":49,"tag":50,"props":3590,"children":3591},{},[3592],{"type":54,"value":3593},"This time after the 4 attempts, the email sending process failed and the recover method was called.",{"type":49,"tag":67,"props":3595,"children":3597},{"id":3596},"conclusion",[3598],{"type":54,"value":3599},"Conclusion",{"type":49,"tag":50,"props":3601,"children":3602},{},[3603],{"type":54,"value":3604},"In this article, we explored the implementation of an asynchronous execution with an automatic retry mechanism for\nsending emails in a Spring application, leveraging Spring's support for async and retry operations.",{"type":49,"tag":50,"props":3606,"children":3607},{},[3608],{"type":54,"value":3609},"This approach can be used to enhance the performance and responsiveness of Spring applications, and to handle occasional\nfailures, such as network issues or third-party service unavailability, to build resilient applications.",{"type":49,"tag":3611,"props":3612,"children":3613},"style",{},[3614],{"type":54,"value":3615},"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 .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html .sepia .shiki span {color: var(--shiki-sepia);background: var(--shiki-sepia-bg);font-style: var(--shiki-sepia-font-style);font-weight: var(--shiki-sepia-font-weight);text-decoration: var(--shiki-sepia-text-decoration);}html.sepia .shiki span {color: var(--shiki-sepia);background: var(--shiki-sepia-bg);font-style: var(--shiki-sepia-font-style);font-weight: var(--shiki-sepia-font-weight);text-decoration: var(--shiki-sepia-text-decoration);}",{"title":31,"searchDepth":136,"depth":136,"links":3617},[3618,3619,3626],{"id":69,"depth":136,"text":72},{"id":80,"depth":136,"text":83,"children":3620},[3621,3622,3623,3624,3625],{"id":92,"depth":145,"text":95},{"id":286,"depth":145,"text":289},{"id":1065,"depth":145,"text":1068},{"id":1907,"depth":145,"text":1910},{"id":3145,"depth":145,"text":3148},{"id":3596,"depth":136,"text":3599},"markdown","content:blog:2024:02:11:spring-async-retry.md","content","blog\u002F2024\u002F02\u002F11\u002Fspring-async-retry.md","blog\u002F2024\u002F02\u002F11\u002Fspring-async-retry","md",{"loc":23},1773617924636]