{"id":39520,"date":"2025-06-12T19:08:22","date_gmt":"2025-06-12T13:38:22","guid":{"rendered":"https:\/\/mobisoftinfotech.com\/resources\/?p=39520"},"modified":"2026-03-10T16:24:31","modified_gmt":"2026-03-10T10:54:31","slug":"saga-pattern-spring-boot-rabbitmq-tutorial","status":"publish","type":"post","link":"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial","title":{"rendered":"Saga Pattern Microservices Tutorial: Using the Saga Pattern with Spring Boot &amp; RabbitMQ"},"content":{"rendered":"<p>Distributed transactions across microservices require a different approach than the traditional two phase commit (2PC). In a <a href=\"https:\/\/mobisoftinfotech.com\/resources\/blog\/essential-principles-spring-boot-microservices\">Spring Boot microservices<\/a> architecture, where each service owns its own database and communicates over the network, 2PC becomes complex, slow, and error prone due to tight coupling and potential locking across services.<\/p>\n\n\n\n<p>To address this, the Saga pattern in microservices has become a widely adopted solution. Instead of one global transaction, a Saga breaks the workflow into a series of local transactions, each managed by an individual service. Once a service completes its part, it publishes an event (e.g., &#8220;DebitCompleted&#8221;), which other services consume to trigger their own local operations.<\/p>\n\n\n\n<p>This event driven architecture in Spring Boot creates a loosely coupled, scalable system where each step in the process knows just enough to do its job, similar to systems built with <a href=\"https:\/\/mobisoftinfotech.com\/services\/golang-consulting-development\">custom golang development services.<\/a> If all goes well, the saga flows through each service to completion.<\/p>\n\n\n\n<p>But real systems aren\u2019t perfect; failures happen. If any service fails during the process, the Saga pattern allows you to run compensating transactions, custom logic designed to undo the effects of previously completed steps. For example, if a credit operation fails, the debit service can be asked to roll back the money transfer.<\/p>\n\n\n\n<p>This way, eventual consistency is preserved without distributed locks or tight coordination, making it ideal for resilient, fault tolerant microservices. This is particularly effective when paired with robust<a href=\"https:\/\/mobisoftinfotech.com\/services\/cloud-development?utm_source=blog&amp;utm_campaign=saga-pattern-spring-boot_blog\"> cloud development services<\/a> to support scalability and on demand infrastructure.<\/p>\n\n\n\n<p>Follow this Saga pattern microservices tutorial step by step with me, and implement it in your IDE to fully understand the Saga pattern and how to apply it in your projects. By the end, you&#8217;ll be confident in setting up and managing distributed transactions in Spring Boot using the Saga pattern.<\/p>\n\n\n\n<p>In this tutorial, we will build a simple money transfer microservice system consisting of:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Account-Debit Service (runs on port 8081)<br><\/li>\n\n\n\n<li>Account-Credit Service (runs on port 8082)<\/li>\n<\/ol>\n\n\n\n<p>Both services will communicate solely via RabbitMQ microservice communication (using Spring AMQP), without any REST calls between them. We will use in-memory data and expose REST endpoints for testing with Postman:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Debit Service:<\/strong><strong><br><\/strong>\n<ul class=\"wp-block-list\">\n<li>POST \/transfer \u2192 publishes a TransferRequested event<br><\/li>\n\n\n\n<li>GET \/accounts \u2192 view in-memory balances<br><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Credit Service:<\/strong><strong><br><\/strong>\n<ul class=\"wp-block-list\">\n<li>GET \/accounts \u2192 view in-memory balances<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>The Saga Workflow:<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Debit Service consumes TransferRequested \u2192<br>\n<ul class=\"wp-block-list\">\n<li>If there is sufficient balance, debit the \u201cfromAccount\u201d, then publish DebitCompleted;<br><\/li>\n\n\n\n<li>Otherwise, publish DebitFailed.<br><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Credit Service consumes DebitCompleted \u2192<br>\n<ul class=\"wp-block-list\">\n<li>If credit logic succeeds, credit the \u201ctoAccount\u201d, then publish CreditCompleted;<br><\/li>\n\n\n\n<li>Otherwise, publish CreditFailed.<br><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Debit Service also listens for CreditFailed \u2192<br>\n<ul class=\"wp-block-list\">\n<li>Issue a compensation refund (i.e., add back the amount to \u201cfromAccount\u201d).<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>We\u2019ll implement full AMQP (Advanced Message Queuing Protocol) RabbitMQ saga implementation, event DTOs, AccountStore (in memory balances with all methods), @RabbitListener handlers, and REST controllers. Finally, we\u2019ll run RabbitMQ locally via Docker and test the entire flow with Postman, including a simulated credit failure.&nbsp; This implementation can complement more advanced<a href=\"https:\/\/mobisoftinfotech.com\/amp\/services\/devops?utm_source=blog&amp;utm_campaign=saga-pattern-spring-boot_blog\"> devops services<\/a> for streamlined automation, testing, and deployment.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/mobisoftinfotech.com\/services\/software-development-company?utm_source=blog&amp;utm_campaign=saga-pattern-spring-boot-rabbitmq-tutorial\"><noscript><img decoding=\"async\" width=\"855\" height=\"363\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/software-development-microservices.png\" alt=\" Software development solutions tailored for microservices architecture.\" class=\"wp-image-39559\" title=\"Custom Software Development for Microservices\"><\/noscript><img decoding=\"async\" width=\"855\" height=\"363\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20855%20363%22%3E%3C%2Fsvg%3E\" alt=\" Software development solutions tailored for microservices architecture.\" class=\"wp-image-39559 lazyload\" title=\"Custom Software Development for Microservices\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/software-development-microservices.png\"><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Technologies<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Java 17<strong><br><\/strong><\/li>\n\n\n\n<li>Spring Boot 4.0.0<strong><br><\/strong><\/li>\n\n\n\n<li>Spring AMQP (spring-boot-starter-amqp)<br><\/li>\n\n\n\n<li>RabbitMQ (Docker image: rabbitmq:3-management)<strong><br><\/strong><\/li>\n\n\n\n<li>Postman (or any REST client)<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Project Setup<\/strong><\/h2>\n\n\n\n<p>Open <a href=\"https:\/\/start.spring.io\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Spring Initializer<\/a>, generate two services, Debit Service and Credit Service, then download the generated ZIP files. Extract and import each service as a Maven project into your preferred IDE.<\/p>\n\n\n\n<p>Add the following dependencies to your project:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Spring Web<\/strong> \u2013 for building RESTful APIs<br><\/li>\n\n\n\n<li><strong>Spring for RabbitMQ<\/strong> \u2013 for asynchronous messaging support using AMQP<br><\/li>\n\n\n\n<li><strong>Spring Boot DevTools<\/strong> \u2013 for automatic restarts and live reload during development<\/li>\n<\/ul>\n\n\n\n<p>To see how this kind of setup scales and aligns with modern software practices, check out our in-depth<a href=\"https:\/\/mobisoftinfotech.com\/resources\/blog\/ci-cd-with-docker-and-aws?utm_source=blog&amp;utm_campaign=saga-pattern-spring-boot_blog\"> CI\/CD with Docker &amp; AWS Blog<\/a><strong> <\/strong>for integrating continuous deployment in similar microservice architectures.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><noscript><img decoding=\"async\" width=\"855\" height=\"398\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/maven-project-import-ide.png\" alt=\"Import Spring Boot Maven project for saga pattern example.\" class=\"wp-image-39529\" title=\"Import Maven Project into IDE\"><\/noscript><img decoding=\"async\" width=\"855\" height=\"398\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20855%20398%22%3E%3C%2Fsvg%3E\" alt=\"Import Spring Boot Maven project for saga pattern example.\" class=\"wp-image-39529 lazyload\" title=\"Import Maven Project into IDE\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/maven-project-import-ide.png\"><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Running RabbitMQ Locally via Docker<\/strong><\/h3>\n\n\n\n<p>Use Docker to run RabbitMQ:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">docker<\/span> <span class=\"hljs-selector-tag\">run<\/span> <span class=\"hljs-selector-tag\">-d<\/span> <span class=\"hljs-selector-tag\">--hostname<\/span> <span class=\"hljs-selector-tag\">rabbit<\/span> <span class=\"hljs-selector-tag\">--name<\/span> <span class=\"hljs-selector-tag\">rabbitmq<\/span> <span class=\"hljs-selector-tag\">-p<\/span> 5672<span class=\"hljs-selector-pseudo\">:5672<\/span> <span class=\"hljs-selector-tag\">-p<\/span> 15672<span class=\"hljs-selector-pseudo\">:15672<\/span> <span class=\"hljs-selector-tag\">rabbitmq<\/span><span class=\"hljs-selector-pseudo\">:3-management<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<figure class=\"wp-block-image size-full\"><noscript><img decoding=\"async\" width=\"855\" height=\"112\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/rabbitmq-management-portal-visit.png\" alt=\"RabbitMQ Management Portal to monitor microservices messages.\" class=\"wp-image-39530\" title=\"Monitor RabbitMQ Management Portal\"><\/noscript><img decoding=\"async\" width=\"855\" height=\"112\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20855%20112%22%3E%3C%2Fsvg%3E\" alt=\"RabbitMQ Management Portal to monitor microservices messages.\" class=\"wp-image-39530 lazyload\" title=\"Monitor RabbitMQ Management Portal\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/rabbitmq-management-portal-visit.png\"><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>AMQP port: 5672<strong><br><\/strong><\/li>\n\n\n\n<li>Visit Management UI:<a href=\"http:\/\/localhost:15672\" target=\"_blank\" rel=\"noreferrer noopener\"> http:\/\/localhost:15672<\/a> (default user\/pass: guest \/ guest)<br><br><noscript><img decoding=\"async\" width=\"855\" height=\"324\" class=\"wp-image-39553\" style=\"width: 855px;\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/docker-rabbitmq-microservices.png\" alt=\"Use Docker to run RabbitMQ for microservice communication.\" title=\"Run RabbitMQ using Docker\"><\/noscript><img decoding=\"async\" width=\"855\" height=\"324\" class=\"wp-image-39553 lazyload\" style=\"width: 855px;\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20855%20324%22%3E%3C%2Fsvg%3E\" alt=\"Use Docker to run RabbitMQ for microservice communication.\" title=\"Run RabbitMQ using Docker\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/docker-rabbitmq-microservices.png\"><br><br><\/li>\n\n\n\n<li>Management Home Page:<br><br><noscript><img decoding=\"async\" width=\"855\" height=\"408\" class=\"wp-image-39556\" style=\"width: 855px;\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/rabbitmq-management-dashboard.png\" alt=\"RabbitMQ management portal home dashboard view.\" title=\"RabbitMQ Management Portal Home\"><\/noscript><img decoding=\"async\" width=\"855\" height=\"408\" class=\"wp-image-39556 lazyload\" style=\"width: 855px;\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20855%20408%22%3E%3C%2Fsvg%3E\" alt=\"RabbitMQ management portal home dashboard view.\" title=\"RabbitMQ Management Portal Home\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/rabbitmq-management-dashboard.png\"><br><br><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Common Event DTOs<\/strong><\/h3>\n\n\n\n<p>Each microservice defines its own copy of the following DTO classes. This design supports microservices coordination and ensures modularity within a distributed system. For each DTO, ensure that it includes: a constructor with all fields, appropriate getters and setters, and an overridden toString() method.<\/p>\n\n\n\n<p><strong>Debit Service \u2192 com.debitservice.events<\/strong><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">TransferRequested<\/span> <span class=\"hljs-keyword\">implements<\/span> <span class=\"hljs-title\">Serializable<\/span> <\/span>{\n    <span class=\"hljs-keyword\">private<\/span> String transferId;\n    <span class=\"hljs-keyword\">private<\/span> String fromAccount;\n    <span class=\"hljs-keyword\">private<\/span> String toAccount;\n    <span class=\"hljs-keyword\">private<\/span> Double amount;\n    <span class=\"hljs-keyword\">private<\/span> TransferRequested() {}\n}\n<span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">DebitCompleted<\/span> <span class=\"hljs-keyword\">implements<\/span> <span class=\"hljs-title\">Serializable<\/span> <\/span>{\n    <span class=\"hljs-keyword\">private<\/span> String transferId;\n    <span class=\"hljs-keyword\">private<\/span> String fromAccount;\n    <span class=\"hljs-keyword\">private<\/span> String toAccount;\n    <span class=\"hljs-keyword\">private<\/span> Double amount;\n    <span class=\"hljs-keyword\">private<\/span> DebitCompleted() {}\n}\n<span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">DebitFailed<\/span> <span class=\"hljs-keyword\">implements<\/span> <span class=\"hljs-title\">Serializable<\/span> <\/span>{\n    <span class=\"hljs-keyword\">private<\/span> String transferId;\n    <span class=\"hljs-keyword\">private<\/span> String reason;\n    <span class=\"hljs-keyword\">private<\/span> DebitFailed() {}\n}\n<span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">CreditFailed<\/span> <span class=\"hljs-keyword\">implements<\/span> <span class=\"hljs-title\">Serializable<\/span> <\/span>{\n    <span class=\"hljs-keyword\">private<\/span> String transferId;\n    <span class=\"hljs-keyword\">private<\/span> String reason;\n    <span class=\"hljs-keyword\">private<\/span> Double refundAmount;\n    <span class=\"hljs-keyword\">private<\/span> String refundAccount;\n    <span class=\"hljs-keyword\">private<\/span> CreditFailed() {}\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><strong>Credit Service \u2192 com.creditservice.events<\/strong><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">DebitCompleted<\/span> <span class=\"hljs-keyword\">implements<\/span> <span class=\"hljs-title\">Serializable<\/span> <\/span>{\n    <span class=\"hljs-keyword\">private<\/span> String transferId;\n    <span class=\"hljs-keyword\">private<\/span> String fromAccount;\n    <span class=\"hljs-keyword\">private<\/span> String toAccount;\n    <span class=\"hljs-keyword\">private<\/span> Double amount;\n    <span class=\"hljs-keyword\">private<\/span> DebitCompleted() {}\n}\n<span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">CreditCompleted<\/span> <span class=\"hljs-keyword\">implements<\/span> <span class=\"hljs-title\">Serializable<\/span> <\/span>{\n    <span class=\"hljs-keyword\">private<\/span> String transferId;\n    <span class=\"hljs-keyword\">private<\/span> String toAccount;\n    <span class=\"hljs-keyword\">private<\/span> Double amount;\n    <span class=\"hljs-keyword\">private<\/span> CreditCompleted() {}\n}\n<span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">CreditFailed<\/span> <span class=\"hljs-keyword\">implements<\/span> <span class=\"hljs-title\">Serializable<\/span> <\/span>{\n    <span class=\"hljs-keyword\">private<\/span> String transferId;\n    <span class=\"hljs-keyword\">private<\/span> String reason;\n    <span class=\"hljs-keyword\">private<\/span> Double refundAmount;\n    <span class=\"hljs-keyword\">private<\/span> String refundAccount;\n    <span class=\"hljs-keyword\">private<\/span> CreditFailed() {}\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\"><strong>3. AccountStore Component (Both Services)<\/strong><\/h3>\n\n\n\n<p>We simulate accounts in-memory. Place this class in debit service under com.debitservice.store<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">package com.debitservice.store;\n\n<span class=\"hljs-keyword\">import<\/span> java.util.Map;\n<span class=\"hljs-keyword\">import<\/span> java.util.concurrent.ConcurrentHashMap;\n<span class=\"hljs-keyword\">import<\/span> org.springframework.stereotype.Component;\n\n@Component\npublic <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">AccountStore<\/span> <\/span>{\n\n\tprivate final <span class=\"hljs-built_in\">Map<\/span>&lt;<span class=\"hljs-built_in\">String<\/span>, Double&gt; accounts = <span class=\"hljs-keyword\">new<\/span> ConcurrentHashMap&lt;&gt;(<span class=\"hljs-built_in\">Map<\/span>.of(<span class=\"hljs-string\">\"A\"<\/span>, <span class=\"hljs-number\">100.0<\/span>, <span class=\"hljs-string\">\"B\"<\/span>, <span class=\"hljs-number\">50.0<\/span>));\n\tpublic <span class=\"hljs-built_in\">Map<\/span>&lt;<span class=\"hljs-built_in\">String<\/span>, Double&gt; getAccounts() {\n\t\t<span class=\"hljs-keyword\">return<\/span> accounts;\n\t}\n\tpublic Double getBalance(<span class=\"hljs-built_in\">String<\/span> acct) {\n\t\t<span class=\"hljs-keyword\">return<\/span> accounts.getOrDefault(acct, <span class=\"hljs-number\">0.0<\/span>);\n\t}\n\tpublic <span class=\"hljs-keyword\">void<\/span> updateBalance(<span class=\"hljs-built_in\">String<\/span> acct, Double newBal) {\n\t\taccounts.put(acct, newBal);\n\t}\n\tpublic boolean debit(<span class=\"hljs-built_in\">String<\/span> acct, Double amount) {\n\t\tsynchronized (accounts) {\n\t\t\tDouble balance = getBalance(acct);\n\t\t\t<span class=\"hljs-keyword\">if<\/span> (balance &gt;= amount) {\n\t\t\t\tDouble updated = balance - amount;\t\t\t\t\n\t\t\t\tupdateBalance(acct, updated);\n\t\t\t\t<span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-literal\">true<\/span>;\n\t\t\t} <span class=\"hljs-keyword\">else<\/span> {\n\t\t\t\t<span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-literal\">false<\/span>;\n\t\t\t}\n\t\t}\n\t}\n\tpublic <span class=\"hljs-keyword\">void<\/span> credit(<span class=\"hljs-built_in\">String<\/span> acct, Double amount) {\n\t\tsynchronized (accounts) {\n\t\t\tDouble balance = getBalance(acct);\n\t\t\tDouble updated = balance + amount;\n\t\t\tupdateBalance(acct, updated);\n\t\t}\n\t}\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h4 class=\"wp-block-heading\"><strong>Explanation<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>We use a ConcurrentHashMap to store balances for accounts &#8220;A&#8221; and &#8220;B&#8221; by default.<\/li>\n\n\n\n<li>Because we\u2019re not using a real database, this is purely in-memory; all state resets when the services restart.<br><\/li>\n\n\n\n<li>Methods:<br>\n<ul class=\"wp-block-list\">\n<li><strong>getAccounts(): <\/strong>returns the map for GET \/accounts endpoint.<br><\/li>\n\n\n\n<li><strong>getBalance(String)<\/strong>: returns current balance or 0.<br><\/li>\n\n\n\n<li><strong>updateBalance(String, Double): <\/strong>overwrites balance.<br><\/li>\n\n\n\n<li><strong>debit(String, Double): <\/strong>synchronized check and subtract; logs each step.<br><\/li>\n\n\n\n<li><strong>credit(String, Double): <\/strong>synchronized add; logs each step.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>This idempotency in microservices is crucial to avoid duplicate transactions in event driven architecture systems.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Spring Boot + RabbitMQ Configuration (AMQP)<\/strong><\/h3>\n\n\n\n<p>RabbitMQ is a message broker that uses the AMQP protocol (Advanced Message Queuing Protocol) to send and receive messages between different systems in a reliable and asynchronous manner.<\/p>\n\n\n\n<p>Spring Boot makes it easy to integrate RabbitMQ using the Spring AMQP module. It abstracts the low-level AMQP details, enabling seamless RabbitMQ microservice communication with simple annotations and configurations.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You use @RabbitListener to receive<strong> <\/strong>messages from a queue.<br><\/li>\n\n\n\n<li>You use RabbitTemplate.convertAndSend() to send messages to an exchange with a routing key.<br><\/li>\n\n\n\n<li>Spring handles message serialization, deserialization, connection management, retries, and error handling under the hood.<\/li>\n<\/ul>\n\n\n\n<p>Together, Spring Boot and RabbitMQ provide a clean and efficient way to enable event-driven communication between microservices or components in a distributed system.<\/p>\n\n\n\n<p>This idempotency in microservices is crucial to avoid duplicate transactions in event-driven architecture systems. For additional reading on building resilient systems with messaging queues and distributed services, refer to our guide on<a href=\"https:\/\/mobisoftinfotech.com\/resources\/blog\/devops\/spring-boot-apache-kafka-guide?utm_source=blog&amp;utm_campaign=saga-pattern-spring-boot_blog\"> Spring Boot with Apache Kafka<\/a><strong>.<\/strong><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Exchange, Routing Keys and Queues Configurations:<\/strong><\/h4>\n\n\n\n<p>We configure a single Direct Exchange named money.transfer.exchange, plus five queues:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>transfer.requested.queue<strong><br><\/strong><\/li>\n\n\n\n<li>debit.completed.queue<strong><br><\/strong><\/li>\n\n\n\n<li>debit.failed.queue<strong><br><\/strong><\/li>\n\n\n\n<li>credit.completed.queue<strong><br><\/strong><\/li>\n\n\n\n<li>credit.failed.queue<br><\/li>\n<\/ul>\n\n\n\n<p>Bindings route messages by routing key, e.g. &#8220;transfer.requested&#8221; \u2192 transfer.requested.queue, &#8220;debit.completed&#8221; \u2192 debit.completed.queue, etc.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><noscript><img decoding=\"async\" width=\"1200\" height=\"573\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/rabbitmq-message-routing-diagram.png\" alt=\"RabbitMQ route bindings by message routing key\" class=\"wp-image-39533\" title=\"RabbitMQ Message Routing Diagram\"><\/noscript><img decoding=\"async\" width=\"1200\" height=\"573\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%201200%20573%22%3E%3C%2Fsvg%3E\" alt=\"RabbitMQ route bindings by message routing key\" class=\"wp-image-39533 lazyload\" title=\"RabbitMQ Message Routing Diagram\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/rabbitmq-message-routing-diagram.png\"><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. Debit Service Implementation (Port 8081)<\/strong><\/h3>\n\n\n\n<p><strong>Debit-service package structure<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><noscript><img decoding=\"async\" width=\"351\" height=\"630\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/debit-service-package-structure.png\" alt=\"Debit-service package structure in Spring Boot microservice.\" class=\"wp-image-39534\" style=\"width:351px\" title=\"Debit Service Package Layout\"><\/noscript><img decoding=\"async\" width=\"351\" height=\"630\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20351%20630%22%3E%3C%2Fsvg%3E\" alt=\"Debit-service package structure in Spring Boot microservice.\" class=\"wp-image-39534 lazyload\" style=\"width:351px\" title=\"Debit Service Package Layout\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/debit-service-package-structure.png\"><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>5.1 application.properties (Debit Service)<\/strong><\/h4>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">spring.application.name=debit-service\nserver.port=8081\nspring.rabbitmq.host=localhost\nspring.rabbitmq.port=5672\nspring.rabbitmq.username=guest\nspring.rabbitmq.password=guest<\/code><\/span><\/pre>\n\n\n<h4 class=\"wp-block-heading\"><strong>5.2 DebitServiceApplication.java<\/strong><\/h4>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">package com.debitservice;\n\n<span class=\"hljs-keyword\">import<\/span> org.springframework.boot.SpringApplication;\n<span class=\"hljs-keyword\">import<\/span> org.springframework.boot.autoconfigure.SpringBootApplication;\n\n@SpringBootApplication\npublic <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">DebitServiceApplication<\/span> <\/span>{\n    public <span class=\"hljs-keyword\">static<\/span> <span class=\"hljs-keyword\">void<\/span> main(<span class=\"hljs-built_in\">String<\/span>&#091;] args) {\n        SpringApplication.run(DebitServiceApplication.class, args);\n    }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h4 class=\"wp-block-heading\"><strong>5.3 AccountStore.java<\/strong><\/h4>\n\n\n\n<p>Add the AccountStore class from the above given example for debit service.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>5.4 RabbitMQConfig.java<\/strong><\/h4>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">package com.debitservice.config;\n\n<span class=\"hljs-keyword\">import<\/span> org.springframework.amqp.core.AmqpTemplate;\n<span class=\"hljs-keyword\">import<\/span> org.springframework.amqp.core.Binding;\n<span class=\"hljs-keyword\">import<\/span> org.springframework.amqp.core.BindingBuilder;\n<span class=\"hljs-keyword\">import<\/span> org.springframework.amqp.core.DirectExchange;\n<span class=\"hljs-keyword\">import<\/span> org.springframework.amqp.core.Queue;\n<span class=\"hljs-keyword\">import<\/span> org.springframework.amqp.core.QueueBuilder;\n<span class=\"hljs-keyword\">import<\/span> org.springframework.amqp.rabbit.connection.ConnectionFactory;\n<span class=\"hljs-keyword\">import<\/span> org.springframework.amqp.rabbit.core.RabbitTemplate;\n<span class=\"hljs-keyword\">import<\/span> org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;\n<span class=\"hljs-keyword\">import<\/span> org.springframework.amqp.support.converter.MessageConverter;\n<span class=\"hljs-keyword\">import<\/span> org.springframework.context.annotation.Bean;\n<span class=\"hljs-keyword\">import<\/span> org.springframework.context.annotation.Configuration;\n\n@Configuration\npublic <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">RabbitMQConfig<\/span> <\/span>{\n\n\tpublic <span class=\"hljs-keyword\">static<\/span> final <span class=\"hljs-built_in\">String<\/span> EXCHANGE = <span class=\"hljs-string\">\"money.transfer.exchange\"<\/span>;\n\n\tpublic <span class=\"hljs-keyword\">static<\/span> final <span class=\"hljs-built_in\">String<\/span> QUEUE_TRANSFER_REQUESTED = <span class=\"hljs-string\">\"transfer.requested.queue\"<\/span>;\n\tpublic <span class=\"hljs-keyword\">static<\/span> final <span class=\"hljs-built_in\">String<\/span> QUEUE_DEBIT_COMPLETED = <span class=\"hljs-string\">\"debit.completed.queue\"<\/span>;\n\tpublic <span class=\"hljs-keyword\">static<\/span> final <span class=\"hljs-built_in\">String<\/span> QUEUE_DEBIT_FAILED = <span class=\"hljs-string\">\"debit.failed.queue\"<\/span>;\n\tpublic <span class=\"hljs-keyword\">static<\/span> final <span class=\"hljs-built_in\">String<\/span> QUEUE_CREDIT_COMPLETED = <span class=\"hljs-string\">\"credit.completed.queue\"<\/span>;\n\tpublic <span class=\"hljs-keyword\">static<\/span> final <span class=\"hljs-built_in\">String<\/span> QUEUE_CREDIT_FAILED = <span class=\"hljs-string\">\"credit.failed.queue\"<\/span>;\n\n\tpublic <span class=\"hljs-keyword\">static<\/span> final <span class=\"hljs-built_in\">String<\/span> RK_TRANSFER_REQUESTED = <span class=\"hljs-string\">\"transfer.requested\"<\/span>;\n\tpublic <span class=\"hljs-keyword\">static<\/span> final <span class=\"hljs-built_in\">String<\/span> RK_DEBIT_COMPLETED = <span class=\"hljs-string\">\"debit.completed\"<\/span>;\n\tpublic <span class=\"hljs-keyword\">static<\/span> final <span class=\"hljs-built_in\">String<\/span> RK_DEBIT_FAILED = <span class=\"hljs-string\">\"debit.failed\"<\/span>;\n\tpublic <span class=\"hljs-keyword\">static<\/span> final <span class=\"hljs-built_in\">String<\/span> RK_CREDIT_COMPLETED = <span class=\"hljs-string\">\"credit.completed\"<\/span>;\n\tpublic <span class=\"hljs-keyword\">static<\/span> final <span class=\"hljs-built_in\">String<\/span> RK_CREDIT_FAILED = <span class=\"hljs-string\">\"credit.failed\"<\/span>;\n\n\t@Bean\n\tDirectExchange sagaExchange() {\n\t\t<span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-keyword\">new<\/span> DirectExchange(EXCHANGE);\n\t}\n\n\t@Bean\n\tQueue transferRequestedQueue() {\n\t\t<span class=\"hljs-keyword\">return<\/span> QueueBuilder.durable(QUEUE_TRANSFER_REQUESTED).build();\n\t}\n\n\t@Bean\n\tQueue debitCompletedQueue() {\n\t\t<span class=\"hljs-keyword\">return<\/span> QueueBuilder.durable(QUEUE_DEBIT_COMPLETED).build();\n\t}\n\n\t@Bean\n\tQueue debitFailedQueue() {\n\t\t<span class=\"hljs-keyword\">return<\/span> QueueBuilder.durable(QUEUE_DEBIT_FAILED).build();\n\t}\n\n\t@Bean\n\tQueue creditCompletedQueue() {\n\t\t<span class=\"hljs-keyword\">return<\/span> QueueBuilder.durable(QUEUE_CREDIT_COMPLETED).build();\n\t}\n\n\t@Bean\n\tQueue creditFailedQueue() {\n\t\t<span class=\"hljs-keyword\">return<\/span> QueueBuilder.durable(QUEUE_CREDIT_FAILED).build();\n\t}\n\n\t@Bean\n\tBinding bindTransferRequested(Queue transferRequestedQueue, DirectExchange exchange) {\n\t\t<span class=\"hljs-keyword\">return<\/span> BindingBuilder.bind(transferRequestedQueue).to(exchange).with(RK_TRANSFER_REQUESTED);\n\t}\n\n\t@Bean\n\tBinding bindDebitCompleted(Queue debitCompletedQueue, DirectExchange exchange) {\n\t\t<span class=\"hljs-keyword\">return<\/span> BindingBuilder.bind(debitCompletedQueue).to(exchange).with(RK_DEBIT_COMPLETED);\n\t}\n\n\t@Bean\n\tBinding bindDebitFailed(Queue debitFailedQueue, DirectExchange exchange) {\n\t\t<span class=\"hljs-keyword\">return<\/span> BindingBuilder.bind(debitFailedQueue).to(exchange).with(RK_DEBIT_FAILED);\n\t}\n\n\t@Bean\n\tBinding bindCreditCompleted(Queue creditCompletedQueue, DirectExchange exchange) {\n\t\t<span class=\"hljs-keyword\">return<\/span> BindingBuilder.bind(creditCompletedQueue).to(exchange).with(RK_CREDIT_COMPLETED);\n\t}\n\n\t@Bean\n\tBinding bindCreditFailed(Queue creditFailedQueue, DirectExchange exchange) {\n\t\t<span class=\"hljs-keyword\">return<\/span> BindingBuilder.bind(creditFailedQueue).to(exchange).with(RK_CREDIT_FAILED);\n\t}\n\n\t@Bean\n\tMessageConverter converter() {\n\t\t<span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-keyword\">new<\/span> Jackson2JsonMessageConverter();\n\t}\n\n\t@Bean\n\tAmqpTemplate amqpTemplate(ConnectionFactory connectionFactory) {\n\t\tRabbitTemplate rabbitTemplate = <span class=\"hljs-keyword\">new<\/span> RabbitTemplate(connectionFactory);\n\t\trabbitTemplate.setMessageConverter(converter());\n\t\t<span class=\"hljs-keyword\">return<\/span> rabbitTemplate;\n\t}\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h4 class=\"wp-block-heading\"><strong>5.5 DebitEventHandler.java<\/strong><\/h4>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">package com.debitservice.handler;\n\n<span class=\"hljs-keyword\">import<\/span> org.springframework.amqp.rabbit.annotation.RabbitListener;\n<span class=\"hljs-keyword\">import<\/span> org.springframework.amqp.rabbit.core.RabbitTemplate;\n<span class=\"hljs-keyword\">import<\/span> org.springframework.stereotype.Component;\n<span class=\"hljs-keyword\">import<\/span> com.debitservice.config.RabbitMQConfig;\n<span class=\"hljs-keyword\">import<\/span> com.debitservice.events.CreditFailed;\n<span class=\"hljs-keyword\">import<\/span> com.debitservice.events.DebitCompleted;\n<span class=\"hljs-keyword\">import<\/span> com.debitservice.events.DebitFailed;\n<span class=\"hljs-keyword\">import<\/span> com.debitservice.events.TransferRequested;\n<span class=\"hljs-keyword\">import<\/span> com.debitservice.store.AccountStore;\n\n@Component\npublic <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">DebitEventHandler<\/span> <\/span>{\n\n\tprivate final RabbitTemplate rabbitTemplate;\n\tprivate final AccountStore accountStore;\n\n\tpublic DebitEventHandler(RabbitTemplate rabbitTemplate, AccountStore accountStore) {\n\t\t<span class=\"hljs-keyword\">this<\/span>.rabbitTemplate = rabbitTemplate;\n\t\t<span class=\"hljs-keyword\">this<\/span>.accountStore = accountStore;\n\t}\n\n\t@RabbitListener(queues = RabbitMQConfig.QUEUE_TRANSFER_REQUESTED)\n\tpublic <span class=\"hljs-keyword\">void<\/span> handleTransferRequest(TransferRequested request) {\n\t\tboolean success = accountStore.debit(request.getFromAccount(), request.getAmount());\n\t\t<span class=\"hljs-keyword\">if<\/span> (success) {\n\t\t\tDebitCompleted event = <span class=\"hljs-keyword\">new<\/span> DebitCompleted(request.getTransferId(), request.getFromAccount(),\n\t\t\t\t\trequest.getToAccount(), request.getAmount());\n\t\t\trabbitTemplate.convertAndSend(RabbitMQConfig.EXCHANGE, RabbitMQConfig.RK_DEBIT_COMPLETED, event);\n\t\t} <span class=\"hljs-keyword\">else<\/span> {\n\t\t\tDebitFailed event = <span class=\"hljs-keyword\">new<\/span> DebitFailed(request.getTransferId(),\n\t\t\t\t\t<span class=\"hljs-string\">\"Insufficient balance in account: \"<\/span> + request.getFromAccount());\n\t\t\trabbitTemplate.convertAndSend(RabbitMQConfig.EXCHANGE, RabbitMQConfig.RK_DEBIT_FAILED, event);\n\t\t}\n\t}\n\n\t@RabbitListener(queues = RabbitMQConfig.QUEUE_CREDIT_FAILED)\n\tpublic <span class=\"hljs-keyword\">void<\/span> handleCreditFailed(CreditFailed event) {\n\t\taccountStore.credit(event.getRefundAccount(), event.getRefundAmount());\n\t}\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h4 class=\"wp-block-heading\"><strong>5.6 TransferController.java<\/strong><\/h4>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">package com.debitservice.controller;\n\n<span class=\"hljs-keyword\">import<\/span> org.springframework.amqp.rabbit.core.RabbitTemplate;\n<span class=\"hljs-keyword\">import<\/span> org.springframework.web.bind.annotation.PostMapping;\n<span class=\"hljs-keyword\">import<\/span> org.springframework.web.bind.annotation.RequestBody;\n<span class=\"hljs-keyword\">import<\/span> org.springframework.web.bind.annotation.RequestMapping;\n<span class=\"hljs-keyword\">import<\/span> org.springframework.web.bind.annotation.RestController;\n<span class=\"hljs-keyword\">import<\/span> com.debitservice.config.RabbitMQConfig;\n<span class=\"hljs-keyword\">import<\/span> com.debitservice.events.TransferRequested;\n\n@RestController\n@RequestMapping(<span class=\"hljs-string\">\"\/transfer\"<\/span>)\npublic <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">TransferController<\/span> <\/span>{\n\t\n\tprivate final RabbitTemplate rabbitTemplate;\n\n\tpublic TransferController(RabbitTemplate rabbitTemplate) {\n\t\t<span class=\"hljs-keyword\">this<\/span>.rabbitTemplate = rabbitTemplate;\n\t}\n\n\t@PostMapping\n\tpublic <span class=\"hljs-built_in\">String<\/span> requestTransfer(@RequestBody TransferRequested request) {\n\t\trabbitTemplate.convertAndSend(RabbitMQConfig.EXCHANGE, RabbitMQConfig.RK_TRANSFER_REQUESTED, request);\n\t\t<span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-string\">\"Transfer requested: \"<\/span> + request.getTransferId();\n\t}\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h4 class=\"wp-block-heading\"><strong>5.7 BalanceController.java<\/strong><\/h4>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">package com.debitservice.controller;\n\n<span class=\"hljs-keyword\">import<\/span> java.util.Map;\n\n<span class=\"hljs-keyword\">import<\/span> org.springframework.web.bind.annotation.GetMapping;\n<span class=\"hljs-keyword\">import<\/span> org.springframework.web.bind.annotation.RequestMapping;\n<span class=\"hljs-keyword\">import<\/span> org.springframework.web.bind.annotation.RestController;\n\n<span class=\"hljs-keyword\">import<\/span> com.debitservice.store.AccountStore;\n\n@RestController\n@RequestMapping(<span class=\"hljs-string\">\"\/accounts\"<\/span>)\npublic <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">BalanceController<\/span> <\/span>{\n\tprivate final AccountStore accountStore;\n\n\tpublic BalanceController(AccountStore accountStore) {\n\t\t<span class=\"hljs-keyword\">this<\/span>.accountStore = accountStore;\n\t}\n\n\t@GetMapping\n\tpublic <span class=\"hljs-built_in\">Map<\/span>&lt;<span class=\"hljs-built_in\">String<\/span>, Double&gt; getAccounts() {\n\t\t<span class=\"hljs-keyword\">return<\/span> accountStore.getAccounts();\n\t}\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\"><strong>6. Credit Service Implementation (Port 8082)<\/strong><\/h3>\n\n\n\n<p><strong>Credit-service package structure<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><noscript><img decoding=\"async\" width=\"351\" height=\"594\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/credit-service-package-structure.png\" alt=\"Credit-service package structure in Spring Boot architecture\" class=\"wp-image-39535\" style=\"width:351px\" title=\"Credit Service Package Layout\"><\/noscript><img decoding=\"async\" width=\"351\" height=\"594\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20351%20594%22%3E%3C%2Fsvg%3E\" alt=\"Credit-service package structure in Spring Boot architecture\" class=\"wp-image-39535 lazyload\" style=\"width:351px\" title=\"Credit Service Package Layout\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/credit-service-package-structure.png\"><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>6.1 application.properties (Credit Service)<\/strong><\/h4>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">spring.application.name=credit-service\nserver.port=8082\nspring.rabbitmq.host=localhost\nspring.rabbitmq.port=5672\nspring.rabbitmq.username=guest\nspring.rabbitmq.password=guest<\/code><\/span><\/pre>\n\n\n<h4 class=\"wp-block-heading\"><strong>6.2 CreditServiceApplication.java<\/strong><\/h4>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">package com.creditservice;\n\n<span class=\"hljs-keyword\">import<\/span> org.springframework.boot.SpringApplication;\n<span class=\"hljs-keyword\">import<\/span> org.springframework.boot.autoconfigure.SpringBootApplication;\n\n@SpringBootApplication\npublic <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">CreditServiceApplication<\/span> <\/span>{\n    public <span class=\"hljs-keyword\">static<\/span> <span class=\"hljs-keyword\">void<\/span> main(<span class=\"hljs-built_in\">String<\/span>&#091;] args) {\n        SpringApplication.run(CreditServiceApplication.class, args);\n    }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h4 class=\"wp-block-heading\"><strong>6.3 AccountStore.java (Credit Service)<\/strong><\/h4>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">package com.creditservice.store;\n\n<span class=\"hljs-keyword\">import<\/span> java.util.Map;\n<span class=\"hljs-keyword\">import<\/span> java.util.concurrent.ConcurrentHashMap;\n<span class=\"hljs-keyword\">import<\/span> org.springframework.stereotype.Component;\n\n@Component\npublic <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">AccountStore<\/span> <\/span>{\n\tprivate final <span class=\"hljs-built_in\">Map<\/span>&lt;<span class=\"hljs-built_in\">String<\/span>, Double&gt; accounts = <span class=\"hljs-keyword\">new<\/span> ConcurrentHashMap&lt;&gt;(<span class=\"hljs-built_in\">Map<\/span>.of(<span class=\"hljs-string\">\"C\"<\/span>, <span class=\"hljs-number\">20.0<\/span>, <span class=\"hljs-string\">\"D\"<\/span>, <span class=\"hljs-number\">80.0<\/span>));\n\n\tpublic <span class=\"hljs-built_in\">Map<\/span>&lt;<span class=\"hljs-built_in\">String<\/span>, Double&gt; getAccounts() {\n\t\t<span class=\"hljs-keyword\">return<\/span> accounts;\n\t}\n\n\tpublic Double getBalance(<span class=\"hljs-built_in\">String<\/span> acct) {\n\t\t<span class=\"hljs-keyword\">return<\/span> accounts.getOrDefault(acct, <span class=\"hljs-number\">0.0<\/span>);\n\t}\n\n\tpublic <span class=\"hljs-keyword\">void<\/span> updateBalance(<span class=\"hljs-built_in\">String<\/span> acct, Double newBal) {\n\t\taccounts.put(acct, newBal);\n\t}\n\n\tpublic boolean debit(<span class=\"hljs-built_in\">String<\/span> acct, Double amount) {\n\t\tsynchronized (accounts) {\n\t\t\tDouble balance = getBalance(acct);\n\t\t\t<span class=\"hljs-keyword\">if<\/span> (balance &gt;= amount) {\n\t\t\t\tDouble updated = balance - amount;\n\t\t\t\tupdateBalance(acct, updated);\n\t\t\t\t<span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-literal\">true<\/span>;\n\t\t\t} <span class=\"hljs-keyword\">else<\/span> {\n\t\t\t\t<span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-literal\">false<\/span>;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic <span class=\"hljs-keyword\">void<\/span> credit(<span class=\"hljs-built_in\">String<\/span> acct, Double amount) {\n\t\tsynchronized (accounts) {\n\t\t\tDouble balance = getBalance(acct);\n\t\t\tDouble updated = balance + amount;\n\t\t\tupdateBalance(acct, updated);\n\t\t}\n\t}\n}\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h4 class=\"wp-block-heading\"><strong>6.4 RabbitMQConfig.java (Credit Service)<\/strong><\/h4>\n\n\n\n<p>Use the same exchange and queue names as the Debit Service, so that they share the same RabbitMQ infrastructure.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>6.5 CreditEventHandler.java<\/strong><\/h4>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">package com.creditservice.handler;\n\n<span class=\"hljs-keyword\">import<\/span> org.springframework.amqp.rabbit.annotation.RabbitListener;\n<span class=\"hljs-keyword\">import<\/span> org.springframework.amqp.rabbit.core.RabbitTemplate;\n<span class=\"hljs-keyword\">import<\/span> org.springframework.stereotype.Component;\n<span class=\"hljs-keyword\">import<\/span> com.creditservice.config.RabbitMQConfig;\n<span class=\"hljs-keyword\">import<\/span> com.creditservice.events.CreditCompleted;\n<span class=\"hljs-keyword\">import<\/span> com.creditservice.events.CreditFailed;\n<span class=\"hljs-keyword\">import<\/span> com.creditservice.events.DebitCompleted;\n<span class=\"hljs-keyword\">import<\/span> com.creditservice.store.AccountStore;\n\n@Component\npublic <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">CreditEventHandler<\/span> <\/span>{\n\n\tprivate final RabbitTemplate rabbitTemplate;\n\tprivate final AccountStore accountStore;\n\n\tpublic CreditEventHandler(RabbitTemplate rabbitTemplate, AccountStore accountStore){\n\t\t<span class=\"hljs-keyword\">this<\/span>.rabbitTemplate = rabbitTemplate;\n\t\t<span class=\"hljs-keyword\">this<\/span>.accountStore = accountStore;\n\t}\n\n\t@RabbitListener(queues = RabbitMQConfig.QUEUE_DEBIT_COMPLETED)\n\tpublic <span class=\"hljs-keyword\">void<\/span> handleDebitCompleted(DebitCompleted event) {\n\t\t<span class=\"hljs-comment\">\/\/ Simulate a failure for a specific transferId \"FAIL-CREDIT\"<\/span>\n\t\t<span class=\"hljs-keyword\">if<\/span> (<span class=\"hljs-string\">\"FAIL-CREDIT\"<\/span>.equals(event.getTransferId())) {\n\t\t\tCreditFailed cf = <span class=\"hljs-keyword\">new<\/span> CreditFailed(event.getTransferId(), <span class=\"hljs-string\">\"Simulated credit failure\"<\/span>, event.getAmount(),\n\t\t\t\t\tevent.getFromAccount());\n\t\t\trabbitTemplate.convertAndSend(RabbitMQConfig.EXCHANGE, RabbitMQConfig.RK_CREDIT_FAILED, cf);\n\t\t\t<span class=\"hljs-keyword\">return<\/span>;\n\t\t}\n\t\taccountStore.credit(event.getToAccount(), event.getAmount());\n\n\t\tCreditCompleted cc = <span class=\"hljs-keyword\">new<\/span> CreditCompleted(event.getTransferId(), event.getFromAccount(), event.getAmount());\n\t\trabbitTemplate.convertAndSend(RabbitMQConfig.EXCHANGE, RabbitMQConfig.RK_CREDIT_COMPLETED, cc);\n\t}\n}\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h4 class=\"wp-block-heading\"><strong>6.6 BalanceController.java<\/strong><\/h4>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">package com.creditservice.controller;\n\n<span class=\"hljs-keyword\">import<\/span> com.creditservice.store.AccountStore;\n<span class=\"hljs-keyword\">import<\/span> org.springframework.web.bind.annotation.GetMapping;\n<span class=\"hljs-keyword\">import<\/span> org.springframework.web.bind.annotation.RestController;\n\n<span class=\"hljs-keyword\">import<\/span> java.util.Map;\n\n@RestController\n@RequestMapping(<span class=\"hljs-string\">\"\/accounts\"<\/span>)\npublic <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">BalanceController<\/span> <\/span>{\n    private final AccountStore accountStore;\n\n    public BalanceController(AccountStore accountStore) {\n        <span class=\"hljs-keyword\">this<\/span>.accountStore = accountStore;\n    }\n\n    @GetMapping\n    public <span class=\"hljs-built_in\">Map<\/span>&lt;<span class=\"hljs-built_in\">String<\/span>, Double&gt; getAccounts() {\n        <span class=\"hljs-keyword\">return<\/span> accountStore.getAccounts();\n    }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\"><strong>7. Testing the Saga Flow via Postman<\/strong><\/h3>\n\n\n\n<p>To validate the spring boot money transfer microservice, start both the Debit and Credit services. Ensure each service runs on its assigned port and is connected to the RabbitMQ server (typically on port 5672)..<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>7.1 Debit Service Accounts:<\/strong><\/h4>\n\n\n\n<p>Check the \/accounts endpoints of each service to view the current account balances. The Debit Service contains two accounts, A and B with balances { &#8220;A&#8221;: 100.0, &#8220;B&#8221;: 50.0 }, while the Credit Service includes accounts C and D with balances { &#8220;C&#8221;: 20.0, &#8220;D&#8221;: 80.0 }.<\/p>\n\n\n\n<p><strong>GET http:\/\/localhost:8081\/accounts<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><noscript><img decoding=\"async\" width=\"855\" height=\"408\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/debit-service-accounts-balance.png\" alt=\"Account balances displayed in Debit Service microservice\" class=\"wp-image-39536\" title=\"Debit Service Account View\"><\/noscript><img decoding=\"async\" width=\"855\" height=\"408\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20855%20408%22%3E%3C%2Fsvg%3E\" alt=\"Account balances displayed in Debit Service microservice\" class=\"wp-image-39536 lazyload\" title=\"Debit Service Account View\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/debit-service-accounts-balance.png\"><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>7.2 Credit Service Accounts:<\/strong><\/h4>\n\n\n\n<p><strong>GET http:\/\/localhost:8082\/accounts<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><noscript><img decoding=\"async\" width=\"855\" height=\"408\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/credit-service-accounts-balance.png\" alt=\"Account balances displayed in Credit Service microservice.\" class=\"wp-image-39537\" title=\"Credit Service Account View\"><\/noscript><img decoding=\"async\" width=\"855\" height=\"408\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20855%20408%22%3E%3C%2Fsvg%3E\" alt=\"Account balances displayed in Credit Service microservice.\" class=\"wp-image-39537 lazyload\" title=\"Credit Service Account View\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/credit-service-accounts-balance.png\"><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>7.3 Perform Successful Transfer<\/strong><\/h4>\n\n\n\n<p>To simulate a successful money transfer, initiate:<\/p>\n\n\n\n<p><strong>POST http:\/\/localhost:8081\/transfer<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><noscript><img decoding=\"async\" width=\"855\" height=\"492\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/successful-saga-pattern-transfer.png\" alt=\"Transaction completed successfully in saga pattern flow.\" class=\"wp-image-39538\" title=\"Successful Money Transfer Transaction\"><\/noscript><img decoding=\"async\" width=\"855\" height=\"492\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20855%20492%22%3E%3C%2Fsvg%3E\" alt=\"Transaction completed successfully in saga pattern flow.\" class=\"wp-image-39538 lazyload\" title=\"Successful Money Transfer Transaction\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/successful-saga-pattern-transfer.png\"><\/figure>\n\n\n\n<p><strong>Working<\/strong>:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Debit Service receives a TransferRequested with transferId=TXN1001.<br>\n<ul class=\"wp-block-list\">\n<li>accountStore.debit(&#8220;A&#8221;, 30.0) \u2192 succeeds (100.0 \u2265 30.0). A\u2019s new balance = 70.0.<\/li>\n\n\n\n<li>Publishes DebitCompleted(&#8220;TXN1001&#8243;,&#8221;A&#8221;,\u201dC\u201d,30.0).<\/li>\n\n\n\n<li>Verify Debit Service Account Balances:<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p>GET http:\/\/localhost:8081\/accounts \u2192 {&#8220;A&#8221;:70.0,&#8221;B&#8221;:50.0}<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><noscript><img decoding=\"async\" width=\"855\" height=\"392\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/debit-service-receives-request.png\" alt=\"Debit Service receives initial debit request in transaction.\" class=\"wp-image-39539\" title=\"Debit Service Receives Transaction Request\"><\/noscript><img decoding=\"async\" width=\"855\" height=\"392\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20855%20392%22%3E%3C%2Fsvg%3E\" alt=\"Debit Service receives initial debit request in transaction.\" class=\"wp-image-39539 lazyload\" title=\"Debit Service Receives Transaction Request\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/debit-service-receives-request.png\"><\/figure>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li>Credit Service consumes DebitCompleted:<br>\n<ul class=\"wp-block-list\">\n<li>Does not match &#8220;FAIL-CREDIT&#8221;, so accountStore.credit(&#8220;C&#8221;, 30.0) \u2192 C\u2019s new balance = 50.0.<\/li>\n\n\n\n<li>Publishes CreditCompleted(&#8220;TXN1001&#8243;,&#8221;A&#8221;,30.0).<\/li>\n\n\n\n<li>Verify Credit Service Account Balances:<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p>GET http:\/\/localhost:8082\/accounts \u2192 {&#8220;C&#8221;:50.0,&#8221;D&#8221;:80.0}<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><noscript><img decoding=\"async\" width=\"855\" height=\"392\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/credit-service-process-debitcompleted.png\" alt=\"Credit Service processes DebitCompleted event message.\" class=\"wp-image-39540\" title=\"Credit Service Consumes DebitCompleted Event\"><\/noscript><img decoding=\"async\" width=\"855\" height=\"392\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20855%20392%22%3E%3C%2Fsvg%3E\" alt=\"Credit Service processes DebitCompleted event message.\" class=\"wp-image-39540 lazyload\" title=\"Credit Service Consumes DebitCompleted Event\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/credit-service-process-debitcompleted.png\"><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>7.4 Insufficient Funds (Debit Failure)<\/strong><\/h4>\n\n\n\n<p>To simulate failure in debit:<\/p>\n\n\n\n<p>POST http:\/\/localhost:8081\/transfer<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><noscript><img decoding=\"async\" width=\"855\" height=\"482\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/debit-service-insufficient-funds.png\" alt=\"Debit service rejects transaction due to insufficient funds.\" class=\"wp-image-39541\" title=\" Debit Service Failure \u2013 Insufficient Funds\"><\/noscript><img decoding=\"async\" width=\"855\" height=\"482\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20855%20482%22%3E%3C%2Fsvg%3E\" alt=\"Debit service rejects transaction due to insufficient funds.\" class=\"wp-image-39541 lazyload\" title=\" Debit Service Failure \u2013 Insufficient Funds\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/debit-service-insufficient-funds.png\"><\/figure>\n\n\n\n<p><strong>What Happens<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Debit Service tries accountStore.debit(&#8220;A&#8221;,1000.0) \u2192 fails (70.0 &lt; 1000.0).<\/li>\n\n\n\n<li>Publishes DebitFailed(&#8220;TXN1002&#8243;,&#8221;Insufficient balance&#8230;&#8221;).<\/li>\n\n\n\n<li>Credit Service does not react to DebitFailed (no listener).<\/li>\n\n\n\n<li>Balances remain unchanged.<\/li>\n<\/ul>\n\n\n\n<p><strong>Verify<\/strong>:<\/p>\n\n\n\n<p><strong>Debit Service<\/strong>:<\/p>\n\n\n\n<p>GET http:\/\/localhost:8081\/accounts \u2192 {&#8220;A&#8221;:70.0,&#8221;B&#8221;:50.0}<\/p>\n\n\n\n<p>Credit Service remains the same.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>7.5 Simulated Credit Failure (Compensation)<\/strong><\/h4>\n\n\n\n<p>To simulate a credit failure and trigger the saga pattern compensation:<\/p>\n\n\n\n<p>POST http:\/\/localhost:8081\/transfer<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><noscript><img decoding=\"async\" width=\"855\" height=\"482\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/simulated-credit-service-failure.png\" alt=\"Simulated credit service failure to test compensation logic.\" class=\"wp-image-39542\" title=\"Credit Failure Simulation for Compensation\"><\/noscript><img decoding=\"async\" width=\"855\" height=\"482\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20855%20482%22%3E%3C%2Fsvg%3E\" alt=\"Simulated credit service failure to test compensation logic.\" class=\"wp-image-39542 lazyload\" title=\"Credit Failure Simulation for Compensation\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/simulated-credit-service-failure.png\"><\/figure>\n\n\n\n<p><strong>Working<\/strong>:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Debit Service<\/strong>:<br>\n<ul class=\"wp-block-list\">\n<li>accountStore.debit(&#8220;A&#8221;,20.0) \u2192 succeeds (A\u2019s balance = 50.0).<\/li>\n\n\n\n<li>Publishes DebitCompleted(&#8220;FAIL-CREDIT&#8221;,&#8221;A&#8221;,20.0).<br><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Credit Service<\/strong> receives DebitCompleted(&#8220;FAIL-CREDIT&#8221;,\u2026):<br>\n<ul class=\"wp-block-list\">\n<li>Matches &#8220;FAIL-CREDIT&#8221; \u2192 publishes CreditFailed(&#8220;FAIL-CREDIT&#8221;, &#8220;Simulated credit failure&#8221;).<br><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Debit Service<\/strong> listens for CreditFailed:<br>\n<ul class=\"wp-block-list\">\n<li>accountStore.credit(&#8220;A&#8221;,50.0) (compensation refund). A\u2019s balance goes back to 100.0 (50.0 + 50.0).<br><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p><strong>Verify<\/strong>:<\/p>\n\n\n\n<p><strong>Debit Service<\/strong>:<\/p>\n\n\n\n<p>GET http:\/\/localhost:8081\/accounts \u2192 {&#8220;A&#8221;:100.0,&#8221;B&#8221;:50.0}<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><noscript><img decoding=\"async\" width=\"855\" height=\"392\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/debit-service-final-state.png\" alt=\"Final state of Debit Service after saga execution.\" class=\"wp-image-39543\" title=\" Final State of Debit Service Post-Transaction\"><\/noscript><img decoding=\"async\" width=\"855\" height=\"392\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20855%20392%22%3E%3C%2Fsvg%3E\" alt=\"Final state of Debit Service after saga execution.\" class=\"wp-image-39543 lazyload\" title=\" Final State of Debit Service Post-Transaction\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/debit-service-final-state.png\"><\/figure>\n\n\n\n<p>Credit Service remains unchanged.<\/p>\n\n\n\n<p>State of RabbitMQ Exchanges and Queues on Management Portal<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><noscript><img decoding=\"async\" width=\"855\" height=\"360\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/credit-service-unchanged-on-failure.png\" alt=\"Credit service remains unchanged due to transaction failure.\" class=\"wp-image-39544\" title=\"Credit Service Unchanged after Failed Transaction\"><\/noscript><img decoding=\"async\" width=\"855\" height=\"360\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20855%20360%22%3E%3C%2Fsvg%3E\" alt=\"Credit service remains unchanged due to transaction failure.\" class=\"wp-image-39544 lazyload\" title=\"Credit Service Unchanged after Failed Transaction\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/credit-service-unchanged-on-failure.png\"><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><noscript><img decoding=\"async\" width=\"855\" height=\"383\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/rabbitmq-exchanges-queues-state.png\" alt=\"View RabbitMQ exchanges and queues state during saga execution.\" class=\"wp-image-39545\" title=\"RabbitMQ State During Saga Execution\"><\/noscript><img decoding=\"async\" width=\"855\" height=\"383\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20855%20383%22%3E%3C%2Fsvg%3E\" alt=\"View RabbitMQ exchanges and queues state during saga execution.\" class=\"wp-image-39545 lazyload\" title=\"RabbitMQ State During Saga Execution\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/rabbitmq-exchanges-queues-state.png\"><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>8. Conclusion &amp; Next Steps<\/strong><\/h3>\n\n\n\n<p>We\u2019ve successfully built a Spring Boot money transfer microservice using the Saga pattern that demonstrates:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>RabbitMQ (AMQP) for asynchronous messaging<br><\/li>\n\n\n\n<li>@RabbitListener for consuming events<br><\/li>\n\n\n\n<li>AccountStore for in memory balances<br><\/li>\n\n\n\n<li>REST APIs for testing with Postman:<br>\n<ul class=\"wp-block-list\">\n<li>POST \/transfer (Debit Service)<br><\/li>\n\n\n\n<li>GET \/accounts (both services)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p><strong>Next Steps:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Use a database<\/strong>: Persist accounts and saga state for production.<br><\/li>\n\n\n\n<li><strong>Docker Compose<\/strong>: Combine both services and RabbitMQ into one docker-compose.yml.<br><\/li>\n\n\n\n<li><strong>Unit tests<\/strong>: Write tests for each handler using @SpringBootTest and mocks.<br><\/li>\n\n\n\n<li><strong>Security<\/strong>: Add authentication\/authorization to REST endpoints.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Wrapping Up:<\/strong><\/h2>\n\n\n\n<p>We\u2019ve successfully implemented a distributed transaction system using the Saga pattern. Now you can extend this pattern for more complex workflows and scale it for production. Keep experimenting with advanced features like fault tolerance and resilience, and don&#8217;t forget to secure your services for a complete, production ready solution.&nbsp;<\/p>\n\n\n\n<p>If you&#8217;re looking to build scalable microservices or distributed systems, explore our end-to-end<a href=\"https:\/\/mobisoftinfotech.com\/services\/software-development-company?utm_source=blog&amp;utm_campaign=saga-pattern-spring-boot_blog\"> software development services<\/a> tailored for modern enterprise needs. You can explore the complete source code on our<a href=\"https:\/\/github.com\/mobisoftinfotech\/saga-pattern-spring-boo-rabbitmq\" target=\"_blank\" rel=\"noreferrer noopener\"> GitHub<\/a><strong> <\/strong>repository.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/mobisoftinfotech.com\/contact-us?utm_source=blog&amp;utm_campaign=saga-pattern-spring-boot_blog\"><noscript><img decoding=\"async\" width=\"855\" height=\"363\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/build-scalable-microservices.png\" alt=\"Build scalable microservices with the right technology stack.\" class=\"wp-image-39546\" title=\" Build Scalable Microservices with the Right Technology\"><\/noscript><img decoding=\"async\" width=\"855\" height=\"363\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20855%20363%22%3E%3C%2Fsvg%3E\" alt=\"Build scalable microservices with the right technology stack.\" class=\"wp-image-39546 lazyload\" title=\" Build Scalable Microservices with the Right Technology\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/build-scalable-microservices.png\"><\/a><\/figure>\n\n\n<div class=\"modern-author-card\">\n    <div class=\"author-card-content\">\n        <div class=\"author-info-section\">\n            <div class=\"author-avatar\">\n                <noscript><img decoding=\"async\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/onkar-musale-saga-pattern-author.png\" alt=\"Onkar Musale\"><\/noscript><img decoding=\"async\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" alt=\"Onkar Musale\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/onkar-musale-saga-pattern-author.png\" class=\" lazyload\">\n            <\/div>\n            <div class=\"author-details\">\n                <h3 class=\"author-name\">Onkar Musale<\/h3>\n                <p class=\"author-title\">Senior Software Engineer<\/p>\n                <a href=\"javascript:void(0);\" class=\"read-more-link read-more-btn\" onclick=\"toggleAuthorBio(this); return false;\">Read more <noscript><img decoding=\"async\" src=\"\/assets\/images\/blog\/Vector.png\" alt=\"expand\" class=\"read-more-arrow down-arrow\"><\/noscript><img decoding=\"async\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" alt=\"expand\" class=\"read-more-arrow down-arrow lazyload\" data-src=\"\/assets\/images\/blog\/Vector.png\"><\/a>\n                <div class=\"author-bio-expanded\">\n                    <p>Onkar Musale is a Senior Software Engineer at <a href=\"https:\/\/mobisoftinfotech.com?utm_source=blog&amp;utm_medium=internal_link&amp;utm_campaign=saga-pattern-spring-boot_blog&amp;utm_content=home-page\">Mobisoft Infotech<\/a> with over 6.5 years of experience in Java backend development and cloud technologies, I specialize in designing scalable microservices and robust RESTful APIs using Java Spring Boot and Golang. I'm passionate about leveraging AWS, Docker, and Kubernetes to build high-performance, cost-efficient solutions. My expertise spans database management (MySQL, PostgreSQL, MongoDB), API documentation, payment gateway integrations, and advanced cloud configurations. I'm a quick learner, resilient, and always eager to adapt to new technologies, dedicated to delivering quality solutions that drive business success.<\/p>\n                    <div class=\"author-social-links\"><div class=\"social-icon\"><a href=\"https:\/\/www.linkedin.com\/in\/onkar96\" target=\"_blank\" rel=\"nofollow noopener\"><i class=\"icon-sprite linkedin\"><\/i><\/a><\/div><\/div>\n                    <a href=\"javascript:void(0);\" class=\"read-more-link read-less-btn\" onclick=\"toggleAuthorBio(this); return false;\" style=\"display: none;\">Read less <noscript><img decoding=\"async\" src=\"\/assets\/images\/blog\/Vector.png\" alt=\"collapse\" class=\"read-more-arrow up-arrow\"><\/noscript><img decoding=\"async\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" alt=\"collapse\" class=\"read-more-arrow up-arrow lazyload\" data-src=\"\/assets\/images\/blog\/Vector.png\"><\/a>\n                <\/div>\n            <\/div>\n        <\/div>\n        <div class=\"share-section\">\n            <span class=\"share-label\">Share Article<\/span>\n            <div class=\"social-share-buttons\">\n                <a href=\"https:\/\/www.facebook.com\/sharer\/sharer.php?u=https%3A%2F%2Fmobisoftinfotech.com%2Fresources%2Fblog%2Fmicroservices%2Fsaga-pattern-spring-boot-rabbitmq-tutorial\" target=\"_blank\" class=\"share-btn facebook-share\"><i class=\"fa fa-facebook-f\"><\/i><\/a>\n                <a href=\"https:\/\/www.linkedin.com\/sharing\/share-offsite\/?url=https%3A%2F%2Fmobisoftinfotech.com%2Fresources%2Fblog%2Fmicroservices%2Fsaga-pattern-spring-boot-rabbitmq-tutorial\" target=\"_blank\" class=\"share-btn linkedin-share\"><i class=\"fa fa-linkedin\"><\/i><\/a>\n            <\/div>\n        <\/div>\n    <\/div>\n<\/div>\n\n\n\n<style>\n.post-content p{\n    margin: 20px 0 20px;\n}\nh4.wp-block-heading{\nfont-size:20px;\n}\nh3.wp-block-heading{\nfont-size:22px;\n}\nh3.wp-block-heading.h3-list {\n    position: relative;\nfont-size:20px;\n    padding-left: 20px;\n}\nh3.wp-block-heading.h3-list:before {\n    position: absolute;\n    content: '';\n    background: #0d265c;\n    height: 9px;\n    width: 9px;\n    left: 0;\n    border-radius: 50px;\n    top: 8px;\n}\n@media only screen and (max-width: 991px) {\nul.wp-block-list.step-9-ul {\n    margin-left: 0px;\n}\n.step-9-h4{padding-left:0px;}\n    .post-content li {\n       padding-left: 25px;\n    }\n    .post-content li:before {\n        content: '';\n         width: 9px;\n        height: 9px;\n        background-color: #0d265c;\n        border-radius: 50%;\n        position: absolute;\n        left: 0px;\n        top: 12px;\n    }\n}\n<\/style>\n<script type=\"application\/ld+json\">\n{\n  \"@context\": \"https:\/\/schema.org\",\n  \"@type\": \"Article\",\n  \"mainEntityOfPage\": {\n    \"@type\": \"WebPage\",\n    \"@id\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial\"\n  },\n  \"headline\": \"Saga Pattern Microservices Tutorial: Using the Saga Pattern with Spring Boot & RabbitMQ\",\n  \"description\": \"A step-by-step tutorial on using the Saga Pattern in Spring Boot microservices with RabbitMQ for distributed transactions and eventual consistency.\",\n  \"image\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/saga-pattern-spring-boot-rabbitmq-tutorial\",\n  \"author\": {\n    \"@type\": \"Person\",\n    \"name\": \"Onkar Musale\",\n    \"description\": \"Onkar Musale is a Senior Software Engineer at Mobisoft Infotech with over 6.5 years of experience in Java backend development and cloud technologies, I specialize in designing scalable microservices and robust RESTful APIs using Java Spring Boot and Golang. I\u2019m passionate about leveraging AWS, Docker, and Kubernetes to build high-performance, cost-efficient solutions. My expertise spans database management (MySQL, PostgreSQL, MongoDB), API documentation, payment gateway integrations, and advanced cloud configurations. I\u2019m a quick learner, resilient, and always eager to adapt to new technologies, dedicated to delivering quality solutions that drive business success.\"\n  },\n  \"publisher\": {\n    \"@type\": \"Organization\",\n    \"name\": \"Mobisoft Infotech\",\n    \"logo\": {\n      \"@type\": \"ImageObject\",\n      \"url\": \"https:\/\/mobisoftinfotech.com\/assets\/images\/mshomepage\/MI_Logo-white.svg\",\n      \"width\": 600,\n      \"height\": 600\n    }\n  },\n  \"datePublished\": \"2025-06-12\",\n  \"dateModified\": \"2025-06-12\"\n}\n<\/script>\n<script type=\"application\/ld+json\">\n{\n    \"@context\": \"https:\/\/schema.org\",\n    \"@type\": \"LocalBusiness\",\n    \"name\": \"Mobisoft Infotech\",\n    \"url\": \"https:\/\/mobisoftinfotech.com\",\n    \"logo\": \"https:\/\/mobisoftinfotech.com\/assets\/images\/mshomepage\/MI_Logo-white.svg\",\n    \"description\": \"Mobisoft Infotech specializes in custom software development and digital solutions.\",\n    \"address\": {\n        \"@type\": \"PostalAddress\",\n        \"streetAddress\": \"5718 Westheimer Rd Suite 1000\",\n        \"addressLocality\": \"Houston\",\n        \"addressRegion\": \"TX\",\n        \"postalCode\": \"77057\",\n        \"addressCountry\": \"USA\"\n    },\n    \"contactPoint\": [{\n        \"@type\": \"ContactPoint\",\n        \"telephone\": \"+1-855-572-2777\",\n        \"contactType\": \"Customer Service\",\n        \"areaServed\": [\"USA\", \"Worldwide\"],\n        \"availableLanguage\": [\"English\"]\n    }],\n    \"sameAs\": [\n        \"https:\/\/www.facebook.com\/pages\/Mobisoft-Infotech\/131035500270720\",\n        \"https:\/\/x.com\/MobisoftInfo\",\n        \"https:\/\/www.linkedin.com\/company\/mobisoft-infotech\",\n        \"https:\/\/in.pinterest.com\/mobisoftinfotech\/\",\n        \"https:\/\/www.instagram.com\/mobisoftinfotech\/\",\n        \"https:\/\/github.com\/MobisoftInfotech\",\n        \"https:\/\/www.behance.net\/MobisoftInfotech\",\n        \"https:\/\/www.youtube.com\/@MobisoftinfotechHouston\"\n    ]\n}\n<\/script>\n<script type=\"application\/ld+json\">\n{\n  \"@context\": \"https:\/\/schema.org\",\n  \"@type\": \"Organization\",\n  \"name\": \"Mobisoft Infotech\",\n  \"url\": \"https:\/\/mobisoftinfotech.com\/\",\n  \"logo\": \"https:\/\/mobisoftinfotech.com\/assets\/images\/MI_Logo.svg\",\n  \"sameAs\": [\n    \"https:\/\/www.facebook.com\/pages\/Mobisoft-Infotech\/131035500270720\",\n    \"https:\/\/x.com\/MobisoftInfo\",\n    \"https:\/\/www.instagram.com\/mobisoftinfotech\/\",\n    \"https:\/\/www.youtube.com\/@MobisoftinfotechHouston\",\n    \"https:\/\/www.linkedin.com\/company\/mobisoft-infotech\",\n    \"https:\/\/in.pinterest.com\/mobisoftinfotech\/\",\n    \"https:\/\/github.com\/MobisoftInfotech\"\n  ],\n  \"contactPoint\": [\n    {\n      \"@type\": \"ContactPoint\",\n      \"telephone\": \"+1-855-572-2777\",\n      \"contactType\": \"Customer Service\",\n      \"areaServed\": \"US\",\n      \"availableLanguage\": [\"English\"]\n    },\n    {\n      \"@type\": \"ContactPoint\",\n      \"telephone\": \"+91-858-600-8627\",\n      \"contactType\": \"Customer Service\",\n      \"areaServed\": \"IN\",\n      \"availableLanguage\": [\"English\"]\n    }\n  ]\n}\n<\/script>\n<script type=\"application\/ld+json\">\n    [\n    {\n            \"@context\": \"https:\/\/schema.org\",\n            \"@type\": \"ImageObject\",\n            \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/software-development-microservices.png\",\n            \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial\",\n            \"name\": \"Custom Software Development for Microservices\",\n            \"caption\": \"Discover custom-built microservices with event-driven architecture.\",\n            \"description\": \"Promote your next microservice project with flexible, tailored software development services.\",\n            \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n            \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n            \"creditText\": \"Mobisoft Infotech\",\n            \"copyrightNotice\": \"Mobisoft Infotech\",\n            \"creator\": {\n                \"@type\": \"Organization\",\n                \"name\": \"Mobisoft Infotech\"\n            },\n            \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/software-development-microservices.png\"\n        },\n        {\n            \"@context\": \"https:\/\/schema.org\",\n            \"@type\": \"ImageObject\",\n            \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/build-scalable-microservices.png\",\n            \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial\",\n            \"name\": \"Build Scalable Microservices with the Right Technology\",\n            \"caption\": \"Turn your business idea into reality with robust Spring Boot microservices.\",\n            \"description\": \"Empower your next big idea using RabbitMQ and Spring Boot in a Saga Pattern architecture.\",\n            \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n            \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n            \"creditText\": \"Mobisoft Infotech\",\n            \"copyrightNotice\": \"Mobisoft Infotech\",\n            \"creator\": {\n                \"@type\": \"Organization\",\n                \"name\": \"Mobisoft Infotech\"\n            },\n            \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/build-scalable-microservices.png\"\n        },\n        {\n            \"@context\": \"https:\/\/schema.org\",\n            \"@type\": \"ImageObject\",\n            \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/onkar-musale-saga-pattern-author.png\",\n            \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial\",\n            \"name\": \"Author-Onkar Musale, expert in Spring Boot\",\n            \"caption\": \"Onkar Musale shares insights on Saga Pattern and microservices.\",\n            \"description\": \"Onkar Musale, software architect, explains RabbitMQ-based microservices using the Saga Pattern.\",\n            \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n            \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n            \"creditText\": \"Mobisoft Infotech\",\n            \"copyrightNotice\": \"Mobisoft Infotech\",\n            \"creator\": {\n                \"@type\": \"Organization\",\n                \"name\": \"Mobisoft Infotech\"\n            },\n            \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/onkar-musale-saga-pattern-author.png\"\n        },\n        {\n            \"@context\": \"https:\/\/schema.org\",\n            \"@type\": \"ImageObject\",\n            \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/saga-pattern-spring-boot-rabbitmq-tutorial.png\",\n            \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial\",\n            \"name\": \"Saga Pattern Microservices Tutorial: Using the Saga Pattern with Spring Boot & RabbitMQ\",\n            \"caption\": \"Learn how to implement the Saga Pattern in Spring Boot microservices.\",\n            \"description\": \"A comprehensive guide to using the Saga Pattern for distributed transactions with RabbitMQ and Spring Boot.\",\n            \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n            \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n            \"creditText\": \"Mobisoft Infotech\",\n            \"copyrightNotice\": \"Mobisoft Infotech\",\n            \"creator\": {\n                \"@type\": \"Organization\",\n                \"name\": \"Mobisoft Infotech\"\n            },\n            \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/saga-pattern-spring-boot-rabbitmq-tutorial.png\"\n        },\n        {\n            \"@context\": \"https:\/\/schema.org\",\n            \"@type\": \"ImageObject\",\n            \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/rabbitmq-message-routing-diagram.png\",\n            \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial\",\n            \"name\": \"RabbitMQ Message Routing Diagram\",\n            \"caption\": \"Understand RabbitMQ message routing using bindings and routing keys.\",\n            \"description\": \"This visual explains how asynchronous messaging works in RabbitMQ for distributed systems.\",\n            \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n            \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n            \"creditText\": \"Mobisoft Infotech\",\n            \"copyrightNotice\": \"Mobisoft Infotech\",\n            \"creator\": {\n                \"@type\": \"Organization\",\n                \"name\": \"Mobisoft Infotech\"\n            },\n            \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/rabbitmq-message-routing-diagram.png\"\n        },\n        {\n            \"@context\": \"https:\/\/schema.org\",\n            \"@type\": \"ImageObject\",\n            \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/maven-project-import-ide.png\",\n            \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial\",\n            \"name\": \" Import Maven Project into IDE\",\n            \"caption\": \"Start your microservices project by importing the Maven setup.\",\n            \"description\": \"Step-by-step setup of the Spring Boot Maven project for implementing the Saga Pattern.\",\n            \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n            \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n            \"creditText\": \"Mobisoft Infotech\",\n            \"copyrightNotice\": \"Mobisoft Infotech\",\n            \"creator\": {\n                \"@type\": \"Organization\",\n                \"name\": \"Mobisoft Infotech\"\n            },\n            \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/maven-project-import-ide.png\"\n        },\n        {\n            \"@context\": \"https:\/\/schema.org\",\n            \"@type\": \"ImageObject\",\n            \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/docker-rabbitmq-microservices.png\",\n            \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial\",\n            \"name\": \"Run RabbitMQ using Docker\",\n            \"caption\": \"Set up RabbitMQ with Docker for microservice communication.\",\n            \"description\": \"Enable asynchronous messaging using RabbitMQ containers for reliable microservices.\",\n            \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n            \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n            \"creditText\": \"Mobisoft Infotech\",\n            \"copyrightNotice\": \"Mobisoft Infotech\",\n            \"creator\": {\n                \"@type\": \"Organization\",\n                \"name\": \"Mobisoft Infotech\"\n            },\n            \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/docker-rabbitmq-microservices.png\"\n        },\n        {\n            \"@context\": \"https:\/\/schema.org\",\n            \"@type\": \"ImageObject\",\n            \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/rabbitmq-management-portal-visit.png\",\n            \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial\",\n            \"name\": \"Monitor RabbitMQ Management Portal\",\n            \"caption\": \"Track distributed message flows using the RabbitMQ dashboard.\",\n            \"description\": \"Check the state of exchanges and queues during saga pattern flow.\",\n            \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n            \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n            \"creditText\": \"Mobisoft Infotech\",\n            \"copyrightNotice\": \"Mobisoft Infotech\",\n            \"creator\": {\n                \"@type\": \"Organization\",\n                \"name\": \"Mobisoft Infotech\"\n            },\n            \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/rabbitmq-management-portal-visit.png\"\n        },\n        {\n            \"@context\": \"https:\/\/schema.org\",\n            \"@type\": \"ImageObject\",\n            \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/debit-service-package-structure.png\",\n            \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial\",\n            \"name\": \"Debit Service Package Layout\",\n            \"caption\": \"Visualize the architecture of the debit service microservice.\",\n            \"description\": \"Debit microservice structure as part of the Saga Pattern implementation in Spring Boot.\",\n            \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n            \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n            \"creditText\": \"Mobisoft Infotech\",\n            \"copyrightNotice\": \"Mobisoft Infotech\",\n            \"creator\": {\n                \"@type\": \"Organization\",\n                \"name\": \"Mobisoft Infotech\"\n            },\n            \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/debit-service-package-structure.png\"\n        },\n        {\n            \"@context\": \"https:\/\/schema.org\",\n            \"@type\": \"ImageObject\",\n            \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/credit-service-package-structure.png\",\n            \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial\",\n            \"name\": \"Credit Service Package Layout\",\n            \"caption\": \"Explore the credit service structure built with Spring Boot.\",\n            \"description\": \"Credit microservice module showing orchestration in a Saga-based architecture.\",\n            \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n            \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n            \"creditText\": \"Mobisoft Infotech\",\n            \"copyrightNotice\": \"Mobisoft Infotech\",\n            \"creator\": {\n                \"@type\": \"Organization\",\n                \"name\": \"Mobisoft Infotech\"\n            },\n            \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/credit-service-package-structure.png\"\n        },\n        {\n            \"@context\": \"https:\/\/schema.org\",\n            \"@type\": \"ImageObject\",\n            \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/rabbitmq-management-dashboard.png\",\n            \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial\",\n            \"name\": \"RabbitMQ Management Portal Home\",\n            \"caption\": \"Access RabbitMQ portal to manage queues and exchanges.\",\n            \"description\": \"Portal interface for monitoring asynchronous transactions in microservices.\",\n            \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n            \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n            \"creditText\": \"Mobisoft Infotech\",\n            \"copyrightNotice\": \"Mobisoft Infotech\",\n            \"creator\": {\n                \"@type\": \"Organization\",\n                \"name\": \"Mobisoft Infotech\"\n            },\n            \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/rabbitmq-management-dashboard.png\"\n        },\n        {\n            \"@context\": \"https:\/\/schema.org\",\n            \"@type\": \"ImageObject\",\n            \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/debit-service-accounts-balance.png\",\n            \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial\",\n            \"name\": \"Debit Service Account View\",\n            \"caption\": \"Check balance state in debit microservice for transaction testing.\",\n            \"description\": \"Debit account balances involved in distributed transaction simulation.\",\n            \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n            \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n            \"creditText\": \"Mobisoft Infotech\",\n            \"copyrightNotice\": \"Mobisoft Infotech\",\n            \"creator\": {\n                \"@type\": \"Organization\",\n                \"name\": \"Mobisoft Infotech\"\n            },\n            \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/debit-service-accounts-balance.png\"\n        },\n        {\n            \"@context\": \"https:\/\/schema.org\",\n            \"@type\": \"ImageObject\",\n            \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/credit-service-accounts-balance.png\",\n            \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial\",\n            \"name\": \"Credit Service Account View\",\n            \"caption\": \"Monitor credit microservice account states after event processing.\",\n            \"description\": \"Credit service account view to test compensation and transaction completion.\",\n            \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n            \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n            \"creditText\": \"Mobisoft Infotech\",\n            \"copyrightNotice\": \"Mobisoft Infotech\",\n            \"creator\": {\n                \"@type\": \"Organization\",\n                \"name\": \"Mobisoft Infotech\"\n            },\n            \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/credit-service-accounts-balance.png\"\n        },\n        {\n            \"@context\": \"https:\/\/schema.org\",\n            \"@type\": \"ImageObject\",\n            \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/successful-saga-pattern-transfer.png\",\n            \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial\",\n            \"name\": \"Successful Money Transfer Transaction\",\n            \"caption\": \"End-to-end transaction in saga pattern using Spring Boot.\",\n            \"description\": \"A completed money transfer demonstrates the effectiveness of distributed transaction handling.\",\n            \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n            \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n            \"creditText\": \"Mobisoft Infotech\",\n            \"copyrightNotice\": \"Mobisoft Infotech\",\n            \"creator\": {\n                \"@type\": \"Organization\",\n                \"name\": \"Mobisoft Infotech\"\n            },\n            \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/successful-saga-pattern-transfer.png\"\n        },\n        {\n            \"@context\": \"https:\/\/schema.org\",\n            \"@type\": \"ImageObject\",\n            \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/debit-service-receives-request.png\",\n            \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial\",\n            \"name\": \"Debit Service Receives Transaction Request\",\n            \"caption\": \"Debit microservice starts the distributed transaction flow.\",\n            \"description\": \"Start of the saga by initiating debit processing in an orchestrated service model.\",\n            \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n            \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n            \"creditText\": \"Mobisoft Infotech\",\n            \"copyrightNotice\": \"Mobisoft Infotech\",\n            \"creator\": {\n                \"@type\": \"Organization\",\n                \"name\": \"Mobisoft Infotech\"\n            },\n            \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/debit-service-receives-request.png\"\n        },\n        {\n            \"@context\": \"https:\/\/schema.org\",\n            \"@type\": \"ImageObject\",\n            \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/credit-service-process-debitcompleted.png\",\n            \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial\",\n            \"name\": \"Credit Service Consumes DebitCompleted Event\",\n            \"caption\": \"Continue the saga with credit service event processing.\",\n            \"description\": \"The credit microservice confirms funds receipt via RabbitMQ event consumption.\",\n            \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n            \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n            \"creditText\": \"Mobisoft Infotech\",\n            \"copyrightNotice\": \"Mobisoft Infotech\",\n            \"creator\": {\n                \"@type\": \"Organization\",\n                \"name\": \"Mobisoft Infotech\"\n            },\n            \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/credit-service-process-debitcompleted.png\"\n        },\n        {\n            \"@context\": \"https:\/\/schema.org\",\n            \"@type\": \"ImageObject\",\n            \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/debit-service-insufficient-funds.png\",\n            \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial\",\n            \"name\": \"Debit Service Failure \u2013 Insufficient Funds\",\n            \"caption\": \"Trigger a rollback using compensating transactions.\",\n            \"description\": \"A failure scenario initiating compensating actions in distributed systems.\",\n            \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n            \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n            \"creditText\": \"Mobisoft Infotech\",\n            \"copyrightNotice\": \"Mobisoft Infotech\",\n            \"creator\": {\n                \"@type\": \"Organization\",\n                \"name\": \"Mobisoft Infotech\"\n            },\n            \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/debit-service-insufficient-funds.png\"\n        },\n        {\n            \"@context\": \"https:\/\/schema.org\",\n            \"@type\": \"ImageObject\",\n            \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/simulated-credit-service-failure.png\",\n            \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial\",\n            \"name\": \"Credit Failure Simulation for Compensation\",\n            \"caption\": \"Validate fault-tolerance with compensation in saga pattern.\",\n            \"description\": \"Simulated failure to show how compensating transactions handle distributed failures.\",\n            \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n            \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n            \"creditText\": \"Mobisoft Infotech\",\n            \"copyrightNotice\": \"Mobisoft Infotech\",\n            \"creator\": {\n                \"@type\": \"Organization\",\n                \"name\": \"Mobisoft Infotech\"\n            },\n            \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/simulated-credit-service-failure.png\"\n        },\n        {\n            \"@context\": \"https:\/\/schema.org\",\n            \"@type\": \"ImageObject\",\n            \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/debit-service-final-state.png\",\n            \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial\",\n            \"name\": \"Final State of Debit Service Post-Transaction\",\n            \"caption\": \" Observe end-state of debit microservice in a distributed transaction.\",\n            \"description\": \"Final confirmation of debit status showcasing eventual consistency in microservices.\",\n            \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n            \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n            \"creditText\": \"Mobisoft Infotech\",\n            \"copyrightNotice\": \"Mobisoft Infotech\",\n            \"creator\": {\n                \"@type\": \"Organization\",\n                \"name\": \"Mobisoft Infotech\"\n            },\n            \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/debit-service-final-state.png\"\n        },\n        {\n            \"@context\": \"https:\/\/schema.org\",\n            \"@type\": \"ImageObject\",\n            \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/credit-service-unchanged-on-failure.png\",\n            \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial\",\n            \"name\": \"Credit Service Unchanged after Failed Transaction\",\n            \"caption\": \"Credit microservice ignores failed transfer events.\",\n            \"description\": \"Shows how idempotency prevents duplicate processing in asynchronous messaging.\",\n            \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n            \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n            \"creditText\": \"Mobisoft Infotech\",\n            \"copyrightNotice\": \"Mobisoft Infotech\",\n            \"creator\": {\n                \"@type\": \"Organization\",\n                \"name\": \"Mobisoft Infotech\"\n            },\n            \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/credit-service-unchanged-on-failure.png\"\n        },\n        {\n            \"@context\": \"https:\/\/schema.org\",\n            \"@type\": \"ImageObject\",\n            \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/rabbitmq-exchanges-queues-state.png\",\n            \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial\",\n            \"name\": \"RabbitMQ State During Saga Execution\",\n            \"caption\": \"Visualize event routing and queue status on the RabbitMQ portal.\",\n            \"description\": \"State of asynchronous message processing in RabbitMQ throughout the saga pattern.\",\n            \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n            \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n            \"creditText\": \"Mobisoft Infotech\",\n            \"copyrightNotice\": \"Mobisoft Infotech\",\n            \"creator\": {\n                \"@type\": \"Organization\",\n                \"name\": \"Mobisoft Infotech\"\n            },\n            \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/rabbitmq-exchanges-queues-state.png\"\n        }\n        ]\n    <\/script>\n","protected":false},"excerpt":{"rendered":"<p>Distributed transactions across microservices require a different approach than the traditional two phase commit (2PC). In a Spring Boot microservices architecture, where each service owns its own database and communicates over the network, 2PC becomes complex, slow, and error prone due to tight coupling and potential locking across services. To address this, the Saga pattern [&hellip;]<\/p>\n","protected":false},"author":118,"featured_media":39547,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_s2mail":"","footnotes":""},"categories":[6125],"tags":[6134,6138,6139,6130,6137,6136,6141,6140,6143,6135,6127,6128,6126,6142,6133,6132,6129,6131],"class_list":["post-39520","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-microservices","tag-asynchronous-messaging","tag-compensating-transactions","tag-distributed-systems-reliability","tag-distributed-transaction-spring-boot","tag-event-driven-architecture-spring-boot","tag-eventual-consistency","tag-fault-tolerant-microservices","tag-idempotency-in-microservices","tag-microservices-coordination","tag-rabbitmq-microservice-communication","tag-rabbitmq-saga-implementation","tag-saga-pattern-example-spring-boot","tag-saga-pattern-microservices","tag-service-orchestration-vs-choreography","tag-spring-boot-microservices-architecture","tag-spring-boot-money-transfer-microservice","tag-spring-boot-saga-pattern","tag-spring-microservices-transaction-management"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Saga Pattern with Spring Boot &amp; RabbitMQ Tutorial<\/title>\n<meta name=\"description\" content=\"A step-by-step tutorial on using the Saga Pattern in Spring Boot microservices with RabbitMQ for distributed transactions and eventual consistency.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Saga Pattern with Spring Boot &amp; RabbitMQ Tutorial\" \/>\n<meta property=\"og:description\" content=\"A step-by-step tutorial on using the Saga Pattern in Spring Boot microservices with RabbitMQ for distributed transactions and eventual consistency.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial\" \/>\n<meta property=\"og:site_name\" content=\"Mobisoft Infotech\" \/>\n<meta property=\"article:published_time\" content=\"2025-06-12T13:38:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-03-10T10:54:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/og-Saga-Pattern-Microservices-Tutorial.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"525\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Onkar Musale\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Onkar Musale\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial#article\",\"isPartOf\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial\"},\"author\":{\"name\":\"Onkar Musale\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/02c73f894b7b649dc06a120abfed5b31\"},\"headline\":\"Saga Pattern Microservices Tutorial: Using the Saga Pattern with Spring Boot &amp; RabbitMQ\",\"datePublished\":\"2025-06-12T13:38:22+00:00\",\"dateModified\":\"2026-03-10T10:54:31+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial\"},\"wordCount\":1582,\"image\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial#primaryimage\"},\"thumbnailUrl\":\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/saga-pattern-spring-boot-rabbitmq-tutorial.png\",\"keywords\":[\"asynchronous messaging\",\"compensating transactions\",\"distributed systems reliability\",\"distributed transaction spring boot\",\"event driven architecture spring boot\",\"eventual consistency\",\"fault-tolerant microservices\",\"idempotency in microservices\",\"microservices coordination\",\"rabbitmq microservice communication\",\"rabbitmq saga implementation\",\"saga pattern example spring boot\",\"saga pattern microservices\",\"service orchestration vs choreography\",\"spring boot microservices architecture\",\"spring boot money transfer microservice\",\"spring boot saga pattern\",\"spring microservices transaction management\"],\"articleSection\":[\"Microservices\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial\",\"url\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial\",\"name\":\"Saga Pattern with Spring Boot & RabbitMQ Tutorial\",\"isPartOf\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial#primaryimage\"},\"image\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial#primaryimage\"},\"thumbnailUrl\":\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/saga-pattern-spring-boot-rabbitmq-tutorial.png\",\"datePublished\":\"2025-06-12T13:38:22+00:00\",\"dateModified\":\"2026-03-10T10:54:31+00:00\",\"author\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/02c73f894b7b649dc06a120abfed5b31\"},\"description\":\"A step-by-step tutorial on using the Saga Pattern in Spring Boot microservices with RabbitMQ for distributed transactions and eventual consistency.\",\"breadcrumb\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial#primaryimage\",\"url\":\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/saga-pattern-spring-boot-rabbitmq-tutorial.png\",\"contentUrl\":\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/saga-pattern-spring-boot-rabbitmq-tutorial.png\",\"width\":855,\"height\":392,\"caption\":\"Tutorial on Saga Pattern using Spring Boot and RabbitMQ.\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/mobisoftinfotech.com\/resources\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Saga Pattern Microservices Tutorial: Using the Saga Pattern with Spring Boot &amp; RabbitMQ\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/#website\",\"url\":\"https:\/\/mobisoftinfotech.com\/resources\/\",\"name\":\"Mobisoft Infotech\",\"description\":\"Discover Mobility\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/mobisoftinfotech.com\/resources\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/02c73f894b7b649dc06a120abfed5b31\",\"name\":\"Onkar Musale\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/fc3a16b43b77d87a7aac74de086cfd8dbe14021bd573ac71d1ae4f22e9b6bbd3?s=96&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/fc3a16b43b77d87a7aac74de086cfd8dbe14021bd573ac71d1ae4f22e9b6bbd3?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/fc3a16b43b77d87a7aac74de086cfd8dbe14021bd573ac71d1ae4f22e9b6bbd3?s=96&r=g\",\"caption\":\"Onkar Musale\"},\"sameAs\":[\"https:\/\/mobisoftinfotech.com\/\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Saga Pattern with Spring Boot & RabbitMQ Tutorial","description":"A step-by-step tutorial on using the Saga Pattern in Spring Boot microservices with RabbitMQ for distributed transactions and eventual consistency.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial","og_locale":"en_US","og_type":"article","og_title":"Saga Pattern with Spring Boot & RabbitMQ Tutorial","og_description":"A step-by-step tutorial on using the Saga Pattern in Spring Boot microservices with RabbitMQ for distributed transactions and eventual consistency.","og_url":"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial","og_site_name":"Mobisoft Infotech","article_published_time":"2025-06-12T13:38:22+00:00","article_modified_time":"2026-03-10T10:54:31+00:00","og_image":[{"width":1000,"height":525,"url":"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/og-Saga-Pattern-Microservices-Tutorial.png","type":"image\/png"}],"author":"Onkar Musale","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Onkar Musale","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial#article","isPartOf":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial"},"author":{"name":"Onkar Musale","@id":"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/02c73f894b7b649dc06a120abfed5b31"},"headline":"Saga Pattern Microservices Tutorial: Using the Saga Pattern with Spring Boot &amp; RabbitMQ","datePublished":"2025-06-12T13:38:22+00:00","dateModified":"2026-03-10T10:54:31+00:00","mainEntityOfPage":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial"},"wordCount":1582,"image":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial#primaryimage"},"thumbnailUrl":"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/saga-pattern-spring-boot-rabbitmq-tutorial.png","keywords":["asynchronous messaging","compensating transactions","distributed systems reliability","distributed transaction spring boot","event driven architecture spring boot","eventual consistency","fault-tolerant microservices","idempotency in microservices","microservices coordination","rabbitmq microservice communication","rabbitmq saga implementation","saga pattern example spring boot","saga pattern microservices","service orchestration vs choreography","spring boot microservices architecture","spring boot money transfer microservice","spring boot saga pattern","spring microservices transaction management"],"articleSection":["Microservices"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial","url":"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial","name":"Saga Pattern with Spring Boot & RabbitMQ Tutorial","isPartOf":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/#website"},"primaryImageOfPage":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial#primaryimage"},"image":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial#primaryimage"},"thumbnailUrl":"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/saga-pattern-spring-boot-rabbitmq-tutorial.png","datePublished":"2025-06-12T13:38:22+00:00","dateModified":"2026-03-10T10:54:31+00:00","author":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/02c73f894b7b649dc06a120abfed5b31"},"description":"A step-by-step tutorial on using the Saga Pattern in Spring Boot microservices with RabbitMQ for distributed transactions and eventual consistency.","breadcrumb":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial#primaryimage","url":"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/saga-pattern-spring-boot-rabbitmq-tutorial.png","contentUrl":"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/06\/saga-pattern-spring-boot-rabbitmq-tutorial.png","width":855,"height":392,"caption":"Tutorial on Saga Pattern using Spring Boot and RabbitMQ."},{"@type":"BreadcrumbList","@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/microservices\/saga-pattern-spring-boot-rabbitmq-tutorial#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/mobisoftinfotech.com\/resources\/"},{"@type":"ListItem","position":2,"name":"Saga Pattern Microservices Tutorial: Using the Saga Pattern with Spring Boot &amp; RabbitMQ"}]},{"@type":"WebSite","@id":"https:\/\/mobisoftinfotech.com\/resources\/#website","url":"https:\/\/mobisoftinfotech.com\/resources\/","name":"Mobisoft Infotech","description":"Discover Mobility","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/mobisoftinfotech.com\/resources\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/02c73f894b7b649dc06a120abfed5b31","name":"Onkar Musale","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/fc3a16b43b77d87a7aac74de086cfd8dbe14021bd573ac71d1ae4f22e9b6bbd3?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/fc3a16b43b77d87a7aac74de086cfd8dbe14021bd573ac71d1ae4f22e9b6bbd3?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/fc3a16b43b77d87a7aac74de086cfd8dbe14021bd573ac71d1ae4f22e9b6bbd3?s=96&r=g","caption":"Onkar Musale"},"sameAs":["https:\/\/mobisoftinfotech.com\/"]}]}},"_links":{"self":[{"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/posts\/39520","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/users\/118"}],"replies":[{"embeddable":true,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/comments?post=39520"}],"version-history":[{"count":25,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/posts\/39520\/revisions"}],"predecessor-version":[{"id":47447,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/posts\/39520\/revisions\/47447"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/media\/39547"}],"wp:attachment":[{"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/media?parent=39520"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/categories?post=39520"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/tags?post=39520"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}