<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vipin Vinod Kumar on Medium]]></title>
        <description><![CDATA[Stories by Vipin Vinod Kumar on Medium]]></description>
        <link>https://medium.com/@vipinvec?source=rss-f7a23b36ec0b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*DBDKHRXzt0Mp6OG6</url>
            <title>Stories by Vipin Vinod Kumar on Medium</title>
            <link>https://medium.com/@vipinvec?source=rss-f7a23b36ec0b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 12:00:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vipinvec/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building a Microservice Pipeline with Apache Camel and Spring Boot]]></title>
            <link>https://medium.com/@vipinvec/building-a-microservice-pipeline-with-apache-camel-and-spring-boot-4d494cfd042a?source=rss-f7a23b36ec0b------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d494cfd042a</guid>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[pipeline-architecture]]></category>
            <category><![CDATA[apache-camel]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Vipin Vinod Kumar]]></dc:creator>
            <pubDate>Sun, 18 May 2025 16:22:07 GMT</pubDate>
            <atom:updated>2025-05-18T16:22:07.244Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XpRvRyNIM3KPXxPjxRTt6A.png" /></figure><p>In modern microservice architectures, services often need to perform multiple sequential tasks — like validating input, transforming data, integrating with third-party systems, and persisting results. Managing this kind of <strong>orchestration logic</strong> can easily get messy if not structured cleanly.</p><p>To address this, I implemented a <strong>pipeline architecture</strong> using <strong>Apache Camel</strong> within a <strong>Spring Boot microservice</strong>, where each flow is a Camel route, and each stage in the flow is handled by a dedicated processor. This approach brings modularity, clarity, and flexibility to the microservice’s internal processing logic.</p><p>In this post, I’ll walk through how I built this using a <strong>concrete example</strong>: processing loan applications and integrating with a <strong>third-party credit score provider</strong> using REST APIs.</p><h3>Why Apache Camel?</h3><p>Apache Camel is an open-source integration framework that excels at routing and mediation. It supports over 300 components (REST, file, JMS, etc.), and makes implementing <strong>Enterprise Integration Patterns (EIP)</strong> easy and expressive.</p><p>Key reasons I chose Apache Camel:</p><ul><li><strong>DSL-based route configuration</strong> (Java or XML)</li><li>Clean separation of concerns</li><li>Easy integration with Spring Boot</li><li>Built-in error handling, retries, and monitoring</li></ul><h3>Use Case: Loan Application Processing</h3><p>Imagine a loan processing microservice that needs to:</p><ol><li>Validate incoming loan applications.</li><li>Enrich the data (e.g., normalize applicant name/address).</li><li>Call a third-party API to fetch the applicant’s credit score.</li><li>Analyze the score to make a loan decision.</li><li>Store or forward the result.</li></ol><p>Each of these steps is implemented as a <strong>Camel processor</strong>, and the entire flow is defined as a <strong>Camel route</strong>.</p><h3>Tech Stack</h3><ul><li><strong>Java 17</strong></li><li><strong>Spring Boot 3</strong></li><li><strong>Apache Camel 4</strong></li><li><strong>REST API integration</strong></li><li><strong>Maven</strong></li></ul><h3>Project Setup</h3><p>Add the following dependencies to your pom.xml:</p><pre>&lt;dependencies&gt;<br>    &lt;dependency&gt;<br>        &lt;groupId&gt;org.apache.camel.springboot&lt;/groupId&gt;<br>        &lt;artifactId&gt;camel-spring-boot-starter&lt;/artifactId&gt;<br>    &lt;/dependency&gt;<br>    &lt;dependency&gt;<br>        &lt;groupId&gt;org.apache.camel.springboot&lt;/groupId&gt;<br>        &lt;artifactId&gt;camel-http-starter&lt;/artifactId&gt;<br>    &lt;/dependency&gt;<br>&lt;/dependencies&gt;</pre><h3>Defining the Pipeline Route</h3><p>Each flow is implemented as a <strong>Camel route</strong>, and each processing step is a <strong>Camel </strong><strong>Processor</strong>:</p><pre>@Component<br>public class LoanApplicationFlowRoute extends RouteBuilder {<br><br>    @Override<br>    public void configure() {<br><br>        from(&quot;direct:loan-application-flow&quot;)<br>            .routeId(&quot;loanApplicationFlow&quot;)<br>            .log(&quot;Received loan application: ${body}&quot;)<br>            .process(new LoanValidationProcessor())<br>            .process(new DataEnrichmentProcessor())<br>            .process(new CreditScoreCallProcessor())<br>            .process(new CreditScoreResponseProcessor())<br>            .process(new LoanDecisionProcessor())<br>            .log(&quot;Loan application processing completed.&quot;);<br>    }<br>}</pre><h3>Step-by-Step Processor Implementation</h3><p>Each processor performs a single step in the pipeline. Here are some examples:</p><p>1. <strong>LoanValidationProcessor</strong></p><pre>public class LoanValidationProcessor implements Processor {<br>    @Override<br>    public void process(Exchange exchange) {<br>        Map&lt;String, Object&gt; body = exchange.getIn().getBody(Map.class);<br>        if (!body.containsKey(&quot;applicantId&quot;) || !body.containsKey(&quot;loanAmount&quot;)) {<br>            throw new IllegalArgumentException(&quot;Missing required fields&quot;);<br>        }<br>    }<br>}</pre><p>2. <strong>DataEnrichmentProcessor</strong></p><pre>public class DataEnrichmentProcessor implements Processor {<br>    @Override<br>    public void process(Exchange exchange) {<br>        Map&lt;String, Object&gt; body = exchange.getIn().getBody(Map.class);<br>        body.put(&quot;normalizedName&quot;, ((String) body.get(&quot;name&quot;)).trim().toUpperCase());<br>        exchange.getIn().setBody(body);<br>    }@Component<br>public class CreditScoreCallProcessor implements Processor {<br><br>    @Autowired<br>    private RestTemplate restTemplate;<br><br>    @Override<br>    public void process(Exchange exchange) {<br>        Map&lt;String, Object&gt; body = exchange.getIn().getBody(Map.class);<br>        String applicantId = (String) body.get(&quot;applicantId&quot;);<br><br>        ResponseEntity&lt;Map&gt; response = restTemplate.getForEntity(<br>                &quot;http://credit-score-provider/api/score?applicantId=&quot; + applicantId, Map.class);<br><br>        body.put(&quot;creditScoreResponse&quot;, response.getBody());<br>        exchange.getIn().setBody(body);<br>    }<br>}<br>}</pre><p>3. <strong>CreditScoreCallProcessor</strong></p><pre>@Component<br>public class CreditScoreCallProcessor implements Processor {<br><br>    @Autowired<br>    private RestTemplate restTemplate;<br><br>    @Override<br>    public void process(Exchange exchange) {<br>        Map&lt;String, Object&gt; body = exchange.getIn().getBody(Map.class);<br>        String applicantId = (String) body.get(&quot;applicantId&quot;);<br><br>        ResponseEntity&lt;Map&gt; response = restTemplate.getForEntity(<br>                &quot;http://credit-score-provider/api/score?applicantId=&quot; + applicantId, Map.class);<br><br>        body.put(&quot;creditScoreResponse&quot;, response.getBody());<br>        exchange.getIn().setBody(body);<br>    }<br>}</pre><p>4. <strong>CreditScoreResponseProcessor</strong></p><pre>public class CreditScoreResponseProcessor implements Processor {<br>    @Override<br>    public void process(Exchange exchange) {<br>        Map&lt;String, Object&gt; body = exchange.getIn().getBody(Map.class);<br>        Map&lt;String, Object&gt; response = (Map&lt;String, Object&gt;) body.get(&quot;creditScoreResponse&quot;);<br><br>        int score = (int) response.getOrDefault(&quot;score&quot;, 0);<br>        body.put(&quot;creditScore&quot;, score);<br>    }<br>}</pre><p>5. <strong>LoanDecisionProcessor</strong></p><pre>public class LoanDecisionProcessor implements Processor {<br>    @Override<br>    public void process(Exchange exchange) {<br>        Map&lt;String, Object&gt; body = exchange.getIn().getBody(Map.class);<br>        int score = (int) body.get(&quot;creditScore&quot;);<br><br>        String decision = score &gt;= 700 ? &quot;APPROVED&quot; : &quot;REJECTED&quot;;<br>        body.put(&quot;decision&quot;, decision);<br><br>        // Simulate persistence<br>        System.out.println(&quot;Storing loan decision: &quot; + body);<br>    }<br>}</pre><p><strong>Exposing the Flow via REST</strong></p><p>We use a Spring Boot controller to trigger the Camel route:</p><pre>@RestController<br>@RequestMapping(&quot;/loans&quot;)<br>public class LoanController {<br><br>    @Autowired<br>    private ProducerTemplate producerTemplate;<br><br>    @PostMapping(&quot;/apply&quot;)<br>    public ResponseEntity&lt;String&gt; applyForLoan(@RequestBody Map&lt;String, Object&gt; loanRequest) {<br>        producerTemplate.sendBody(&quot;direct:loan-application-flow&quot;, loanRequest);<br>        return ResponseEntity.ok(&quot;Loan application is being processed.&quot;);<br>    }<br>}</pre><h3>Benefits of This Architecture</h3><ul><li><strong>Modular</strong>: Each stage is isolated and reusable.</li><li><strong>Maintainable</strong>: Easy to change a step or insert a new one.</li><li><strong>Testable</strong>: Processors can be unit tested independently.</li><li><strong>Scalable</strong>: Routes can be extended for multiple types of flows.</li><li><strong>Observable</strong>: Logging at each stage enables step-by-step monitoring.</li></ul><h3>Final Thoughts</h3><p>Apache Camel is an excellent fit when your microservice requires sequential processing, especially when integrating with external systems. By structuring your pipeline with Camel routes and processors, you gain clarity, flexibility, and maintainability — all without bloating your service logic.</p><p>This approach has worked well in production, handling real-time integrations with minimal latency and high reliability.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d494cfd042a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>