{"id":2079,"date":"2026-01-31T02:12:38","date_gmt":"2026-01-30T13:12:38","guid":{"rendered":"https:\/\/www.ronella.xyz\/?p=2079"},"modified":"2026-01-31T02:12:38","modified_gmt":"2026-01-30T13:12:38","slug":"apache-camel-seda","status":"publish","type":"post","link":"https:\/\/www.ronella.xyz\/?p=2079","title":{"rendered":"Apache Camel SEDA"},"content":{"rendered":"<p>Apache Camel SEDA implements the Staged Event-Driven Architecture pattern, enabling in-VM asynchronous messaging that decouples producers from consumers via BlockingQueue. This excels in high-load scenarios where synchronous endpoints like Direct would block threads\u2014SEDA queues messages instead, boosting scalability with configurable concurrent consumers.<\/p>\n<h2>Core Advantages<\/h2>\n<ul>\n<li><strong>Non-blocking Producers<\/strong>: Senders complete instantly while slow consumers process from the queue, preventing cascade failures.<\/li>\n<li><strong>Thread Pool Efficiency<\/strong>: Multiple consumers (<code>concurrentConsumers=3<\/code>) parallelize work without manual thread management.<\/li>\n<li><strong>Configurable Resilience<\/strong>: Options like <code>queueSize<\/code>, <code>discardWhenFull<\/code>, and <code>offerTimeout<\/code> handle overload gracefully.<\/li>\n<\/ul>\n<h2>Example<\/h2>\n<p>This standalone app uses Camel Main (Camel 4.x) with a custom <code>ExchangeFormatter<\/code> to visualize thread names, exchange IDs, and route context\u2014clearly demonstrating SEDA's parallel consumer threads. Producers fire 5 messages rapidly (100ms intervals) into SEDA, while consumers lag with 1s delays; logs reveal immediate sends followed by staggered, multi-threaded processing.<\/p>\n<pre><code class=\"language-java\">import org.apache.camel.builder.RouteBuilder;\nimport org.apache.camel.spi.ExchangeFormatter;\n\n\/**\n * Apache Camel example demonstrating SEDA (Staged Event-Driven Architecture) pattern.\n * Shows asynchronous message processing with concurrent consumers and queuing.\n *\/\npublic class SedaExample {\n\n    static void main(String[] args) throws Exception {\n        \/\/ Create a new Camel Main instance (using fully qualified name to avoid conflict)\n        org.apache.camel.main.Main main = new org.apache.camel.main.Main();\n\n        \/\/ Add routes with SEDA processing\n        main.configure().addRoutesBuilder(new RouteBuilder() {\n            @Override\n            public void configure() {\n                \/\/ Create a custom ExchangeFormatter for detailed log output\n                ExchangeFormatter customFormatter = exchange -&gt;\n                        String.format(&quot;[Thread: %s] Body: %s | ExchangeId: %s | RouteId: %s&quot;,\n                                Thread.currentThread().getName(),\n                                exchange.getIn().getBody(String.class),\n                                exchange.getExchangeId(),\n                                exchange.getFromRouteId());\n\n                \/\/ Register the custom formatter in the Camel registry\n                getContext().getRegistry().bind(&quot;customFormatter&quot;, customFormatter);\n\n                \/\/ SEDA endpoint: queueId=myQueue, concurrent consumers for parallelism\n                from(&quot;seda:myQueue?concurrentConsumers=3&quot;)\n                    .log(&quot;Processing: ${body}&quot;)\n                    .delay(1000)  \/\/ Simulate slow consumer (1s delay)\n                    .to(&quot;log:output?showAll=true&amp;exchangeFormatter=#customFormatter&quot;);\n\n                \/\/ Producer route for demo\n                from(&quot;timer:tick?repeatCount=5&amp;delay=100&quot;)  \/\/ Fire 5 msgs quickly\n                    .setBody().simple(&quot;Msg ${exchangeId}&quot;)\n                    .log(&quot;Sending: ${body}&quot;)\n                    .to(&quot;seda:myQueue&quot;);\n            }\n        });\n\n        \/\/ Run Camel (will run until Ctrl+C is pressed)\n        main.run(args);\n    }\n}<\/code><\/pre>\n<h2>Running and Verification<\/h2>\n<p>Compile and run the Java class directly (requires Camel 4.14.0 on classpath). Sample output shows the advantage:<\/p>\n<pre><code>Sending: Msg 1CB44DE50955685-0000000000000000     \/\/ Producer thread - instant\nSending: Msg 1CB44DE50955685-0000000000000001     \/\/ Producer continues rapidly\noutput - [Thread: Camel (camel-1) thread #6 - Delay] Body: Msg 1CB44DE50955685-0000000000000000 | ExchangeId: 1CB44DE50955685-0000000000000002 | RouteId: route1\noutput - [Thread: Camel (camel-1) thread #7 - Delay] Body: Msg 1CB44DE50955685-0000000000000001 | ExchangeId: 1CB44DE50955685-0000000000000004 | RouteId: route1  \/\/ Parallel consumers<\/code><\/pre>\n<p>Contrast with <code>direct:myQueue<\/code>: sends block behind delays on single thread. SEDA's queue absorbs bursts across threads, perfect for enterprise workloads like order processing.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Apache Camel SEDA implements the Staged Event-Driven Architecture pattern, enabling in-VM asynchronous messaging that decouples producers from consumers via BlockingQueue. This excels in high-load scenarios where synchronous endpoints like Direct would block threads\u2014SEDA queues messages instead, boosting scalability with configurable concurrent consumers. Core Advantages Non-blocking Producers: Senders complete instantly while slow consumers process from the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[92],"tags":[],"_links":{"self":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/2079"}],"collection":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2079"}],"version-history":[{"count":1,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/2079\/revisions"}],"predecessor-version":[{"id":2080,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/2079\/revisions\/2080"}],"wp:attachment":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2079"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2079"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2079"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}