<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.8.3">Jekyll</generator><link href="https://citrusframework.org/feed.xml" rel="self" type="application/atom+xml" /><link href="https://citrusframework.org/" rel="alternate" type="text/html" /><updated>2026-11-30T15:37:27+01:00</updated><id>https://citrusframework.org/feed.xml</id><title type="html">Citrus Integration Tests</title><subtitle>Automated integration tests for message protocols and data formats that you require</subtitle><entry><title type="html">Citrus 5.2.1</title><link href="https://citrusframework.org/news/2026/11/30/release-5.2.1/" rel="alternate" type="text/html" title="Citrus 5.2.1" /><published>2026-11-30T00:00:00+01:00</published><updated>2026-11-30T00:00:00+01:00</updated><id>https://citrusframework.org/news/2026/11/30/release-5.2.1</id><content type="html" xml:base="https://citrusframework.org/news/2026/11/30/release-5.2.1/">&lt;p&gt;The Citrus community is happy to announce the release of &lt;strong&gt;Citrus 5.2.1&lt;/strong&gt;!
This patch release delivers a broad set of new features alongside important stability and correctness fixes.&lt;/p&gt;

&lt;p&gt;The release contains &lt;strong&gt;18 new features and enhancements&lt;/strong&gt;, &lt;strong&gt;24 bug fixes&lt;/strong&gt; and several &lt;strong&gt;dependency and migration updates&lt;/strong&gt;.
Here is a look at the highlights.&lt;/p&gt;

&lt;h2 id=&quot;spring-boot-test-starter&quot;&gt;Spring Boot test starter&lt;/h2&gt;

&lt;p&gt;A new &lt;code class=&quot;highlighter-rouge&quot;&gt;citrus-spring-boot-test-starter&lt;/code&gt; module makes it easier than ever to bootstrap Citrus tests in Spring Boot projects (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1943&quot;&gt;#1943&lt;/a&gt;). Just add the starter dependency and Spring Boot auto-configuration takes care of wiring up the Citrus context, endpoints and test infrastructure — no manual bean definitions required.&lt;/p&gt;

&lt;h2 id=&quot;modern-junit-jupiter-test-generation&quot;&gt;Modern JUnit Jupiter test generation&lt;/h2&gt;

&lt;p&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;citrus init&lt;/code&gt; command now generates &lt;strong&gt;JUnit Jupiter&lt;/strong&gt; test classes by default (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/2004&quot;&gt;#2004&lt;/a&gt;). Previously generated tests used the older JUnit 4 style. New projects start with idiomatic JUnit 5 code out of the box, and the init command also fails early when the target file already exists (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/2043&quot;&gt;#2043&lt;/a&gt;) to prevent accidental overwrites.&lt;/p&gt;

&lt;h2 id=&quot;xslt-based-spring-xml-migration-tool&quot;&gt;XSLT-based Spring XML migration tool&lt;/h2&gt;

&lt;p&gt;A new XSLT-based migration tool converts legacy Spring bean XML tests to the native Citrus XML DSL (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/2047&quot;&gt;#2047&lt;/a&gt;). This tool is also available through the Citrus MCP server (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/2121&quot;&gt;#2121&lt;/a&gt;), making it easy to integrate into AI-assisted migration workflows.&lt;/p&gt;

&lt;h2 id=&quot;extended-yamlxml-dsl-coverage&quot;&gt;Extended YAML/XML DSL coverage&lt;/h2&gt;

&lt;p&gt;Citrus 5.2.1 continues to close the gap between the Java DSL and the YAML/XML DSL with support for several additional transports and actions:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Docker actions&lt;/strong&gt; — build, start, stop and inspect containers directly from YAML and XML tests (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/2045&quot;&gt;#2045&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kubernetes actions&lt;/strong&gt; — delete pods and execute commands on running containers (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/2048&quot;&gt;#2048&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Zookeeper actions&lt;/strong&gt; — create, get, set and delete znodes from YAML and XML tests&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;FTP, SFTP, RMI and Hamcrest&lt;/strong&gt; — full YAML/XML support for FTP/SFTP transfers, RMI invocations and Hamcrest matchers (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/2058&quot;&gt;#2058&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Server port and URL as test variables&lt;/strong&gt; — dynamically allocated server ports and URLs are now automatically exposed as test variables in the YAML DSL (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/2115&quot;&gt;#2115&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;playwright-enhancements&quot;&gt;Playwright enhancements&lt;/h2&gt;

&lt;p&gt;The Playwright browser testing module gains several new capabilities:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Ref locators, &lt;code class=&quot;highlighter-rouge&quot;&gt;within&lt;/code&gt; scoping and AI ARIA snapshots&lt;/strong&gt; — locate elements by ref attribute, scope actions within a parent element, and capture accessibility snapshots for AI-driven test generation (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/2074&quot;&gt;#2074&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Screencast options, WebAuthn &lt;code class=&quot;highlighter-rouge&quot;&gt;signCount&lt;/code&gt; and shadow DOM page-source&lt;/strong&gt; — record screencasts during test execution, configure WebAuthn authenticator counters, and extract page source from shadow DOM elements (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/2079&quot;&gt;#2079&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;cli-improvements&quot;&gt;CLI improvements&lt;/h2&gt;

&lt;p&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;citrus run&lt;/code&gt; command gains a new &lt;code class=&quot;highlighter-rouge&quot;&gt;--clear&lt;/code&gt; option to explicitly clean the work directory, while the default behavior now preserves it between runs (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/2044&quot;&gt;#2044&lt;/a&gt;). This makes it easier to inspect intermediate outputs and debug test failures.&lt;/p&gt;

&lt;h2 id=&quot;ai-and-tooling-support&quot;&gt;AI and tooling support&lt;/h2&gt;

&lt;p&gt;YAML schemas and action catalogs are now structured so that AI agents and MCP-compatible tools can discover and navigate them automatically (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/2119&quot;&gt;#2119&lt;/a&gt;). Combined with the Spring XML migration tool exposed through the MCP server, this makes Citrus a first-class citizen in AI-assisted testing workflows.&lt;/p&gt;

&lt;h2 id=&quot;notable-fixes&quot;&gt;Notable fixes&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Thread safety&lt;/strong&gt; — &lt;code class=&quot;highlighter-rouge&quot;&gt;TestFlowReporter&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;JBangSupport.trust&lt;/code&gt; are now safe for concurrent test execution (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1999&quot;&gt;#1999&lt;/a&gt;, &lt;a href=&quot;https://github.com/citrusframework/citrus/issues/2011&quot;&gt;#2011&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Parameterized tests&lt;/strong&gt; — remaining invocations continue to run after a failure, and parameterized arguments are correctly passed to file-based tests (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/2024&quot;&gt;#2024&lt;/a&gt;, &lt;a href=&quot;https://github.com/citrusframework/citrus/issues/2041&quot;&gt;#2041&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test variable resolution in endpoints&lt;/strong&gt; — endpoint initialization now resolves test variables, enabling dynamic endpoint configuration (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/2077&quot;&gt;#2077&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Error reporting&lt;/strong&gt; — improved error messages for operators and unknown variables (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/2118&quot;&gt;#2118&lt;/a&gt;), validation of unbalanced function calls (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/2039&quot;&gt;#2039&lt;/a&gt;, &lt;a href=&quot;https://github.com/citrusframework/citrus/issues/2100&quot;&gt;#2100&lt;/a&gt;), and rejection of multiple operations in a single HTTP action (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/2108&quot;&gt;#2108&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Finally block reliability&lt;/strong&gt; — the original test failure is preserved when finally actions also fail (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/2112&quot;&gt;#2112&lt;/a&gt;), and the reference resolver is properly injected into finally block action builders (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/2087&quot;&gt;#2087&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;migration-updates&quot;&gt;Migration updates&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Citrus test suite migrated from TestNG to JUnit Jupiter (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1873&quot;&gt;#1873&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;Spring bean XML integration tests migrated to plain XML DSL (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/2123&quot;&gt;#2123&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;Deprecated Cucumber and Kafka APIs replaced (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/2106&quot;&gt;#2106&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;Playwright module aligned with Playwright 1.65 semantics (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/2022&quot;&gt;#2022&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For the full list of changes see the &lt;a href=&quot;/docs/history/#v5.2.1&quot;&gt;release changelog&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;update&quot;&gt;Update&lt;/h2&gt;

&lt;p&gt;Update the Citrus BOM in your &lt;code class=&quot;highlighter-rouge&quot;&gt;pom.xml&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.citrusframework&lt;span class=&quot;nt&quot;&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;citrus-bom&lt;span class=&quot;nt&quot;&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;version&amp;gt;&lt;/span&gt;5.2.1&lt;span class=&quot;nt&quot;&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;type&amp;gt;&lt;/span&gt;pom&lt;span class=&quot;nt&quot;&gt;&amp;lt;/type&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;scope&amp;gt;&lt;/span&gt;import&lt;span class=&quot;nt&quot;&gt;&amp;lt;/scope&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Thank you to everyone who contributed to this release!&lt;/p&gt;</content><author><name>Christoph Deppisch</name></author></entry><entry><title type="html">Citrus 5.2.0</title><link href="https://citrusframework.org/news/2026/11/16/release-5.2.0/" rel="alternate" type="text/html" title="Citrus 5.2.0" /><published>2026-11-16T00:00:00+01:00</published><updated>2026-11-16T00:00:00+01:00</updated><id>https://citrusframework.org/news/2026/11/16/release-5.2.0</id><content type="html" xml:base="https://citrusframework.org/news/2026/11/16/release-5.2.0/">&lt;p&gt;The Citrus community is happy to announce the release of &lt;strong&gt;Citrus 5.2.0&lt;/strong&gt;!
This release brings significant improvements to the Cucumber integration, the JBang CLI, test reporting and YAML/XML DSL completeness.&lt;/p&gt;

&lt;p&gt;The release contains &lt;strong&gt;22 new features and enhancements&lt;/strong&gt;, &lt;strong&gt;13 bug fixes&lt;/strong&gt; and several &lt;strong&gt;dependency and migration updates&lt;/strong&gt;.
Here is a look at the highlights.&lt;/p&gt;

&lt;h2 id=&quot;java-21-required&quot;&gt;Java 21 required&lt;/h2&gt;

&lt;p&gt;As announced with the 5.1.0 release, Citrus 5.2.0 &lt;strong&gt;requires Java 21&lt;/strong&gt; as the minimum version. Java 17 is no longer supported. If you have not migrated yet, please update your runtime before upgrading to Citrus 5.2.0.&lt;/p&gt;

&lt;h2 id=&quot;jbang-cli-ported-to-aesh&quot;&gt;JBang CLI ported to Aesh&lt;/h2&gt;

&lt;p&gt;The Citrus JBang CLI has been ported from Picocli to &lt;a href=&quot;https://github.com/aeshell/aesh&quot;&gt;Aesh&lt;/a&gt; (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1574&quot;&gt;#1574&lt;/a&gt;), the same command-line framework used by Apache Camel and Quarkus. Aesh provides interactive shell capabilities, command completion and a consistent user experience across the Camel ecosystem. If you use the Citrus JBang commands, the switch is transparent — all existing commands continue to work, and you benefit from improved tab completion and interactive mode support.&lt;/p&gt;

&lt;h2 id=&quot;cucumber-8-improvements&quot;&gt;Cucumber 8 improvements&lt;/h2&gt;

&lt;p&gt;Citrus 5.2.0 brings a substantial overhaul of the Cucumber integration:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Suite hooks, DocString/DataTable steps and parallel scenarios&lt;/strong&gt; — Cucumber tests can now use &lt;code class=&quot;highlighter-rouge&quot;&gt;@BeforeAll&lt;/code&gt;/&lt;code class=&quot;highlighter-rouge&quot;&gt;@AfterAll&lt;/code&gt; suite hooks, DocString and DataTable step definitions, and run scenarios in parallel (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1889&quot;&gt;#1889&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Glue selection, package-private glue and named hooks&lt;/strong&gt; — leverages Cucumber 8’s improved glue class scanning, supports package-private step definitions, and enables named hooks for better traceability (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1874&quot;&gt;#1874&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;JUnit Platform engine migration&lt;/strong&gt; — the Cucumber runtime and all cucumber-steps modules have been migrated from the legacy runner to the JUnit Platform engine, aligning with modern JUnit 5 test execution (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1858&quot;&gt;#1858&lt;/a&gt;, &lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1860&quot;&gt;#1860&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;complete-http-yamlxml-dsl-parity&quot;&gt;Complete HTTP YAML/XML DSL parity&lt;/h2&gt;

&lt;p&gt;The HTTP module now has full DSL parity across Java, YAML and XML (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1919&quot;&gt;#1919&lt;/a&gt;). Every HTTP test action that was previously only available in the Java DSL can now be expressed in YAML and XML as well. This is part of a broader effort to ensure that all Citrus capabilities are available in every DSL flavor.&lt;/p&gt;

&lt;h2 id=&quot;simplified-messaging-endpoint-definitions&quot;&gt;Simplified messaging endpoint definitions&lt;/h2&gt;

&lt;p&gt;Messaging endpoint definitions in YAML and XML have been streamlined (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1888&quot;&gt;#1888&lt;/a&gt;). The new simplified syntax reduces boilerplate when declaring endpoints, making test definitions cleaner and easier to read.&lt;/p&gt;

&lt;h2 id=&quot;test-reporting-improvements&quot;&gt;Test reporting improvements&lt;/h2&gt;

&lt;p&gt;Test reporting has been enhanced in several areas:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Nested action reporting&lt;/strong&gt; — test action containers now report the execution of their nested actions, giving better visibility into what happens inside iterating, conditional and parallel containers (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1938&quot;&gt;#1938&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Container lifecycle callbacks&lt;/strong&gt; — a new container listener allows hooking into lifecycle events of action containers for custom reporting or monitoring (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1936&quot;&gt;#1936&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dedicated finally section&lt;/strong&gt; — final (cleanup) actions are now reported in their own section, clearly separated from the main test flow (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1851&quot;&gt;#1851&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Skipped tests in JUnit XML&lt;/strong&gt; — the JUnit XML report now correctly includes skipped tests, improving compatibility with CI dashboards and test aggregation tools (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1319&quot;&gt;#1319&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;yamlxml-dsl-and-catalog-improvements&quot;&gt;YAML/XML DSL and catalog improvements&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Catalog metadata and unknown action rejection&lt;/strong&gt; — the YAML action catalog now carries rich metadata descriptions and rejects unknown action names with helpful error messages instead of silently ignoring them (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1918&quot;&gt;#1918&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Colon-delimited action names&lt;/strong&gt; — schema aggregate catalogs now use colon delimiters for test action names, providing a cleaner namespace hierarchy (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1850&quot;&gt;#1850&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test variable metadata in schemas&lt;/strong&gt; — &lt;code class=&quot;highlighter-rouge&quot;&gt;@SchemaType&lt;/code&gt; annotations now include test variable metadata, and the generated JSON schemas carry this information for tooling support (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1973&quot;&gt;#1973&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Minified JSON schemas&lt;/strong&gt; — generated JSON schema files are now minified, reducing artifact size (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1981&quot;&gt;#1981&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Endpoint dependency detection&lt;/strong&gt; — Citrus now detects endpoint dependencies from &lt;code class=&quot;highlighter-rouge&quot;&gt;createEndpoint&lt;/code&gt; test actions, improving dependency tracking and validation (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1852&quot;&gt;#1852&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;camel-integration-improvements&quot;&gt;Camel integration improvements&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Verify running integrations by name&lt;/strong&gt; — the Camel verify action can now find already-running Camel integrations by name, useful when testing against long-lived integration routes (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1970&quot;&gt;#1970&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Skip plugins option&lt;/strong&gt; — &lt;code class=&quot;highlighter-rouge&quot;&gt;CamelRunIntegrationAction&lt;/code&gt; supports a new &lt;code class=&quot;highlighter-rouge&quot;&gt;--skip-plugins&lt;/code&gt; option for faster startup when plugins are not needed (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1957&quot;&gt;#1957&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;EndpointProducerBuilder support&lt;/strong&gt; — &lt;code class=&quot;highlighter-rouge&quot;&gt;CamelExchangeActionBuilder&lt;/code&gt; now accepts Camel’s &lt;code class=&quot;highlighter-rouge&quot;&gt;EndpointProducerBuilder&lt;/code&gt; for type-safe endpoint URIs&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Auto-set properties&lt;/strong&gt; — a new &lt;code class=&quot;highlighter-rouge&quot;&gt;autoSetProperties&lt;/code&gt; option on the Camel CLI run action simplifies property configuration (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1882&quot;&gt;#1882&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;notable-fixes&quot;&gt;Notable fixes&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Thread safety&lt;/strong&gt; — static lookup caches are now thread-safe on first use, and header validator resolution avoids the lookup lock to prevent deadlocks (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1878&quot;&gt;#1878&lt;/a&gt;, &lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1884&quot;&gt;#1884&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SQL script resolution&lt;/strong&gt; — SQL scripts are now resolved by prefix (&lt;code class=&quot;highlighter-rouge&quot;&gt;classpath:&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;file:&lt;/code&gt;, URL) and execute in declaration order (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1174&quot;&gt;#1174&lt;/a&gt;, &lt;a href=&quot;https://github.com/citrusframework/citrus/issues/701&quot;&gt;#701&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Dynamic HTTP server ports&lt;/strong&gt; — the actual bound server port is now correctly resolved when using dynamic port allocation (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1960&quot;&gt;#1960&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Deterministic ZipMessage serialization&lt;/strong&gt; — zip message payload serialization is now deterministic, eliminating flaky assertions caused by non-deterministic entry ordering (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1976&quot;&gt;#1976&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;HTTP binary body logging&lt;/strong&gt; — HTTP logging interceptors now summarize binary bodies instead of dumping raw bytes (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/896&quot;&gt;#896&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;migration-updates&quot;&gt;Migration updates&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Cucumber runtime and step modules migrated to JUnit Platform engine (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1858&quot;&gt;#1858&lt;/a&gt;, &lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1860&quot;&gt;#1860&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;Tests migrated from TestNG to JUnit Jupiter (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1873&quot;&gt;#1873&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;Date functions migrated from legacy &lt;code class=&quot;highlighter-rouge&quot;&gt;Calendar&lt;/code&gt; to &lt;code class=&quot;highlighter-rouge&quot;&gt;java.time&lt;/code&gt; API (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1864&quot;&gt;#1864&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For the full list of changes see the &lt;a href=&quot;/docs/history/#v5.2.0&quot;&gt;release changelog&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;major-library-versions&quot;&gt;Major library versions&lt;/h2&gt;

&lt;p&gt;Citrus 5.2.0 ships with the following major dependency versions:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Library&lt;/th&gt;
      &lt;th&gt;Version&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Apache Camel&lt;/td&gt;
      &lt;td&gt;4.23.0&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Quarkus&lt;/td&gt;
      &lt;td&gt;3.40.1.2&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Spring Framework&lt;/td&gt;
      &lt;td&gt;7.0.10&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Spring Boot&lt;/td&gt;
      &lt;td&gt;4.1.2&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Kafka&lt;/td&gt;
      &lt;td&gt;4.4.0&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Selenium&lt;/td&gt;
      &lt;td&gt;4.52.0&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Playwright&lt;/td&gt;
      &lt;td&gt;1.65.0&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Cucumber&lt;/td&gt;
      &lt;td&gt;8.0.4&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;JUnit Jupiter&lt;/td&gt;
      &lt;td&gt;6.1.3&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;TestNG&lt;/td&gt;
      &lt;td&gt;7.12.0&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Testcontainers&lt;/td&gt;
      &lt;td&gt;2.0.5&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Kubernetes Client&lt;/td&gt;
      &lt;td&gt;8.0.0&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Apache ActiveMQ Artemis&lt;/td&gt;
      &lt;td&gt;2.57.0&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Vert.x&lt;/td&gt;
      &lt;td&gt;5.2.3&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Jetty&lt;/td&gt;
      &lt;td&gt;12.1.15&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Netty&lt;/td&gt;
      &lt;td&gt;4.2.20.Final&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;update&quot;&gt;Update&lt;/h2&gt;

&lt;p&gt;Update the Citrus BOM in your &lt;code class=&quot;highlighter-rouge&quot;&gt;pom.xml&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.citrusframework&lt;span class=&quot;nt&quot;&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;citrus-bom&lt;span class=&quot;nt&quot;&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;version&amp;gt;&lt;/span&gt;5.2.1&lt;span class=&quot;nt&quot;&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;type&amp;gt;&lt;/span&gt;pom&lt;span class=&quot;nt&quot;&gt;&amp;lt;/type&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;scope&amp;gt;&lt;/span&gt;import&lt;span class=&quot;nt&quot;&gt;&amp;lt;/scope&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Thank you to everyone who contributed to this release!&lt;/p&gt;</content><author><name>Christoph Deppisch</name></author></entry><entry><title type="html">Citrus 5.1.0</title><link href="https://citrusframework.org/news/2026/10/19/release-5.1.0/" rel="alternate" type="text/html" title="Citrus 5.1.0" /><published>2026-10-19T00:00:00+02:00</published><updated>2026-10-19T00:00:00+02:00</updated><id>https://citrusframework.org/news/2026/10/19/release-5.1.0</id><content type="html" xml:base="https://citrusframework.org/news/2026/10/19/release-5.1.0/">&lt;p&gt;The Citrus community is happy to announce the release of &lt;strong&gt;Citrus 5.1.0&lt;/strong&gt;! 
This release brings three new modules, major improvements to browser-based testing with Selenium and a fresh set of validation capabilities with AssertJ.&lt;/p&gt;

&lt;p&gt;The release is packed with &lt;strong&gt;21 new features and enhancements&lt;/strong&gt;, &lt;strong&gt;13 bug fixes&lt;/strong&gt; and many &lt;strong&gt;dependency version updates&lt;/strong&gt;.
Here is a look at the highlights.&lt;/p&gt;

&lt;h2 id=&quot;graphql-support&quot;&gt;GraphQL support&lt;/h2&gt;

&lt;p&gt;Citrus 5.1.0 introduces a brand-new &lt;strong&gt;citrus-graphql&lt;/strong&gt; module (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1797&quot;&gt;#1797&lt;/a&gt;, &lt;a href=&quot;https://citrusframework.org/citrus/reference/html#graphql&quot;&gt;docs&lt;/a&gt;) that adds first-class support for testing GraphQL APIs. You can send queries, mutations and subscriptions through a typed &lt;code class=&quot;highlighter-rouge&quot;&gt;graphql()&lt;/code&gt; test action API, validate responses against SDL schemas, and simulate a GraphQL server for contract testing. The module builds on Spring GraphQL and supports Java, XML and YAML DSL out of the box.&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;given&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;graphql&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;graphqlClient&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;query&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;{ user(id: 1) { name email } }&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;graphql&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;graphqlClient&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;receive&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;validate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;$.data.user.name&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;John&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;assertj-validation&quot;&gt;AssertJ validation&lt;/h2&gt;

&lt;p&gt;The new &lt;strong&gt;citrus-validation-assertj&lt;/strong&gt; module (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1782&quot;&gt;#1782&lt;/a&gt;, &lt;a href=&quot;https://citrusframework.org/citrus/reference/html#assertj-message-validation&quot;&gt;docs&lt;/a&gt;) lets you use AssertJ assertion chains directly in your Citrus validation. You can write &lt;code class=&quot;highlighter-rouge&quot;&gt;@assertj()@&lt;/code&gt; expressions in expected message payloads or use the Java DSL with &lt;code class=&quot;highlighter-rouge&quot;&gt;satisfies()&lt;/code&gt; factories. The module covers value assertions, header validation, container conditions and coexists seamlessly with existing Hamcrest matchers.&lt;/p&gt;

&lt;p&gt;In the Java DSL, use &lt;code class=&quot;highlighter-rouge&quot;&gt;satisfies()&lt;/code&gt; with AssertJ’s fluent API to validate JsonPath and XPath values or message headers:&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;err&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;receive&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;MessageType&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;header&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;count&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;satisfies&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Integer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;assertThat&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;isBetween&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;40&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)))&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;validate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;validation&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;jsonPath&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;expression&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;$.qty&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;satisfies&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Integer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;
                    &lt;span class=&quot;n&quot;&gt;q&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;assertThat&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;q&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;isGreaterThan&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)))&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;expression&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;$.status&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;satisfies&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                    &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;assertThat&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;asString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;startsWith&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;OK&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)))));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In XML or YAML DSL, the &lt;code class=&quot;highlighter-rouge&quot;&gt;@assertj()@&lt;/code&gt; validation matcher lets you chain assertions directly in the expected value:&lt;/p&gt;

&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;receive&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;endpoint=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;myEndpoint&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;message&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;type=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;json&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;validate&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;nt&quot;&gt;&amp;lt;json-path&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;expression=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;$.qty&quot;&lt;/span&gt;
                 &lt;span class=&quot;na&quot;&gt;value=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;@assertj(asInt().isBetween(1, 10))@&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;nt&quot;&gt;&amp;lt;json-path&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;expression=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;$.tags&quot;&lt;/span&gt;
                 &lt;span class=&quot;na&quot;&gt;value=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;@assertj(asList().containsExactly('a', 'b'))@&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/validate&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;/message&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;header&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;element&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Operation&quot;&lt;/span&gt;
             &lt;span class=&quot;na&quot;&gt;value=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;@assertj(isIn('sayHello', 'sayHi'))@&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;/header&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/receive&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;playwright-browser-automation&quot;&gt;Playwright browser automation&lt;/h2&gt;

&lt;p&gt;Citrus 5.1.0 introduces &lt;strong&gt;citrus-playwright&lt;/strong&gt; (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1714&quot;&gt;#1714&lt;/a&gt;, &lt;a href=&quot;https://citrusframework.org/citrus/reference/html#playwright&quot;&gt;docs&lt;/a&gt;), a new module for browser automation built on &lt;a href=&quot;https://playwright.dev/&quot;&gt;Playwright&lt;/a&gt;. Playwright offers fast, reliable cross-browser testing with auto-waiting, network interception and multi-context isolation — and Citrus now wraps it in a familiar endpoint and action API that integrates naturally with your integration test scenarios.&lt;/p&gt;

&lt;p&gt;The module ships with Playwright 1.63.0 and a rich set of capabilities out of the box:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Typed &lt;code class=&quot;highlighter-rouge&quot;&gt;playwright()&lt;/code&gt; test actions&lt;/strong&gt; for navigation, clicks, form fills, screenshots, tracing, aria snapshots, WebAuthn passkeys, screencast recording and more (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1737&quot;&gt;#1737&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;XML and YAML DSL&lt;/strong&gt; elements for all Playwright actions (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1745&quot;&gt;#1745&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Browser-session HTTP client&lt;/strong&gt; that sends API requests carrying the browser’s cookies and auth state, bridging UI and API testing in a single scenario (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1751&quot;&gt;#1751&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Cucumber steps&lt;/strong&gt; via a companion citrus-cucumber-playwright module for BDD-style browser tests (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1803&quot;&gt;#1803&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Endpoint catalog&lt;/strong&gt; integration so AI-assisted coding and IDE completion discover the Playwright endpoint (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1775&quot;&gt;#1775&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;selenium-improvements&quot;&gt;Selenium improvements&lt;/h2&gt;

&lt;p&gt;Selenium-based browser testing (&lt;a href=&quot;https://citrusframework.org/citrus/reference/html#selenium&quot;&gt;docs&lt;/a&gt;) has been modernized with a wave of new actions and quality-of-life fixes:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Interaction actions&lt;/strong&gt; — double click, right click, drag and drop, press keys and extended dropdown select (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1819&quot;&gt;#1819&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Verify and extract actions&lt;/strong&gt; with variable-aware XML/YAML locators to check page URL, title, element state and store values as test variables (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1821&quot;&gt;#1821&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Frame navigation, cookie management&lt;/strong&gt; and JavaScript result variable support (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1830&quot;&gt;#1830&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Browser options&lt;/strong&gt; — headless mode, arguments, window size and timeouts configurable on the endpoint (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1833&quot;&gt;#1833&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;Several &lt;strong&gt;bug fixes&lt;/strong&gt; covering start-page resolution, element lookup error handling, JS error collection and cache clearing (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1812&quot;&gt;#1812&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;test-behavior-and-validation-improvements&quot;&gt;Test behavior and validation improvements&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Named and composable test behaviors&lt;/strong&gt; — behaviors can now carry a name, be nested and scoped, so they compose cleanly and appear with meaningful labels in reports (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1752&quot;&gt;#1752&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Typed test results&lt;/strong&gt; — ask a question in a test behavior and receive a typed answer back for downstream assertions (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1757&quot;&gt;#1757&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Combinator validation matchers&lt;/strong&gt; — &lt;code class=&quot;highlighter-rouge&quot;&gt;@allOf()@&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;@anyOf()@&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;@not()@&lt;/code&gt; let you compose multiple validation matchers into a single expression (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1768&quot;&gt;#1768&lt;/a&gt;, &lt;a href=&quot;https://citrusframework.org/citrus/reference/html#matcher-allof&quot;&gt;docs&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Comparison validation matchers&lt;/strong&gt; — &lt;code class=&quot;highlighter-rouge&quot;&gt;@greaterThanOrEqualTo()@&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;@lowerThanOrEqualTo()@&lt;/code&gt; complement the existing comparison set (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1767&quot;&gt;#1767&lt;/a&gt;, &lt;a href=&quot;https://citrusframework.org/citrus/reference/html#matcher-greaterthanorequalto&quot;&gt;docs&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Plain-Java SQL result set validation&lt;/strong&gt; — validate SQL query results with a typed &lt;code class=&quot;highlighter-rouge&quot;&gt;SqlResultSetValidator&lt;/code&gt; callback and POJO row mapping instead of scripts (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/619&quot;&gt;#619&lt;/a&gt;, &lt;a href=&quot;https://citrusframework.org/citrus/reference/html#actions-sql&quot;&gt;docs&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;notable-fixes&quot;&gt;Notable fixes&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;TestContext isolation&lt;/strong&gt; — each dynamic test in &lt;code class=&quot;highlighter-rouge&quot;&gt;JUnitCitrusTest&lt;/code&gt; now receives its own context, preventing final-action side effects across tests (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1816&quot;&gt;#1816&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Content-Type on bodyless requests&lt;/strong&gt; — HTTP client no longer sends &lt;code class=&quot;highlighter-rouge&quot;&gt;Content-Type: text/plain&lt;/code&gt; on GET and other bodyless requests (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1826&quot;&gt;#1826&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;CitrusSettings refactoring&lt;/strong&gt; — static final fields replaced with dynamic accessor methods so settings changes take effect at runtime (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1771&quot;&gt;#1771&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Send action error handling&lt;/strong&gt; — send actions inside &lt;code class=&quot;highlighter-rouge&quot;&gt;assertException&lt;/code&gt; no longer hang when message creation fails (&lt;a href=&quot;https://github.com/citrusframework/citrus/issues/1798&quot;&gt;#1798&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For the full list of changes see the &lt;a href=&quot;/docs/history/#v5.1.0&quot;&gt;release changelog&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;major-library-versions&quot;&gt;Major library versions&lt;/h2&gt;

&lt;p&gt;Citrus 5.1.0 ships with the following major dependency versions:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Library&lt;/th&gt;
      &lt;th&gt;Version&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Apache Camel&lt;/td&gt;
      &lt;td&gt;4.23.0&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Quarkus&lt;/td&gt;
      &lt;td&gt;3.40.1&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Spring Framework&lt;/td&gt;
      &lt;td&gt;7.0.9&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Spring Boot&lt;/td&gt;
      &lt;td&gt;4.1.1&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Kafka&lt;/td&gt;
      &lt;td&gt;4.4.0&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Selenium&lt;/td&gt;
      &lt;td&gt;4.51.0&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Playwright&lt;/td&gt;
      &lt;td&gt;1.63.0&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Cucumber&lt;/td&gt;
      &lt;td&gt;8.0.4&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;JUnit Jupiter&lt;/td&gt;
      &lt;td&gt;6.1.3&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;TestNG&lt;/td&gt;
      &lt;td&gt;7.12.0&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Testcontainers&lt;/td&gt;
      &lt;td&gt;2.0.5&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Kubernetes Client&lt;/td&gt;
      &lt;td&gt;7.9.0&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Apache ActiveMQ Artemis&lt;/td&gt;
      &lt;td&gt;2.57.0&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Vert.x&lt;/td&gt;
      &lt;td&gt;4.5.35&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Jetty&lt;/td&gt;
      &lt;td&gt;12.1.14&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Netty&lt;/td&gt;
      &lt;td&gt;4.2.19.Final&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;java-17--last-supported-release&quot;&gt;Java 17 — last supported release&lt;/h2&gt;

&lt;p&gt;Citrus 5.1.0 is the &lt;strong&gt;last release to support Java 17&lt;/strong&gt;. Starting with &lt;strong&gt;Citrus 5.2.x&lt;/strong&gt;, the minimum required Java version will be &lt;strong&gt;Java 21&lt;/strong&gt;. If you are still on Java 17, please plan your migration accordingly before upgrading to the next release line.&lt;/p&gt;

&lt;h2 id=&quot;update&quot;&gt;Update&lt;/h2&gt;

&lt;p&gt;Update the Citrus BOM in your &lt;code class=&quot;highlighter-rouge&quot;&gt;pom.xml&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.citrusframework&lt;span class=&quot;nt&quot;&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;citrus-bom&lt;span class=&quot;nt&quot;&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;version&amp;gt;&lt;/span&gt;5.2.1&lt;span class=&quot;nt&quot;&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;type&amp;gt;&lt;/span&gt;pom&lt;span class=&quot;nt&quot;&gt;&amp;lt;/type&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;scope&amp;gt;&lt;/span&gt;import&lt;span class=&quot;nt&quot;&gt;&amp;lt;/scope&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Thank you to everyone who contributed to this release!&lt;/p&gt;</content><author><name>Christoph Deppisch</name></author></entry><entry><title type="html">Testing Drools-Backed Camel Routes with Citrus</title><link href="https://citrusframework.org/samples/camel-drools-rules/" rel="alternate" type="text/html" title="Testing Drools-Backed Camel Routes with Citrus" /><published>2026-09-26T00:00:00+02:00</published><updated>2026-09-26T00:00:00+02:00</updated><id>https://citrusframework.org/samples/sample-eip-drools-rules</id><content type="html" xml:base="https://citrusframework.org/samples/camel-drools-rules/">&lt;p&gt;Business logic that lives in code is logic that only developers can change.
Pricing tiers shift, fraud thresholds evolve, and routing rules drift as business requirements grow — and every one of those changes requires a developer to open a Java file, write a test, get a review, and deploy.
That cycle is expensive for decisions that a business analyst should own.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://www.drools.org&quot;&gt;Drools&lt;/a&gt; breaks that coupling.
Rules are expressed in a &lt;code class=&quot;highlighter-rouge&quot;&gt;.drl&lt;/code&gt; file or a decision table spreadsheet, compiled at startup, and evaluated at runtime against incoming facts.
A business analyst can change a routing threshold, commit the &lt;code class=&quot;highlighter-rouge&quot;&gt;.drl&lt;/code&gt; file, and the next application restart picks it up — no Java changes, no redeployment of compiled code.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://camel.apache.org&quot;&gt;Apache Camel&lt;/a&gt; and Drools are a natural pair.
Camel handles the plumbing — consuming from Kafka, transforming the payload, dispatching to the right output channel.
Drools handles the decision — evaluating the message against a set of rules and declaring a routing outcome.
The two are connected through a plain Camel bean processor that runs the KIE session and writes the result back as a message header.&lt;/p&gt;

&lt;p&gt;The challenge is testing this arrangement end-to-end.
Unit tests can exercise the DRL rules in isolation, but they cannot prove that Camel correctly wires the rule engine output to the right downstream channel, handles the marshal-evaluate-marshal pipeline, and routes deterministically under real Kafka connectivity.
That is the gap that &lt;a href=&quot;https://citrusframework.org&quot;&gt;Citrus&lt;/a&gt; fills.&lt;/p&gt;

&lt;p&gt;This post walks through the &lt;code class=&quot;highlighter-rouge&quot;&gt;24-drools-rules&lt;/code&gt; example from the &lt;a href=&quot;https://github.com/citrusframework/citrus-camel-eip-examples&quot;&gt;Camel EIP examples&lt;/a&gt; repository.
It shows the complete picture: the data model and DRL rules, the Camel route that consumes decisions from the rule engine, and the Citrus integration tests that prove every routing branch is taken correctly — running on both Quarkus and Spring Boot.
The shared Docker Compose infrastructure, &lt;code class=&quot;highlighter-rouge&quot;&gt;EipInfraSetup&lt;/code&gt;, and how to run the tests are described in the &lt;a href=&quot;/samples/camel-eip/&quot;&gt;Camel EIP examples overview&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;the-scenario-rule-based-order-routing&quot;&gt;The scenario: rule-based order routing&lt;/h2&gt;

&lt;p&gt;The application consumes order events from a Kafka topic &lt;code class=&quot;highlighter-rouge&quot;&gt;eip.orders.placed&lt;/code&gt;.
Each order carries several attributes — a monetary amount, a destination country, and a hazardous-materials flag — and the rule engine evaluates those attributes against a priority-ordered rule set to assign exactly one routing decision.
Camel then dispatches the order to the appropriate output topic based on that decision.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Routing decision&lt;/th&gt;
      &lt;th&gt;Rule condition&lt;/th&gt;
      &lt;th&gt;Output topic&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;hazmat&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;containsHazmat == true&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;eip.orders.hazmat&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;fraud-review&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;amount &amp;gt;= 10000&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;destinationCountry != &quot;US&quot;&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;eip.orders.fraud-review&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;express&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;amount &amp;gt;= 500&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;eip.orders.express&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;standard&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;everything else (catch-all default)&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;eip.orders.standard&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Rules are evaluated top-to-bottom with decreasing salience: hazmat (40) beats fraud-review (30), which beats express (20), which beats the default (10).
A high-value international order that also contains hazardous materials goes to the hazmat channel, not the fraud-review channel.
That priority ordering is a business rule in its own right, and the tests verify it explicitly.&lt;/p&gt;

&lt;h2 id=&quot;the-data-model&quot;&gt;The data model&lt;/h2&gt;

&lt;p&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;Order&lt;/code&gt; class is the &lt;em&gt;fact&lt;/em&gt; that Drools reasons over.
It is a plain Java POJO; no Drools annotations are needed on the model itself.&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Order&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;orderId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customerId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;amount&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;destinationCountry&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;boolean&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;containsHazmat&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;routingDecision&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;// written by the rule engine&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// getters and setters ...&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;routingDecision&lt;/code&gt; field starts &lt;code class=&quot;highlighter-rouge&quot;&gt;null&lt;/code&gt;.
Each rule checks for &lt;code class=&quot;highlighter-rouge&quot;&gt;routingDecision == null&lt;/code&gt; in its &lt;code class=&quot;highlighter-rouge&quot;&gt;when&lt;/code&gt; clause, which ensures only one rule fires per fact: once any rule sets the field, the remaining rules see a non-null value and skip themselves.&lt;/p&gt;

&lt;h2 id=&quot;the-drl-rules&quot;&gt;The DRL rules&lt;/h2&gt;

&lt;p&gt;The rules live in &lt;code class=&quot;highlighter-rouge&quot;&gt;src/main/resources/com/example/eip/drools/order-routing.drl&lt;/code&gt;.
The &lt;code class=&quot;highlighter-rouge&quot;&gt;salience&lt;/code&gt; attribute controls evaluation order — higher salience fires first:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-drl&quot;&gt;package com.example.eip.drools;

import com.example.eip.drools.Order;

rule &quot;Route hazmat orders to hazmat handler&quot;
    salience 40
when
    $o: Order(containsHazmat == true, routingDecision == null)
then
    $o.setRoutingDecision(&quot;hazmat&quot;);
    update($o);
end

rule &quot;Route high-value international to fraud review&quot;
    salience 30
when
    $o: Order(amount &amp;gt;= 10000, destinationCountry != &quot;US&quot;, routingDecision == null)
then
    $o.setRoutingDecision(&quot;fraud-review&quot;);
    update($o);
end

rule &quot;Route express orders to priority queue&quot;
    salience 20
when
    $o: Order(amount &amp;gt;= 500, routingDecision == null)
then
    $o.setRoutingDecision(&quot;express&quot;);
    update($o);
end

rule &quot;Default routing&quot;
    salience 10
when
    $o: Order(routingDecision == null)
then
    $o.setRoutingDecision(&quot;standard&quot;);
    update($o);
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;update($o)&lt;/code&gt; call after each &lt;code class=&quot;highlighter-rouge&quot;&gt;then&lt;/code&gt; block re-inserts the modified fact into working memory.
This allows the engine to propagate the change but, because the remaining rules all guard with &lt;code class=&quot;highlighter-rouge&quot;&gt;routingDecision == null&lt;/code&gt;, no second rule can fire.&lt;/p&gt;

&lt;p&gt;Rules are registered in &lt;code class=&quot;highlighter-rouge&quot;&gt;META-INF/kmodule.xml&lt;/code&gt;, which tells Drools which packages to load and which session name to use:&lt;/p&gt;

&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;kmodule&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;xmlns=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://www.drools.org/xsd/kmodule&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;kbase&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;orderRules&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;packages=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;com.example.eip.drools&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;ksession&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;orderSession&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/kbase&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/kmodule&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;the-rule-engine-bridge&quot;&gt;The rule engine bridge&lt;/h2&gt;

&lt;p&gt;The rules cannot call Camel directly — Drools is a pure reasoning engine.
The bridge is a CDI/Spring bean named &lt;code class=&quot;highlighter-rouge&quot;&gt;ruleBasedRouter&lt;/code&gt; that Camel invokes as a bean processor.
It translates the incoming message body into an &lt;code class=&quot;highlighter-rouge&quot;&gt;Order&lt;/code&gt; fact, runs a KIE session, and writes the &lt;code class=&quot;highlighter-rouge&quot;&gt;routingDecision&lt;/code&gt; outcome back as a Camel message header.&lt;/p&gt;

&lt;p&gt;On &lt;strong&gt;Quarkus&lt;/strong&gt;, the bean uses CDI annotations:&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@ApplicationScoped&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@Named&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;ruleBasedRouter&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;RuleBasedRouter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;KieContainer&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;kieContainer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;RuleBasedRouter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;KieServices&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ks&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;KieServices&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;Factory&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;kieContainer&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ks&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getKieClasspathContainer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;evaluate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Exchange&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getIn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getBody&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;Order&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;order&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Order&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;setOrderId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Number&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;order_id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)).&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;longValue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;());&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;setCustomerId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;valueOf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;customer_id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)));&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;setAmount&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Number&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;amount&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)).&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;doubleValue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;());&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;setDestinationCountry&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getOrDefault&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;destination_country&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;US&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;setContainsHazmat&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Boolean&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;equals&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;contains_hazmat&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)));&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;KieSession&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;kieContainer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;newKieSession&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;orderSession&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;insert&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;fireAllRules&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;finally&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;dispose&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getIn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;setHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;routingDecision&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getRoutingDecision&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;());&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;On &lt;strong&gt;Spring Boot&lt;/strong&gt;, the only difference is the annotation:&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@Component&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;ruleBasedRouter&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;RuleBasedRouter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// identical implementation&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;KieContainer&lt;/code&gt; is built once at construction time from the classpath — &lt;code class=&quot;highlighter-rouge&quot;&gt;kmodule.xml&lt;/code&gt; and all &lt;code class=&quot;highlighter-rouge&quot;&gt;.drl&lt;/code&gt; files on &lt;code class=&quot;highlighter-rouge&quot;&gt;com.example.eip.drools&lt;/code&gt; are compiled into it.
Each message invocation then creates a fresh &lt;code class=&quot;highlighter-rouge&quot;&gt;KieSession&lt;/code&gt; from the container, inserts the fact, fires all rules, and disposes the session.
The &lt;code class=&quot;highlighter-rouge&quot;&gt;try-finally&lt;/code&gt; around &lt;code class=&quot;highlighter-rouge&quot;&gt;dispose()&lt;/code&gt; is important: KIE sessions hold internal state and must be released to avoid memory leaks in long-running processes.&lt;/p&gt;

&lt;h2 id=&quot;the-camel-route&quot;&gt;The Camel route&lt;/h2&gt;

&lt;p&gt;With the rule engine wrapped in a bean, the Camel route is remarkably short:&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@ApplicationScoped&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// @Component on Spring Boot&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;OrderRoutingRoute&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RouteBuilder&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.placed?brokers=&amp;amp;groupId=rule-router&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;drools-content-router&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;unmarshal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;java&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;util&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;bean&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;ruleBasedRouter&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;evaluate&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Rule engine decided: ${header.routingDecision} for order ${body[order_id]}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;toD&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;direct:${header.routingDecision}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;direct:standard&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;route-standard&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;marshal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.standard?brokers=&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;direct:express&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;route-express&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;marshal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.express?brokers=&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;direct:hazmat&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;route-hazmat&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;marshal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.hazmat?brokers=&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;direct:fraud-review&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;route-fraud-review&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;marshal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.fraud-review?brokers=&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The main &lt;code class=&quot;highlighter-rouge&quot;&gt;drools-content-router&lt;/code&gt; route does four things: consume from Kafka, unmarshal the JSON body into a &lt;code class=&quot;highlighter-rouge&quot;&gt;Map&lt;/code&gt;, invoke the rule engine via &lt;code class=&quot;highlighter-rouge&quot;&gt;.bean()&lt;/code&gt;, and then dispatch dynamically with &lt;code class=&quot;highlighter-rouge&quot;&gt;.toD(&quot;direct:${header.routingDecision}&quot;)&lt;/code&gt;.
The &lt;code class=&quot;highlighter-rouge&quot;&gt;toD&lt;/code&gt; EIP is the dynamic version of &lt;code class=&quot;highlighter-rouge&quot;&gt;to&lt;/code&gt; — the destination URI is evaluated at message-processing time from the header the rule engine just wrote.&lt;/p&gt;

&lt;p&gt;Each &lt;code class=&quot;highlighter-rouge&quot;&gt;direct:*&lt;/code&gt; sub-route is minimal by design: it just marshals the &lt;code class=&quot;highlighter-rouge&quot;&gt;Map&lt;/code&gt; back to JSON and forwards to the corresponding Kafka topic.
Keeping the sub-routes thin means the routing logic lives entirely in the rules, not scattered across Camel processing steps.&lt;/p&gt;

&lt;h2 id=&quot;the-citrus-tests&quot;&gt;The Citrus tests&lt;/h2&gt;

&lt;p&gt;The test class implements &lt;code class=&quot;highlighter-rouge&quot;&gt;EipTestSupport&lt;/code&gt; and the application-under-test runs in the same JVM as the tests.
Citrus acts as both the message producer (sending order events to &lt;code class=&quot;highlighter-rouge&quot;&gt;eip.orders.placed&lt;/code&gt;) and the message consumer (listening on each output topic to verify where Camel routed the order).&lt;/p&gt;

&lt;h3 id=&quot;test-1--standard-order&quot;&gt;Test 1 — Standard order&lt;/h3&gt;

&lt;p&gt;The first test verifies the default path: an order with a low amount, a domestic destination, and no hazardous materials should be routed to &lt;code class=&quot;highlighter-rouge&quot;&gt;eip.orders.standard&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@Test&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;shouldRouteStandardOrder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// amount &amp;lt; 500, no hazmat, domestic -&amp;gt; standard&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;given&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;waitForCamelRouteStarted&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;drools-content-router&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.placed&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;{\&quot;order_id\&quot;: 1001, \&quot;customer_id\&quot;: \&quot;C-100\&quot;, \&quot;amount\&quot;: 49.99, &quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;\&quot;destination_country\&quot;: \&quot;US\&quot;, \&quot;contains_hazmat\&quot;: false}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;header&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;KafkaMessageHeaders&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;MESSAGE_KEY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;DROOLS-STD-1001&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;repeatOnError&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;times&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;actions&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;receive&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.standard?consumerGroup=citrus-drools-standard-group&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&quot;&quot;
                    {
                      &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;order_id&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: 1001,
                      &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;customer_id&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;,
                      &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;amount&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: 49.99,
                      &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;destination_country&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;US&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;,
                      &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;contains_hazmat&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: false
                    }
                    &quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The structure follows Citrus’s given-when-then convention.
The &lt;code class=&quot;highlighter-rouge&quot;&gt;given&lt;/code&gt; phase ensures the route is running.
The &lt;code class=&quot;highlighter-rouge&quot;&gt;when&lt;/code&gt; phase produces the order event to Kafka.
The &lt;code class=&quot;highlighter-rouge&quot;&gt;then&lt;/code&gt; phase consumes from &lt;code class=&quot;highlighter-rouge&quot;&gt;eip.orders.standard&lt;/code&gt; and validates the body.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;repeatOnError()&lt;/code&gt; wrapper on the receive action is the key to reliable asynchronous assertions.
Camel consumes from Kafka, runs the DRL rules, evaluates the result, and publishes to the output topic — all asynchronously.
The test cannot know exactly when the message will appear on the output side.
&lt;code class=&quot;highlighter-rouge&quot;&gt;repeatOnError()&lt;/code&gt; retries the receive action until it succeeds or the attempt limit is reached, bridging the asynchrony without introducing arbitrary &lt;code class=&quot;highlighter-rouge&quot;&gt;Thread.sleep()&lt;/code&gt; calls.&lt;/p&gt;

&lt;p&gt;Each test uses a distinct Kafka consumer group on the receive endpoint.
This is important: if two tests share a consumer group, the second test might receive the message that was published during the first test, producing a false positive.
Named groups ensure Citrus sees exactly the message that the current test produced.&lt;/p&gt;

&lt;h3 id=&quot;test-2--express-order&quot;&gt;Test 2 — Express order&lt;/h3&gt;

&lt;p&gt;An order with amount ≥ $500 and no special flags should match the “Route express orders to priority queue” rule:&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@Test&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;shouldRouteExpressOrder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// amount &amp;gt;= 500, domestic, no hazmat -&amp;gt; express&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;given&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;waitForCamelRouteStarted&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;drools-content-router&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.placed&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;{\&quot;order_id\&quot;: 1002, \&quot;customer_id\&quot;: \&quot;C-200\&quot;, \&quot;amount\&quot;: 750.00, &quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;\&quot;destination_country\&quot;: \&quot;US\&quot;, \&quot;contains_hazmat\&quot;: false}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;header&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;KafkaMessageHeaders&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;MESSAGE_KEY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;DROOLS-EXP-1002&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;repeatOnError&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;times&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;actions&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;receive&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.express?consumerGroup=citrus-drools-express-group&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&quot;&quot;
                    {
                      &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;order_id&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: 1002,
                      &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;customer_id&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;,
                      &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;amount&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: 750.0,
                      &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;destination_country&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;US&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;,
                      &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;contains_hazmat&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: false
                    }
                    &quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Notice that &lt;code class=&quot;highlighter-rouge&quot;&gt;750.00&lt;/code&gt; in the input becomes &lt;code class=&quot;highlighter-rouge&quot;&gt;750.0&lt;/code&gt; in the expected body.
That is a consequence of Java’s JSON serialization of &lt;code class=&quot;highlighter-rouge&quot;&gt;double&lt;/code&gt; values — the trailing zero is dropped.
This kind of serialization difference is common when round-tripping through &lt;code class=&quot;highlighter-rouge&quot;&gt;unmarshal().json(Map.class)&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;marshal().json()&lt;/code&gt;, and the test body must match what Camel actually produces, not what the human eye expects.&lt;/p&gt;

&lt;h3 id=&quot;test-3--hazmat-order-salience-override&quot;&gt;Test 3 — Hazmat order (salience override)&lt;/h3&gt;

&lt;p&gt;The hazmat test is the most important rule-priority test in the suite.
An order with &lt;code class=&quot;highlighter-rouge&quot;&gt;contains_hazmat: true&lt;/code&gt; should go to &lt;code class=&quot;highlighter-rouge&quot;&gt;eip.orders.hazmat&lt;/code&gt; regardless of its amount or destination country — because the hazmat rule has salience 40, which beats all other rules:&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@Test&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;shouldRouteHazmatOrder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// contains_hazmat = true -&amp;gt; hazmat (highest salience, wins over express)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;given&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;waitForCamelRouteStarted&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;drools-content-router&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.placed&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;{\&quot;order_id\&quot;: 1003, \&quot;customer_id\&quot;: \&quot;C-300\&quot;, \&quot;amount\&quot;: 120.00, &quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;\&quot;destination_country\&quot;: \&quot;US\&quot;, \&quot;contains_hazmat\&quot;: true}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;header&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;KafkaMessageHeaders&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;MESSAGE_KEY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;DROOLS-HAZ-1003&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;repeatOnError&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;times&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;actions&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;receive&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.hazmat?consumerGroup=citrus-drools-hazmat-group&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&quot;&quot;
                    {
                      &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;order_id&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: 1003,
                      &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;customer_id&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;300&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;,
                      &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;amount&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: 120.0,
                      &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;destination_country&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;US&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;,
                      &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;contains_hazmat&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: true
                    }
                    &quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This test proves more than just “hazmat orders are routed correctly”.
It proves that when &lt;code class=&quot;highlighter-rouge&quot;&gt;contains_hazmat&lt;/code&gt; is &lt;code class=&quot;highlighter-rouge&quot;&gt;true&lt;/code&gt;, the hazmat rule fires and sets &lt;code class=&quot;highlighter-rouge&quot;&gt;routingDecision = &quot;hazmat&quot;&lt;/code&gt;, which prevents the express and standard rules from firing (because they guard on &lt;code class=&quot;highlighter-rouge&quot;&gt;routingDecision == null&lt;/code&gt;).
That mutual-exclusion logic is a Drools concern, not a Camel concern — but the end-to-end test is the only place that confirms the full chain delivers the right outcome on the right Kafka topic.&lt;/p&gt;

&lt;h3 id=&quot;test-4--fraud-review-order&quot;&gt;Test 4 — Fraud review order&lt;/h3&gt;

&lt;p&gt;The final test covers the fraud-review path.
A high-value order ($15,000) destined for Germany matches the “Route high-value international to fraud review” rule, which sits at salience 30:&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@Test&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;shouldRouteFraudReviewOrder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// amount &amp;gt;= 10000, non-US destination, no hazmat -&amp;gt; fraud-review&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;given&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;waitForCamelRouteStarted&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;drools-content-router&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.placed&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;{\&quot;order_id\&quot;: 1004, \&quot;customer_id\&quot;: \&quot;C-400\&quot;, \&quot;amount\&quot;: 15000.00, &quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;\&quot;destination_country\&quot;: \&quot;DE\&quot;, \&quot;contains_hazmat\&quot;: false}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;header&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;KafkaMessageHeaders&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;MESSAGE_KEY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;DROOLS-FRAUD-1004&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;repeatOnError&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;times&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;actions&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;receive&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.fraud-review?consumerGroup=citrus-drools-fraud-review-group&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&quot;&quot;
                    {
                      &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;order_id&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: 1004,
                      &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;customer_id&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;400&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;,
                      &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;amount&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: 15000.0,
                      &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;destination_country&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DE&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;,
                      &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;contains_hazmat&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: false
                    }
                    &quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Together, the four tests form a complete branch-coverage suite.
Every rule in the DRL file is exercised by at least one test, and the salience ordering is verified by the hazmat test (which uses an amount that would otherwise qualify for express routing).&lt;/p&gt;

&lt;h2 id=&quot;what-makes-this-test-strategy-effective&quot;&gt;What makes this test strategy effective&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;End-to-end over mocking.&lt;/strong&gt; The tests make no attempt to mock the Kafka broker, the Drools runtime, or the Camel route itself.
The entire stack runs inside a single JVM, connected to a real Kafka broker in a Docker container.
This means the tests find the problems that matter most in production: message serialization bugs, consumer group configuration errors, rule compilation failures, and KIE session lifecycle issues.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Async-safe assertions with &lt;code class=&quot;highlighter-rouge&quot;&gt;repeatOnError()&lt;/code&gt;.&lt;/strong&gt; Camel consumes from Kafka, runs the DRL rules, and publishes to the output topic — all asynchronously.
The &lt;code class=&quot;highlighter-rouge&quot;&gt;repeatOnError()&lt;/code&gt; wrapper retries the receive action until the message arrives, without introducing arbitrary &lt;code class=&quot;highlighter-rouge&quot;&gt;Thread.sleep()&lt;/code&gt; calls.
The alternative is brittle: too short and the test fails on slow CI machines, too long and the suite becomes unnecessarily slow.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Isolated consumer groups.&lt;/strong&gt; Each test receives on a uniquely named Kafka consumer group.
Without this isolation, a message produced in test N could be consumed by test N+1 if the consumer group offset had not advanced.
Named groups ensure each test sees exactly the message it produced.&lt;/p&gt;

&lt;h2 id=&quot;drools-dependencies&quot;&gt;Drools dependencies&lt;/h2&gt;

&lt;p&gt;Drools 10 can be used without the Quarkus Drools extension, which avoids Quarkus-version coupling.
The three artifacts needed are:&lt;/p&gt;

&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.drools&lt;span class=&quot;nt&quot;&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;drools-engine&lt;span class=&quot;nt&quot;&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;version&amp;gt;&lt;/span&gt;10.2.0&lt;span class=&quot;nt&quot;&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.drools&lt;span class=&quot;nt&quot;&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;drools-xml-support&lt;span class=&quot;nt&quot;&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;version&amp;gt;&lt;/span&gt;10.2.0&lt;span class=&quot;nt&quot;&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.drools&lt;span class=&quot;nt&quot;&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;drools-mvel&lt;span class=&quot;nt&quot;&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;version&amp;gt;&lt;/span&gt;10.2.0&lt;span class=&quot;nt&quot;&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;drools-engine&lt;/code&gt; provides the core KIE API.
&lt;code class=&quot;highlighter-rouge&quot;&gt;drools-xml-support&lt;/code&gt; is required for &lt;code class=&quot;highlighter-rouge&quot;&gt;kmodule.xml&lt;/code&gt; parsing.
&lt;code class=&quot;highlighter-rouge&quot;&gt;drools-mvel&lt;/code&gt; provides the MVEL expression evaluator used inside DRL &lt;code class=&quot;highlighter-rouge&quot;&gt;when&lt;/code&gt; clauses — without it, conditions like &lt;code class=&quot;highlighter-rouge&quot;&gt;amount &amp;gt;= 500&lt;/code&gt; will fail to compile at startup.&lt;/p&gt;

&lt;h2 id=&quot;key-takeaways&quot;&gt;Key takeaways&lt;/h2&gt;

&lt;p&gt;Drools and Camel complement each other well for scenarios where routing logic needs to change frequently and be readable by non-developers.
But integration between a rule engine, a messaging broker, and a Camel route is exactly the kind of multi-moving-part system where integration tests are essential.&lt;/p&gt;

&lt;p&gt;Citrus provides the missing test layer.
Its Kafka endpoints act as first-class test participants — producing order events and consuming routing results — without any mocking or interception.
The &lt;code class=&quot;highlighter-rouge&quot;&gt;repeatOnError()&lt;/code&gt; wrapper handles asynchrony cleanly.
The given-when-then structure makes each test scenario easy to read and maintain.
And the same test assertions run against Quarkus and Spring Boot without modification, so the routing behavior is verified regardless of deployment choice.&lt;/p&gt;

&lt;p&gt;The four tests in this suite cover every routing branch and exercise every DRL rule.
That coverage gives confidence that rule priority ordering is correct, the KIE session lifecycle is sound, and Camel’s &lt;code class=&quot;highlighter-rouge&quot;&gt;toD()&lt;/code&gt; dynamic dispatch correctly interprets the header the rule engine writes.
Together, they form the kind of automated safety net that makes ongoing rule maintenance safe — change a threshold in the DRL file, run the tests, and know immediately whether the expected routing behavior is preserved.&lt;/p&gt;

&lt;p&gt;For the test infrastructure setup, shared test utilities, runtime wiring, dependencies, and how to run the tests, see the &lt;a href=&quot;/samples/camel-eip/&quot;&gt;Camel EIP examples&lt;/a&gt; overview page.&lt;/p&gt;</content><author><name></name></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://citrusframework.org/img/icons/camel.png" /></entry><entry><title type="html">Testing Redis-Backed Camel Routes with Citrus</title><link href="https://citrusframework.org/samples/camel-redis-integration/" rel="alternate" type="text/html" title="Testing Redis-Backed Camel Routes with Citrus" /><published>2026-09-25T00:00:00+02:00</published><updated>2026-09-25T00:00:00+02:00</updated><id>https://citrusframework.org/samples/sample-eip-redis-integration</id><content type="html" xml:base="https://citrusframework.org/samples/camel-redis-integration/">&lt;p&gt;Redis is one of those infrastructure components that adds much value to various integration scenarios.
In an integration layer, it acts as a cache that quietly shoulders four distinct jobs: caching expensive lookups so the database is not hammered on every message, deduplicating events so downstream services are not charged twice, coordinating multiple service instances through distributed locks, and acting as a lightweight pub/sub channel for intra-service notifications.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://camel.apache.org&quot;&gt;Apache Camel&lt;/a&gt; integrates with Redis natively, and the patterns that Redis enables — Content Enricher with cache-aside, Idempotent Receiver with Redis-backed deduplication, and Competing Consumers with distributed locking — map cleanly to Camel’s route DSL.
But integration at the boundary of a live Redis instance is exactly the kind of scenario that a unit test cannot cover.
You need a real Redis, real Kafka topics, and an integration test framework that can coordinate both sides of the exchange.&lt;/p&gt;

&lt;p&gt;This post walks through three Redis-backed Camel routes and the &lt;a href=&quot;https://citrusframework.org&quot;&gt;Citrus&lt;/a&gt; integration tests that verify them end-to-end, running identically on both Quarkus and Spring Boot.
The test infrastructure follows the same pattern used across all Camel EIP examples — see the &lt;a href=&quot;/samples/camel-eip/&quot;&gt;Camel EIP examples&lt;/a&gt; overview page for the shared Docker Compose setup, &lt;code class=&quot;highlighter-rouge&quot;&gt;EipInfraSetup&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;EipTestSupport&lt;/code&gt;, dependencies, and how to run the tests.
This example extends the base Compose stack with a Redis service alongside Kafka.&lt;/p&gt;

&lt;h2 id=&quot;the-three-patterns&quot;&gt;The three patterns&lt;/h2&gt;

&lt;p&gt;The example covers the three most common uses of Redis in an integration layer:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Pattern&lt;/th&gt;
      &lt;th&gt;Route ID&lt;/th&gt;
      &lt;th&gt;Redis operation&lt;/th&gt;
      &lt;th&gt;Test focus&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Content Enricher with caching&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;cached-enrichment&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;GET&lt;/code&gt; / &lt;code class=&quot;highlighter-rouge&quot;&gt;SETEX&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Cache miss on first request, cache hit on second&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Idempotent Receiver&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;idempotent-receiver&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;SET NX EX&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Unique events forwarded, duplicates dropped&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Distributed lock&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;distributed-lock&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;SET NX EX&lt;/code&gt; / &lt;code class=&quot;highlighter-rouge&quot;&gt;DEL&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Lock acquisition and safe release&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;All three routes consume from or produce to Kafka topics, which makes the test structure consistent: send a message to a Kafka topic, wait for the Camel route to process it, and verify the output on another Kafka topic or through Camel’s route statistics.&lt;/p&gt;

&lt;h2 id=&quot;pattern-1--content-enricher-with-redis-caching&quot;&gt;Pattern 1 — Content Enricher with Redis caching&lt;/h2&gt;

&lt;h3 id=&quot;the-route&quot;&gt;The route&lt;/h3&gt;

&lt;p&gt;The first route enriches incoming order events with customer data.
High-throughput pipelines cannot afford a database call for every message, so the customer lookup is cached in Redis with a 10-minute TTL.&lt;/p&gt;

&lt;h4 id=&quot;quarkus&quot;&gt;Quarkus&lt;/h4&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@ApplicationScoped&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;CachingEnricherRoute&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RouteBuilder&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Inject&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;RedisAPI&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;redis&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.placed?brokers={{kafka.brokers}}&amp;amp;groupId=redis-enricher&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cached-enrichment&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;unmarshal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;enrichFromCache&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Enriched order ${body[order_id]}: customer=${body[customer_name]}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;marshal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.enriched?brokers={{kafka.brokers}}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;enrichFromCache&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Exchange&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;order&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getIn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getBody&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customerId&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;valueOf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;customer_id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cacheKey&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;customer:&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customerId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;Response&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cached&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;redis&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cacheKey&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;indefinitely&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cached&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;customer_name&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cached&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;());&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cache_hit&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;c1&quot;&gt;// Cache miss: perform lookup and populate cache&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customerName&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Customer &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customerId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;customer_name&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customerName&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cache_hit&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;c1&quot;&gt;// Cache for 10 minutes&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;redis&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;setex&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cacheKey&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;600&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customerName&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;indefinitely&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;spring-boot&quot;&gt;Spring Boot&lt;/h4&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@Component&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;CachingEnricherRoute&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RouteBuilder&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Autowired&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;StringRedisTemplate&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;redisTemplate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.placed?brokers={{kafka.brokers}}&amp;amp;groupId=redis-enricher&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cached-enrichment&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;unmarshal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;enrichFromCache&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Enriched order ${body[order_id]}: customer=${body[customer_name]}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;marshal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.enriched?brokers={{kafka.brokers}}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;enrichFromCache&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Exchange&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;order&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getIn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getBody&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customerId&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;valueOf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;customer_id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cacheKey&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;customer:&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customerId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cached&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;redisTemplate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;opsForValue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cacheKey&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cached&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;customer_name&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cached&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cache_hit&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customerName&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Customer &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customerId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;customer_name&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customerName&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cache_hit&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;redisTemplate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;opsForValue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cacheKey&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customerName&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Duration&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;ofSeconds&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;600&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The route logic is identical between runtimes.
The only difference is the Redis client: Quarkus uses the Vert.x Mutiny &lt;code class=&quot;highlighter-rouge&quot;&gt;RedisAPI&lt;/code&gt; injected via CDI, while Spring Boot uses &lt;code class=&quot;highlighter-rouge&quot;&gt;StringRedisTemplate&lt;/code&gt; from Spring Data Redis.
In both cases, the cache-aside pattern is the same: attempt a Redis &lt;code class=&quot;highlighter-rouge&quot;&gt;GET&lt;/code&gt;, serve the cached value if present (and mark &lt;code class=&quot;highlighter-rouge&quot;&gt;cache_hit: true&lt;/code&gt;), otherwise perform the lookup and write the result to Redis with a &lt;code class=&quot;highlighter-rouge&quot;&gt;SETEX&lt;/code&gt; for TTL-bounded expiration.&lt;/p&gt;

&lt;p&gt;The enriched order — now carrying &lt;code class=&quot;highlighter-rouge&quot;&gt;customer_name&lt;/code&gt; and a &lt;code class=&quot;highlighter-rouge&quot;&gt;cache_hit&lt;/code&gt; flag — is serialized back to JSON and forwarded to &lt;code class=&quot;highlighter-rouge&quot;&gt;eip.orders.enriched&lt;/code&gt;.
The &lt;code class=&quot;highlighter-rouge&quot;&gt;cache_hit&lt;/code&gt; field is not a production concern; it exists specifically to make the caching behavior visible to tests.&lt;/p&gt;

&lt;h3 id=&quot;the-tests&quot;&gt;The tests&lt;/h3&gt;

&lt;p&gt;The caching enricher requires two test methods that must run in order.
The first sends an order for a customer that has never been seen — a cache miss.
The second sends a different order for the &lt;em&gt;same&lt;/em&gt; customer — a cache hit.
Because Redis state is shared between test executions within the same suite, the second method can only prove a cache hit if the first method ran first and populated the cache.
&lt;code class=&quot;highlighter-rouge&quot;&gt;@TestClassOrder&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;@Order&lt;/code&gt; annotations enforce this dependency.&lt;/p&gt;

&lt;h4 id=&quot;quarkus-1&quot;&gt;Quarkus&lt;/h4&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@QuarkusTest&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@CitrusSupport&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@TestClassOrder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ClassOrderer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;OrderAnnotation&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;EipTests&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;implements&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;EipTestSupport&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@CitrusResource&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;TestCaseRunner&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Inject&lt;/span&gt;
    &lt;span class=&quot;nd&quot;&gt;@BindToRegistry&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;CamelContext&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Nested&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;CachingEnricherTest&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

        &lt;span class=&quot;nd&quot;&gt;@Test&lt;/span&gt;
        &lt;span class=&quot;nd&quot;&gt;@Order&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;shouldEnrichOrderWithCacheMiss&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;given&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;waitForCamelRouteStarted&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cached-enrichment&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.placed&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;{\&quot;order_id\&quot;: 1001, \&quot;customer_id\&quot;: \&quot;C-101\&quot;, &quot;&lt;/span&gt;
                        &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;\&quot;item_sku\&quot;: \&quot;SKU-R1\&quot;, \&quot;quantity\&quot;: 2, \&quot;amount\&quot;: 49.99}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;header&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;KafkaMessageHeaders&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;MESSAGE_KEY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;ORDER-1001&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;repeatOnError&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;times&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;actions&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                        &lt;span class=&quot;n&quot;&gt;receive&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.enriched&quot;&lt;/span&gt;
                                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;?consumerGroup=citrus-enriched-cache-miss-group&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&quot;&quot;
                            {
                              &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;order_id&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: 1001,
                              &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;customer_id&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;101&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;,
                              &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;item_sku&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SKU&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;R1&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;,
                              &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;quantity&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: 2,
                              &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;amount&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: 49.99,
                              &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;customer_name&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Customer&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;101&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;,
                              &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cache_hit&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: false
                            }
                            &quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;nd&quot;&gt;@Test&lt;/span&gt;
        &lt;span class=&quot;nd&quot;&gt;@Order&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;shouldEnrichOrderWithCacheHit&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;given&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;waitForCamelRouteStarted&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cached-enrichment&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.placed&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;{\&quot;order_id\&quot;: 1002, \&quot;customer_id\&quot;: \&quot;C-101\&quot;, &quot;&lt;/span&gt;
                        &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;\&quot;item_sku\&quot;: \&quot;SKU-R2\&quot;, \&quot;quantity\&quot;: 1, \&quot;amount\&quot;: 29.99}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;header&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;KafkaMessageHeaders&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;MESSAGE_KEY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;ORDER-1002&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;repeatOnError&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;times&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;actions&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                        &lt;span class=&quot;n&quot;&gt;receive&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.enriched&quot;&lt;/span&gt;
                                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;?consumerGroup=citrus-enriched-cache-hit-group&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&quot;&quot;
                            {
                              &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;order_id&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: 1002,
                              &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;customer_id&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;101&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;,
                              &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;item_sku&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SKU&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;R2&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;,
                              &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;quantity&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: 1,
                              &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;amount&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: 29.99,
                              &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;customer_name&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Customer&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;101&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;,
                              &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cache_hit&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: true
                            }
                            &quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;shouldEnrichOrderWithCacheMiss&lt;/code&gt;&lt;/strong&gt; sends order 1001 for customer &lt;code class=&quot;highlighter-rouge&quot;&gt;C-101&lt;/code&gt;.
This customer has never been looked up, so the Redis &lt;code class=&quot;highlighter-rouge&quot;&gt;GET&lt;/code&gt; returns nothing and the route falls through to the simulated database lookup.
The enriched output on &lt;code class=&quot;highlighter-rouge&quot;&gt;eip.orders.enriched&lt;/code&gt; must contain &lt;code class=&quot;highlighter-rouge&quot;&gt;&quot;cache_hit&quot;: false&lt;/code&gt; — proving the cache was not consulted.
The &lt;code class=&quot;highlighter-rouge&quot;&gt;customer_name&lt;/code&gt; field &lt;code class=&quot;highlighter-rouge&quot;&gt;&quot;Customer C-101&quot;&lt;/code&gt; is the result of the simulated lookup and is now stored in Redis under the key &lt;code class=&quot;highlighter-rouge&quot;&gt;customer:C-101&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;shouldEnrichOrderWithCacheHit&lt;/code&gt;&lt;/strong&gt; sends a different order — order 1002 — but for the same customer &lt;code class=&quot;highlighter-rouge&quot;&gt;C-101&lt;/code&gt;.
This time, the Redis &lt;code class=&quot;highlighter-rouge&quot;&gt;GET&lt;/code&gt; on &lt;code class=&quot;highlighter-rouge&quot;&gt;customer:C-101&lt;/code&gt; returns the cached value from the first test.
The enriched output must contain &lt;code class=&quot;highlighter-rouge&quot;&gt;&quot;cache_hit&quot;: true&lt;/code&gt;, confirming the route served the customer name directly from Redis without performing another lookup.&lt;/p&gt;

&lt;p&gt;Each test uses a distinct Kafka consumer group (&lt;code class=&quot;highlighter-rouge&quot;&gt;citrus-enriched-cache-miss-group&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;citrus-enriched-cache-hit-group&lt;/code&gt;).
Without this isolation, a single consumer group tracking offsets across both tests could cause the second &lt;code class=&quot;highlighter-rouge&quot;&gt;receive()&lt;/code&gt; call to pick up the message produced by the first test.&lt;/p&gt;

&lt;h4 id=&quot;spring-boot-1&quot;&gt;Spring Boot&lt;/h4&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@SpringBootTest&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;classes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RedisIntegrationApplication&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;webEnvironment&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SpringBootTest&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;WebEnvironment&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;DEFINED_PORT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@CamelSpringBootTest&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@CitrusSpringSupport&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@ContextConfiguration&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;classes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;EipInfraSetup&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CitrusSpringConfig&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;})&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@TestClassOrder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ClassOrderer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;OrderAnnotation&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;EipTests&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;implements&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;EipTestSupport&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Autowired&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;CamelContext&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Nested&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;CachingEnricherTest&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

        &lt;span class=&quot;nd&quot;&gt;@CitrusResource&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;TestCaseRunner&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;nd&quot;&gt;@Test&lt;/span&gt;
        &lt;span class=&quot;nd&quot;&gt;@Order&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;shouldEnrichOrderWithCacheMiss&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// Identical test logic — only the customer_id differs (C-201 instead of C-101)&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// to avoid cross-runtime state collision when both test suites are run together&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;nd&quot;&gt;@Test&lt;/span&gt;
        &lt;span class=&quot;nd&quot;&gt;@Order&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;shouldEnrichOrderWithCacheHit&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// Same structure as the Quarkus test; verifies cache_hit: true for C-201&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The test logic is identical to the Quarkus version.
Differences are limited to the class-level annotations (&lt;code class=&quot;highlighter-rouge&quot;&gt;@SpringBootTest&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;@CamelSpringBootTest&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;@CitrusSpringSupport&lt;/code&gt;) and the &lt;code class=&quot;highlighter-rouge&quot;&gt;TestCaseRunner&lt;/code&gt; injection point, which moves from a class-level field to nested class fields because Spring Boot’s test context wires &lt;code class=&quot;highlighter-rouge&quot;&gt;@CitrusResource&lt;/code&gt; per nested class.
The Spring Boot tests use customer &lt;code class=&quot;highlighter-rouge&quot;&gt;C-201&lt;/code&gt; instead of &lt;code class=&quot;highlighter-rouge&quot;&gt;C-101&lt;/code&gt; to avoid Redis key collisions if both test suites are run against the same Redis instance.&lt;/p&gt;

&lt;h2 id=&quot;pattern-2--idempotent-receiver-with-redis-deduplication&quot;&gt;Pattern 2 — Idempotent Receiver with Redis deduplication&lt;/h2&gt;

&lt;h3 id=&quot;the-route-1&quot;&gt;The route&lt;/h3&gt;

&lt;p&gt;The second route receives payment events from a Kafka topic and deduplicates them using Redis.
Each event carries an &lt;code class=&quot;highlighter-rouge&quot;&gt;event_id&lt;/code&gt;.
The route uses Redis’s &lt;code class=&quot;highlighter-rouge&quot;&gt;SET NX EX&lt;/code&gt; command as a distributed &lt;code class=&quot;highlighter-rouge&quot;&gt;setIfAbsent&lt;/code&gt; operation: if the key &lt;code class=&quot;highlighter-rouge&quot;&gt;idempotent:&amp;lt;event_id&amp;gt;&lt;/code&gt; does not yet exist, it is created with a 24-hour TTL and the event is processed normally.
If the key already exists, the event is a duplicate and is routed to a dead-end &lt;code class=&quot;highlighter-rouge&quot;&gt;handle-duplicate-payment&lt;/code&gt; route.&lt;/p&gt;

&lt;h4 id=&quot;quarkus-2&quot;&gt;Quarkus&lt;/h4&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@ApplicationScoped&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;IdempotentReceiverRoute&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RouteBuilder&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Inject&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;RedisAPI&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;redis&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.payments?brokers={{kafka.brokers}}&amp;amp;groupId=redis-idempotent&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;idempotent-receiver&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;unmarshal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;deduplicateAndProcess&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;choice&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;header&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;CamelDuplicate&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;isEqualTo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;direct:handle-duplicate-payment&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;otherwise&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Processing payment event ${body[event_id]} for order ${body[order_id]}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;marshal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.payment-confirmed?brokers={{kafka.brokers}}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;direct:handle-duplicate-payment&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;handle-duplicate-payment&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Duplicate payment event ${body[event_id]} -- skipping&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;deduplicateAndProcess&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Exchange&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;event&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getIn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getBody&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eventId&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;valueOf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;event_id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dedupeKey&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;idempotent:&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eventId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;c1&quot;&gt;// SET NX with a 24-hour TTL — returns null if the key already exists&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;Response&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;redis&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;of&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dedupeKey&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;1&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;NX&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;EX&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;86400&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;indefinitely&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;

        &lt;span class=&quot;kt&quot;&gt;boolean&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;isDuplicate&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getIn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;setHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;CamelDuplicate&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;isDuplicate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;spring-boot-2&quot;&gt;Spring Boot&lt;/h4&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@Component&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;IdempotentReceiverRoute&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RouteBuilder&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Autowired&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;StringRedisTemplate&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;redisTemplate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.payments?brokers={{kafka.brokers}}&amp;amp;groupId=redis-idempotent&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;idempotent-receiver&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;unmarshal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;deduplicateAndProcess&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;choice&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;header&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;CamelDuplicate&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;isEqualTo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;direct:handle-duplicate-payment&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;otherwise&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Processing payment event ${body[event_id]} for order ${body[order_id]}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;marshal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.payment-confirmed?brokers={{kafka.brokers}}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;direct:handle-duplicate-payment&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;handle-duplicate-payment&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Duplicate payment event ${body[event_id]} -- skipping&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;deduplicateAndProcess&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Exchange&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;event&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getIn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getBody&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eventId&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;valueOf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;event_id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dedupeKey&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;idempotent:&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eventId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;c1&quot;&gt;// SET NX with a 24-hour TTL — returns false if the key already exists&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;Boolean&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;wasSet&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;redisTemplate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;opsForValue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;setIfAbsent&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dedupeKey&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;1&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Duration&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;ofSeconds&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;86400&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;

        &lt;span class=&quot;kt&quot;&gt;boolean&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;isDuplicate&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Boolean&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;equals&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;wasSet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getIn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;setHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;CamelDuplicate&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;isDuplicate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The two implementations are semantically identical.
In Quarkus, &lt;code class=&quot;highlighter-rouge&quot;&gt;redis.set(List.of(dedupeKey, &quot;1&quot;, &quot;NX&quot;, &quot;EX&quot;, &quot;86400&quot;))&lt;/code&gt; returns &lt;code class=&quot;highlighter-rouge&quot;&gt;null&lt;/code&gt; when the key already exists.
In Spring Boot, &lt;code class=&quot;highlighter-rouge&quot;&gt;redisTemplate.opsForValue().setIfAbsent(...)&lt;/code&gt; returns &lt;code class=&quot;highlighter-rouge&quot;&gt;false&lt;/code&gt; when the key already exists.
Both implementations set the &lt;code class=&quot;highlighter-rouge&quot;&gt;CamelDuplicate&lt;/code&gt; header to &lt;code class=&quot;highlighter-rouge&quot;&gt;true&lt;/code&gt; for duplicates, which the &lt;code class=&quot;highlighter-rouge&quot;&gt;choice()&lt;/code&gt; EIP then routes to &lt;code class=&quot;highlighter-rouge&quot;&gt;handle-duplicate-payment&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Routing duplicates to a named dead-end route — rather than simply filtering them with a &lt;code class=&quot;highlighter-rouge&quot;&gt;filter()&lt;/code&gt; — is a deliberate design choice that makes the duplicate count visible through Camel’s route statistics.
This is what the tests exploit.&lt;/p&gt;

&lt;h3 id=&quot;the-tests-1&quot;&gt;The tests&lt;/h3&gt;

&lt;p&gt;The idempotent receiver test suite requires two methods that run in a fixed order, using &lt;code class=&quot;highlighter-rouge&quot;&gt;@TestMethodOrder&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;@Order&lt;/code&gt;.
The first test sends a new event and verifies it is forwarded.
The second re-sends the &lt;em&gt;same&lt;/em&gt; event and verifies that the route silently drops it.&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@Nested&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@TestMethodOrder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;MethodOrderer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;OrderAnnotation&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;IdempotentReceiverTest&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Test&lt;/span&gt;
    &lt;span class=&quot;nd&quot;&gt;@Order&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;shouldProcessNewPaymentEvent&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;given&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;waitForCamelRouteStarted&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;idempotent-receiver&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.payments&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;{\&quot;event_id\&quot;: \&quot;EVT-2001\&quot;, \&quot;order_id\&quot;: 2001, \&quot;amount\&quot;: 149.99}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;header&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;KafkaMessageHeaders&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;MESSAGE_KEY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;PAY-2001&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;repeatOnError&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;times&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;actions&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                    &lt;span class=&quot;n&quot;&gt;receive&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                        &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.payment-confirmed&quot;&lt;/span&gt;
                            &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;?consumerGroup=citrus-payment-confirmed-group&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                        &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                        &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&quot;&quot;
                        {
                          &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;event_id&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;EVT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2001&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;,
                          &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;order_id&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: 2001,
                          &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;amount&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: 149.99
                        }
                        &quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Test&lt;/span&gt;
    &lt;span class=&quot;nd&quot;&gt;@Order&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;shouldDropDuplicatePaymentEvent&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;given&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;waitForCamelRouteStarted&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;idempotent-receiver&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.payments&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;{\&quot;event_id\&quot;: \&quot;EVT-2001\&quot;, \&quot;order_id\&quot;: 2001, \&quot;amount\&quot;: 149.99}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;header&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;KafkaMessageHeaders&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;MESSAGE_KEY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;PAY-2001-DUP&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;verifyCompletedExchanges&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;handle-duplicate-payment&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;shouldProcessNewPaymentEvent&lt;/code&gt;&lt;/strong&gt; sends event &lt;code class=&quot;highlighter-rouge&quot;&gt;EVT-2001&lt;/code&gt; for the first time.
The Redis &lt;code class=&quot;highlighter-rouge&quot;&gt;SET NX&lt;/code&gt; succeeds — the key &lt;code class=&quot;highlighter-rouge&quot;&gt;idempotent:EVT-2001&lt;/code&gt; is created and the event is forwarded to &lt;code class=&quot;highlighter-rouge&quot;&gt;eip.orders.payment-confirmed&lt;/code&gt;.
The &lt;code class=&quot;highlighter-rouge&quot;&gt;receive()&lt;/code&gt; block with &lt;code class=&quot;highlighter-rouge&quot;&gt;repeatOnError()&lt;/code&gt; polls the topic up to 20 times, succeeding as soon as the confirmed message appears.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;shouldDropDuplicatePaymentEvent&lt;/code&gt;&lt;/strong&gt; re-sends the exact same event body with a different Kafka message key (&lt;code class=&quot;highlighter-rouge&quot;&gt;PAY-2001-DUP&lt;/code&gt; instead of &lt;code class=&quot;highlighter-rouge&quot;&gt;PAY-2001&lt;/code&gt; — the Kafka key has no bearing on deduplication, only &lt;code class=&quot;highlighter-rouge&quot;&gt;event_id&lt;/code&gt; matters).
The Redis &lt;code class=&quot;highlighter-rouge&quot;&gt;SET NX&lt;/code&gt; fails this time because &lt;code class=&quot;highlighter-rouge&quot;&gt;idempotent:EVT-2001&lt;/code&gt; already exists from the previous test.
The route sets &lt;code class=&quot;highlighter-rouge&quot;&gt;CamelDuplicate: true&lt;/code&gt; and routes the exchange to &lt;code class=&quot;highlighter-rouge&quot;&gt;direct:handle-duplicate-payment&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The assertion for the duplicate test is &lt;code class=&quot;highlighter-rouge&quot;&gt;verifyCompletedExchanges(&quot;handle-duplicate-payment&quot;, 1, camelContext)&lt;/code&gt;.
This polls Camel’s internal route statistics and passes only when the &lt;code class=&quot;highlighter-rouge&quot;&gt;handle-duplicate-payment&lt;/code&gt; route has completed exactly one exchange.
This approach is cleaner than using &lt;code class=&quot;highlighter-rouge&quot;&gt;expectTimeout()&lt;/code&gt; on the output Kafka topic because it directly measures what the route did rather than waiting for an absence of output.
It also avoids adding unnecessary wait time to the test suite.
Both &lt;code class=&quot;highlighter-rouge&quot;&gt;waitForCamelRouteStarted&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;verifyCompletedExchanges&lt;/code&gt; are shared utilities provided by the &lt;code class=&quot;highlighter-rouge&quot;&gt;EipTestSupport&lt;/code&gt; interface — see the &lt;a href=&quot;/samples/camel-eip/&quot;&gt;Camel EIP examples&lt;/a&gt; overview page for their implementation.&lt;/p&gt;

&lt;h2 id=&quot;understanding-the-redis-deduplication-approach&quot;&gt;Understanding the Redis deduplication approach&lt;/h2&gt;

&lt;p&gt;The custom &lt;code class=&quot;highlighter-rouge&quot;&gt;SET NX EX&lt;/code&gt; approach in these routes takes a slightly different path from Camel’s built-in &lt;code class=&quot;highlighter-rouge&quot;&gt;idempotentConsumer()&lt;/code&gt; EIP.
The built-in EIP uses a &lt;code class=&quot;highlighter-rouge&quot;&gt;RedisIdempotentRepository&lt;/code&gt; that Camel manages internally.
The custom approach gives the route author full control over the key naming scheme, TTL, and the routing decision — including the ability to route duplicates to a named branch for counting and logging rather than simply dropping them silently.&lt;/p&gt;

&lt;p&gt;The TTL is a deliberate design constraint.
A Redis key that never expires would grow the idempotent store indefinitely.
A 24-hour TTL (86400 seconds) bounds memory usage: events that arrive more than 24 hours after their first processing will be treated as new and processed again.
This is acceptable when Kafka’s own retention window is also 24 hours — any message that could arrive as a duplicate would still be within the TTL window.&lt;/p&gt;

&lt;h2 id=&quot;pattern-3--distributed-lock-for-scheduled-tasks&quot;&gt;Pattern 3 — Distributed lock for scheduled tasks&lt;/h2&gt;

&lt;h3 id=&quot;the-route-2&quot;&gt;The route&lt;/h3&gt;

&lt;p&gt;The third route addresses a problem that appears when a Camel service scales horizontally.
A nightly order export should run exactly once per night — not once per instance.
Without coordination, all three replicas of the service would fire the same timer and run the export three times.&lt;/p&gt;

&lt;p&gt;The distributed lock pattern uses Redis’s &lt;code class=&quot;highlighter-rouge&quot;&gt;SET NX EX&lt;/code&gt; as a lease: the first instance to write the lock key wins and runs the task.
The other instances find the key already set, skip their execution, and log a message.&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@ApplicationScoped&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;DistributedLockRoute&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RouteBuilder&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LOCK_KEY&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;lock:nightly-order-export&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LOCK_TTL_SECONDS&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;30&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;instanceId&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;UUID&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;randomUUID&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Inject&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;RedisAPI&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;redis&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;timer:nightly-export?period=60000&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;autoStartup&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;enabled&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;distributed-lock&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tryAcquireLock&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;choice&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;header&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;LockAcquired&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;isEqualTo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Lock acquired by instance &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;instanceId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;runExportTask&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;releaseLock&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Nightly order export complete -- lock released&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;otherwise&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Lock held by another instance -- skipping nightly export&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;tryAcquireLock&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Exchange&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;Response&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;redis&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;of&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LOCK_KEY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;instanceId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;NX&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;EX&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LOCK_TTL_SECONDS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;indefinitely&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getIn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;setHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;LockAcquired&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;runExportTask&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Exchange&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;exportedCount&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;42&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;nanoTime&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getIn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;setBody&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;s&quot;&gt;&quot;{\&quot;task\&quot;: \&quot;nightly-order-export\&quot;, \&quot;exported_count\&quot;: %d, \&quot;instance\&quot;: \&quot;%s\&quot;}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;exportedCount&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;instanceId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;releaseLock&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Exchange&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// Only release if we still own the lock (compare-and-delete)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;Response&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;currentValue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;redis&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LOCK_KEY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;indefinitely&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;currentValue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;instanceId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;equals&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;currentValue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;redis&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;del&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;of&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LOCK_KEY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)).&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;await&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;indefinitely&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The lock value is the &lt;code class=&quot;highlighter-rouge&quot;&gt;instanceId&lt;/code&gt; — a random UUID generated at startup.
After the export completes, &lt;code class=&quot;highlighter-rouge&quot;&gt;releaseLock&lt;/code&gt; reads the current lock value and only deletes the key if it still matches &lt;code class=&quot;highlighter-rouge&quot;&gt;instanceId&lt;/code&gt;.
This compare-and-delete prevents a stale instance from releasing a lock that has already been re-acquired by another instance after a TTL expiry.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;autoStartup(enabled)&lt;/code&gt; flag allows the distributed lock route to be disabled in tests via a configuration property (&lt;code class=&quot;highlighter-rouge&quot;&gt;eip.distributed.lock.enabled=false&lt;/code&gt;).
This is important because the timer fires every 60 seconds — in an automated test suite, you do not want a background timer interfering with assertions that rely on route statistics.&lt;/p&gt;

&lt;h2 id=&quot;why-redis-integration-tests-are-harder-than-they-look&quot;&gt;Why Redis integration tests are harder than they look&lt;/h2&gt;

&lt;h3 id=&quot;cache-behavior-is-stateful-and-ordered&quot;&gt;Cache behavior is stateful and ordered&lt;/h3&gt;

&lt;p&gt;Testing a cache requires two messages sent to the same consumer group in a specific order.
The first message primes the cache; the second proves it.
If the test framework ran them in parallel or in an unpredictable order, the second test could either see a cache miss (if the first has not yet completed) or always see a cache hit (if the Redis state from a previous test run is still present).&lt;/p&gt;

&lt;p&gt;Citrus’s &lt;code class=&quot;highlighter-rouge&quot;&gt;@TestClassOrder&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;@Order&lt;/code&gt; annotations enforce execution order.
The &lt;code class=&quot;highlighter-rouge&quot;&gt;repeatOnError()&lt;/code&gt; wrapper ensures the first test does not complete until the enriched message is confirmed on the output topic — guaranteeing that the cache is warm before the second test starts.&lt;/p&gt;

&lt;h3 id=&quot;verifying-duplicate-suppression-requires-route-statistics&quot;&gt;Verifying duplicate suppression requires route statistics&lt;/h3&gt;

&lt;p&gt;Proving that a duplicate was dropped is a negative assertion: you need to confirm that &lt;em&gt;no&lt;/em&gt; output was produced.
There are two ways to verify this with Citrus.
The &lt;code class=&quot;highlighter-rouge&quot;&gt;expectTimeout()&lt;/code&gt; approach waits for a specified duration and fails if a message arrives.
The &lt;code class=&quot;highlighter-rouge&quot;&gt;verifyCompletedExchanges&lt;/code&gt; approach checks Camel’s internal route statistics to confirm a specific route was invoked.&lt;/p&gt;

&lt;p&gt;The route statistics approach is preferred here because the &lt;code class=&quot;highlighter-rouge&quot;&gt;handle-duplicate-payment&lt;/code&gt; route represents a positive claim: the duplicate &lt;em&gt;was&lt;/em&gt; processed — it was routed to a specific named branch.
Verifying completed exchange count is faster than waiting for a timeout and makes the test’s intent explicit.&lt;/p&gt;

&lt;h3 id=&quot;ttl-bounded-deduplication-requires-care-with-test-isolation&quot;&gt;TTL-bounded deduplication requires care with test isolation&lt;/h3&gt;

&lt;p&gt;Because Redis keys expire, the test must run within the key’s TTL window — which is never a problem for 24-hour TTLs.
But shorter TTLs in distributed lock tests (30 seconds in the example) can cause intermittent failures if the test takes longer than expected.
The distributed lock route uses &lt;code class=&quot;highlighter-rouge&quot;&gt;autoStartup(enabled)&lt;/code&gt; to disable itself during tests, avoiding uncontrolled timer firings that could compete with a lock held by the test.&lt;/p&gt;

&lt;p&gt;For the test infrastructure setup, shared test utilities, runtime wiring, dependencies, and how to run the tests, see the &lt;a href=&quot;/samples/camel-eip/&quot;&gt;Camel EIP examples&lt;/a&gt; overview page.&lt;/p&gt;

&lt;h2 id=&quot;key-takeaways&quot;&gt;Key takeaways&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Redis serves multiple roles in an integration layer — and each role needs a different test strategy.&lt;/strong&gt; Caching requires ordered, stateful tests that verify both a miss and a subsequent hit. Deduplication requires proving a negative — that a duplicate was absorbed and not forwarded. Distributed locking requires disabling the timer route during tests to prevent background interference.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;verifyCompletedExchanges&lt;/code&gt; is a cleaner alternative to &lt;code class=&quot;highlighter-rouge&quot;&gt;expectTimeout()&lt;/code&gt; for negative assertions.&lt;/strong&gt; Routing duplicates to a named &lt;code class=&quot;highlighter-rouge&quot;&gt;handle-duplicate-payment&lt;/code&gt; route makes the drop count visible through Camel’s route statistics. Checking that count is faster and more expressive than waiting for an absence of output on a Kafka topic.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;SET NX EX&lt;/code&gt; pattern is a portable distributed primitive.&lt;/strong&gt; Both the idempotent receiver and the distributed lock use &lt;code class=&quot;highlighter-rouge&quot;&gt;SET NX EX&lt;/code&gt; as their core Redis operation. Quarkus and Spring Boot expose it through different client APIs — &lt;code class=&quot;highlighter-rouge&quot;&gt;redis.set(List.of(...))&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;redisTemplate.opsForValue().setIfAbsent(...)&lt;/code&gt; — but the semantics are identical.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test-ordered execution is necessary for stateful integration tests.&lt;/strong&gt; Cache hit tests depend on cache miss tests having completed successfully. JUnit 5’s &lt;code class=&quot;highlighter-rouge&quot;&gt;@TestClassOrder&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;@Order&lt;/code&gt; annotations, combined with Citrus’s &lt;code class=&quot;highlighter-rouge&quot;&gt;repeatOnError()&lt;/code&gt; for readiness checks, make this dependency explicit and reliable.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Disable timer-driven routes in tests.&lt;/strong&gt; Routes that fire on a schedule — like the distributed lock route — should support a configuration flag to disable them during test execution. Without this, background timer firings can increment route statistics and invalidate exchange count assertions.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Two runtimes, one test structure.&lt;/strong&gt; Whether you run on Quarkus or Spring Boot, the test shape — &lt;code class=&quot;highlighter-rouge&quot;&gt;given&lt;/code&gt; infrastructure, &lt;code class=&quot;highlighter-rouge&quot;&gt;when&lt;/code&gt; stimulus, &lt;code class=&quot;highlighter-rouge&quot;&gt;then&lt;/code&gt; assertion — stays the same. The only differences are class-level annotations and the injection mechanism for &lt;code class=&quot;highlighter-rouge&quot;&gt;CamelContext&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;TestCaseRunner&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;</content><author><name></name></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://citrusframework.org/img/icons/camel.png" /></entry><entry><title type="html">Testing Apache Pulsar Routes with Citrus</title><link href="https://citrusframework.org/samples/camel-pulsar-deep-dive/" rel="alternate" type="text/html" title="Testing Apache Pulsar Routes with Citrus" /><published>2026-09-24T00:00:00+02:00</published><updated>2026-09-24T00:00:00+02:00</updated><id>https://citrusframework.org/samples/sample-eip-pulsar-deep-dive</id><content type="html" xml:base="https://citrusframework.org/samples/camel-pulsar-deep-dive/">&lt;p&gt;Apache Pulsar offers a set of capabilities that Kafka simply does not have out of the box: per-message TTL enforced at the broker, key-shared subscriptions that guarantee per-key ordering without requiring partitions, and a built-in schema registry.
These features make Pulsar an attractive fit for certain integration scenarios — but they also introduce new testing challenges.
When your Camel route relies on Pulsar-specific subscription semantics, how do you write automated integration tests that actually exercise those behaviors?&lt;/p&gt;

&lt;p&gt;This post walks through three Camel route patterns built on top of Apache Pulsar, and shows how to test each one with &lt;a href=&quot;https://citrusframework.org&quot;&gt;Citrus&lt;/a&gt; across both Quarkus and Spring Boot runtimes.
The three scenarios are: a Shared subscription for competing-consumer order processing, a Key_Shared subscription for ordered per-key processing, and a Dead Letter Topic (DLT) pipeline that captures messages that exhaust all redelivery attempts.
Each scenario is backed by real Pulsar infrastructure spun up with Docker Compose via Testcontainers — no mocks, no stubs, no embedded broker.&lt;/p&gt;

&lt;h1 id=&quot;what-makes-pulsar-different-for-testing&quot;&gt;What makes Pulsar different for testing&lt;/h1&gt;

&lt;p&gt;Before diving into the code, a brief word on what sets Pulsar apart from Kafka — and why that matters for integration tests.&lt;/p&gt;

&lt;p&gt;Pulsar separates the concept of &lt;em&gt;consumers&lt;/em&gt; from &lt;em&gt;subscriptions&lt;/em&gt;.
In Kafka, a consumer group is the mechanism for load-balancing and offset tracking; parallelism is tied to partitions.
In Pulsar, a &lt;em&gt;subscription&lt;/em&gt; carries the cursor, and the &lt;em&gt;subscription type&lt;/em&gt; determines how messages are dispatched among the consumers sharing that subscription:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Subscription type&lt;/th&gt;
      &lt;th&gt;Behavior&lt;/th&gt;
      &lt;th&gt;Testing concern&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Exclusive&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Single consumer only&lt;/td&gt;
      &lt;td&gt;Simplest to test — one consumer, one message stream&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Shared&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Round-robin across consumers&lt;/td&gt;
      &lt;td&gt;Must verify processing happens regardless of which consumer instance receives the message&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Key_Shared&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Same key always routes to same consumer&lt;/td&gt;
      &lt;td&gt;Must verify that all messages for a given key are processed in order by a single consumer instance&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Failover&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;One active consumer, others on standby&lt;/td&gt;
      &lt;td&gt;Must verify promotion behavior on consumer loss&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Another Pulsar-specific feature is the &lt;strong&gt;Dead Letter Topic&lt;/strong&gt; (DLT).
When a consumer fails to acknowledge a message within a configurable number of redelivery attempts (&lt;code class=&quot;highlighter-rouge&quot;&gt;maxRedeliverCount&lt;/code&gt;), Pulsar automatically moves the message to a designated dead-letter topic.
Testing this end-to-end — message enters, processing fails, retries exhaust, message appears on the DLT — requires real broker behavior.&lt;/p&gt;

&lt;p&gt;The example project uses Apache Camel and contains three route builders, each demonstrating a distinct Pulsar capability.&lt;/p&gt;

&lt;h1 id=&quot;shared-subscription&quot;&gt;Shared subscription&lt;/h1&gt;

&lt;h2 id=&quot;the-camel-route&quot;&gt;The Camel route&lt;/h2&gt;

&lt;p&gt;The first route publishes orders to a persistent Pulsar topic and consumes them with a &lt;code class=&quot;highlighter-rouge&quot;&gt;Shared&lt;/code&gt; subscription using two concurrent consumer threads.
Any order can be received by any consumer instance, which is the standard competing-consumer pattern.&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Quarkus&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@ApplicationScoped&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;SharedSubscriptionRoute&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RouteBuilder&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;pulsar:persistent://public/default/eip.orders.placed&quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;?subscriptionName=inventory-service&quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&amp;amp;subscriptionType=Shared&quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&amp;amp;numberOfConsumers=2&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;pulsar-shared-consumer&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Shared consumer received: ${body}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;direct:process-pulsar-order&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;direct:process-pulsar-order&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;pulsar-order-processor&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Processing Pulsar order&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;On Spring Boot, &lt;code class=&quot;highlighter-rouge&quot;&gt;@ApplicationScoped&lt;/code&gt; is replaced with &lt;code class=&quot;highlighter-rouge&quot;&gt;@Component&lt;/code&gt; and the config property is injected with &lt;code class=&quot;highlighter-rouge&quot;&gt;@Value&lt;/code&gt; instead of &lt;code class=&quot;highlighter-rouge&quot;&gt;@ConfigProperty&lt;/code&gt;.
The route logic is identical across both runtimes.&lt;/p&gt;

&lt;p&gt;The key points here are &lt;code class=&quot;highlighter-rouge&quot;&gt;subscriptionType=Shared&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;numberOfConsumers=2&lt;/code&gt;.
Shared subscriptions distribute messages round-robin across all consumers sharing the same subscription name.
Because the number of consumers exceeds one, you cannot predict which consumer thread will receive any particular message — but you &lt;em&gt;can&lt;/em&gt; assert that the message was processed by one of them.
This is a subtle but important distinction that shapes how the Citrus test is structured, as we will see shortly.&lt;/p&gt;

&lt;h2 id=&quot;testing-the-shared-subscription&quot;&gt;Testing the Shared subscription&lt;/h2&gt;

&lt;p&gt;The Shared subscription test sends an order message directly to the Pulsar topic using Citrus’s Camel endpoint DSL, then verifies that the &lt;code class=&quot;highlighter-rouge&quot;&gt;pulsar-order-processor&lt;/code&gt; route processed at least one exchange successfully.&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@Test&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;shouldProcessOrderWithSharedSubscription&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;given&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;waitForCamelRouteStarted&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;pulsar-shared-consumer&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;camel&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CamelSupport&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;camel&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoints&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;pulsar&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;persistent://public/default/eip.orders.placed&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;serviceUrl&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;pulsar://localhost:6650&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;producerName&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;citrus-shared-sub-test&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getRawUri&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;{\&quot;order_id\&quot;: 2001, \&quot;customer_id\&quot;: \&quot;C-001\&quot;, &quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;\&quot;item_sku\&quot;: \&quot;SKU-P1\&quot;, \&quot;quantity\&quot;: 2, \&quot;amount\&quot;: 49.99}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;verifyCompletedExchanges&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;pulsar-order-processor&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;A few things to notice about this test.&lt;/p&gt;

&lt;p&gt;First, Citrus sends the message via the Camel Pulsar endpoint using &lt;code class=&quot;highlighter-rouge&quot;&gt;camel().send()&lt;/code&gt;.
This uses the same &lt;code class=&quot;highlighter-rouge&quot;&gt;camel-pulsar&lt;/code&gt; component that the application routes use — Citrus does not need a separate Pulsar client library; it borrows the application’s Camel context to produce the message.
The &lt;code class=&quot;highlighter-rouge&quot;&gt;producerName&lt;/code&gt; is explicitly set to avoid producer name conflicts with the application’s own producers.&lt;/p&gt;

&lt;p&gt;Second, the verification uses &lt;code class=&quot;highlighter-rouge&quot;&gt;verifyCompletedExchanges&lt;/code&gt; rather than a &lt;code class=&quot;highlighter-rouge&quot;&gt;receive()&lt;/code&gt; action.
Because the route routes the processed message to &lt;code class=&quot;highlighter-rouge&quot;&gt;direct:process-pulsar-order&lt;/code&gt; and then logs it, there is no output topic to consume from.
Instead, the test checks the JMX statistics of the &lt;code class=&quot;highlighter-rouge&quot;&gt;pulsar-order-processor&lt;/code&gt; route to confirm that at least one exchange was completed without failures.
This approach is particularly well-suited to &lt;code class=&quot;highlighter-rouge&quot;&gt;Shared&lt;/code&gt; subscriptions, where you care that &lt;em&gt;some&lt;/em&gt; consumer processed the message, not &lt;em&gt;which&lt;/em&gt; one.&lt;/p&gt;

&lt;h1 id=&quot;key_shared-subscription&quot;&gt;Key_Shared subscription&lt;/h1&gt;

&lt;h2 id=&quot;the-camel-route-1&quot;&gt;The Camel route&lt;/h2&gt;

&lt;p&gt;The second route uses a Key_Shared subscription to enforce per-key ordering across multiple consumer threads.
Every order message carries a key based on its order ID; Pulsar guarantees that all messages with the same key are always dispatched to the same consumer instance.&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Quarkus&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@ApplicationScoped&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;KeySharedRoute&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RouteBuilder&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;pulsar:persistent://public/default/eip.orders.keyed&quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;?subscriptionName=shipping-service&quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&amp;amp;subscriptionType=Key_Shared&quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&amp;amp;numberOfConsumers=2&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;pulsar-key-shared-consumer&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Key_Shared consumer received order [key=${header[pulsar.producer.message.key]}]: ${body}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;direct:process-keyed-order&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;direct:process-keyed-order&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;pulsar-keyed-order-processor&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;unmarshal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Processing keyed order ${body[order_id]} for customer ${body[customer_id]}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;All events for the same order key route to the same consumer instance&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The message key is communicated to the Pulsar producer via the &lt;code class=&quot;highlighter-rouge&quot;&gt;pulsar.producer.message.key&lt;/code&gt; Camel message header.
Unlike Kafka — where ordering is guaranteed only within a partition, and repartitioning can break key affinity — Pulsar routes by key at the subscription level, independently of how many consumers share the subscription.
Adding or removing consumer instances does not disrupt key affinity.&lt;/p&gt;

&lt;h2 id=&quot;testing-the-key_shared-subscription&quot;&gt;Testing the Key_Shared subscription&lt;/h2&gt;

&lt;p&gt;The Key_Shared test follows the same structure but sets the message key header to ensure the message can be correlated with the correct consumer instance.&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@Test&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;shouldProcessKeyedOrderWithKeySharedSubscription&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;given&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;waitForCamelRouteStarted&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;pulsar-key-shared-consumer&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;camel&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CamelSupport&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;camel&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoints&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;pulsar&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;persistent://public/default/eip.orders.keyed&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;serviceUrl&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;pulsar://localhost:6650&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;producerName&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;citrus-key-shared-test&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getRawUri&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;header&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;pulsar.producer.message.key&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;order-3001&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;{\&quot;order_id\&quot;: 3001, \&quot;customer_id\&quot;: \&quot;C-001\&quot;, &quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;\&quot;item_sku\&quot;: \&quot;SKU-P2\&quot;, \&quot;quantity\&quot;: 3, \&quot;status\&quot;: \&quot;placed\&quot;}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;verifyCompletedExchanges&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;pulsar-keyed-order-processor&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Setting the &lt;code class=&quot;highlighter-rouge&quot;&gt;pulsar.producer.message.key&lt;/code&gt; header is the test-side equivalent of what the production producer route does when it sets &lt;code class=&quot;highlighter-rouge&quot;&gt;exchange.getIn().setHeader(&quot;pulsar.producer.message.key&quot;, key)&lt;/code&gt;.
By using the same header name, the test exercises the complete key routing path: producer attaches the key, Pulsar routes the message to the designated consumer instance for that key, consumer processes it.&lt;/p&gt;

&lt;p&gt;What does this test actually prove?
It verifies that a message with a specific key is received by the &lt;code class=&quot;highlighter-rouge&quot;&gt;pulsar-key-shared-consumer&lt;/code&gt; route and successfully processed by the downstream &lt;code class=&quot;highlighter-rouge&quot;&gt;pulsar-keyed-order-processor&lt;/code&gt;.
In a production scenario with multiple running instances, adding a second test with the same key and verifying sequential ordering would demonstrate the full Key_Shared guarantee.
For the purposes of this example — a single Camel application with two consumer threads — the test confirms the end-to-end path functions correctly without failures.&lt;/p&gt;

&lt;h1 id=&quot;dead-letter-topic&quot;&gt;Dead Letter Topic&lt;/h1&gt;

&lt;h2 id=&quot;the-camel-route-2&quot;&gt;The Camel route&lt;/h2&gt;

&lt;p&gt;The third route exercises Pulsar’s built-in dead-letter handling.
The payment consumer intentionally throws a &lt;code class=&quot;highlighter-rouge&quot;&gt;RuntimeException&lt;/code&gt; for single-item orders (orders where &lt;code class=&quot;highlighter-rouge&quot;&gt;quantity == 1&lt;/code&gt;) to simulate a processing failure.
After three failed redelivery attempts (&lt;code class=&quot;highlighter-rouge&quot;&gt;maxRedeliverCount=3&lt;/code&gt;), Pulsar moves the message to the &lt;code class=&quot;highlighter-rouge&quot;&gt;eip.orders.payments-dlq&lt;/code&gt; topic.
A second route monitors that dead-letter topic.&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Quarkus&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@ApplicationScoped&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;DeadLetterRoute&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RouteBuilder&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;pulsar:persistent://public/default/eip.orders.payments&quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;?subscriptionName=payment-service&quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&amp;amp;subscriptionType=Shared&quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&amp;amp;maxRedeliverCount=3&quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&amp;amp;deadLetterTopic=persistent://public/default/eip.orders.payments-dlq&quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&amp;amp;numberOfConsumers=1&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;pulsar-dlt-consumer&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Processing payment order: ${body}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getIn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getBody&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;contains&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;\&quot;quantity\&quot;: 1,&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
                    &lt;span class=&quot;k&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;RuntimeException&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                        &lt;span class=&quot;s&quot;&gt;&quot;Simulated payment failure for single-item order&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;})&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Payment order processed successfully&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;pulsar:persistent://public/default/eip.orders.payments-dlq&quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;?subscriptionName=dlt-monitor&quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&amp;amp;subscriptionType=Exclusive&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;pulsar-dlt-monitor&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Dead letter topic received failed order: ${body}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Order exhausted all redelivery attempts and requires manual review&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;deadLetterTopic&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;maxRedeliverCount&lt;/code&gt; parameters are pure Pulsar configuration — no application code manages the retry or DLT routing.
This is one of Pulsar’s strongest points for reliability testing: the broker takes care of the dead-letter flow, so the route logic stays clean and the failure path is broker-enforced.&lt;/p&gt;

&lt;h2 id=&quot;testing-valid-payment-processing&quot;&gt;Testing valid payment processing&lt;/h2&gt;

&lt;p&gt;The Dead Letter Topic scenario has two separate test cases.
The first verifies the happy path: a valid payment order (quantity &amp;gt; 1, which does &lt;em&gt;not&lt;/em&gt; trigger the simulated failure) is processed successfully.&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@Test&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;shouldProcessValidPaymentOrder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// quantity=2 does NOT trigger the simulated failure (only quantity=1 does)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;given&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;waitForCamelRouteStarted&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;pulsar-dlt-consumer&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;camel&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CamelSupport&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;camel&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoints&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;pulsar&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;persistent://public/default/eip.orders.payments&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;serviceUrl&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;pulsar://localhost:6650&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;producerName&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;citrus-dlt-test&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getRawUri&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;{\&quot;order_id\&quot;: 4002, \&quot;customer_id\&quot;: \&quot;C-002\&quot;, &quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;\&quot;item_sku\&quot;: \&quot;SKU-P3\&quot;, \&quot;quantity\&quot;: 2, \&quot;amount\&quot;: 39.98}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;verifyCompletedExchanges&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;pulsar-dlt-consumer&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The comment in the test (&lt;code class=&quot;highlighter-rouge&quot;&gt;quantity=2 does NOT trigger the simulated failure&lt;/code&gt;) is important documentation.
It makes the test’s intent explicit: this test specifically exercises the success path.
A reader can immediately see the boundary condition that separates success from failure — &lt;code class=&quot;highlighter-rouge&quot;&gt;quantity=1&lt;/code&gt; fails, everything else succeeds — without having to trace back to the route implementation.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;verifyCompletedExchanges&lt;/code&gt; call verifies both that the exchange completed &lt;em&gt;and&lt;/em&gt; that no failures occurred.
If you accidentally send a &lt;code class=&quot;highlighter-rouge&quot;&gt;quantity=1&lt;/code&gt; order here, the failure assertion in &lt;code class=&quot;highlighter-rouge&quot;&gt;verifyCompletedExchanges&lt;/code&gt; catches it.&lt;/p&gt;

&lt;h1 id=&quot;what-the-exchange-statistics-approach-gives-you&quot;&gt;What the exchange statistics approach gives you&lt;/h1&gt;

&lt;p&gt;Throughout these tests, a recurring pattern is the use of &lt;code class=&quot;highlighter-rouge&quot;&gt;verifyCompletedExchanges&lt;/code&gt; backed by JMX route statistics instead of consuming messages from output endpoints.
This approach deserves a brief explanation of when it is the right choice.&lt;/p&gt;

&lt;p&gt;Citrus’s standard &lt;code class=&quot;highlighter-rouge&quot;&gt;receive()&lt;/code&gt; action is ideal when:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The route produces output to a topic or queue that the test can consume&lt;/li&gt;
  &lt;li&gt;The output message content needs to be validated&lt;/li&gt;
  &lt;li&gt;You want to assert the exact shape of the transformed message&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The JMX statistics approach is better when:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The route routes to a &lt;code class=&quot;highlighter-rouge&quot;&gt;direct:&lt;/code&gt; endpoint with no external output&lt;/li&gt;
  &lt;li&gt;Multiple consumer threads share a subscription and message delivery is non-deterministic&lt;/li&gt;
  &lt;li&gt;The test goal is to prove that processing completed without errors, not to validate specific output content&lt;/li&gt;
  &lt;li&gt;The route subscribes to a dead-letter topic and you want to confirm it handles DLT messages gracefully&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the Pulsar tests above, every route terminates at either a &lt;code class=&quot;highlighter-rouge&quot;&gt;direct:&lt;/code&gt; endpoint or a log statement — there is no output topic to consume.
The JMX approach threads a needle: it validates real end-to-end processing behavior while adapting to routes that do not expose an output endpoint convenient for test consumption.&lt;/p&gt;

&lt;p&gt;For the test infrastructure setup, shared test utilities, runtime wiring, dependencies, and how to run the tests, see the &lt;a href=&quot;/samples/camel-eip/&quot;&gt;Camel EIP examples&lt;/a&gt; overview page.&lt;/p&gt;

&lt;h1 id=&quot;key-takeaways&quot;&gt;Key takeaways&lt;/h1&gt;

&lt;p&gt;Apache Pulsar’s subscription model, key-based routing, and built-in dead-letter handling require integration tests that exercise the broker’s own behavior — not mocked replicas of it.
Citrus provides the right tools for this through its Camel DSL integration, Testcontainers support, and JMX-backed route statistics.&lt;/p&gt;

&lt;p&gt;Here is a summary of the patterns used across these three scenarios:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Camel endpoint DSL for Pulsar producers&lt;/strong&gt; — &lt;code class=&quot;highlighter-rouge&quot;&gt;CamelSupport.camel().endpoints().pulsar(...)&lt;/code&gt; lets Citrus send messages via the same &lt;code class=&quot;highlighter-rouge&quot;&gt;camel-pulsar&lt;/code&gt; component the application uses, with full control over subscription name, producer name, and message key headers. No separate Pulsar client SDK is needed in the test.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;JMX route statistics for non-consuming assertions&lt;/strong&gt; — When a route terminates at a &lt;code class=&quot;highlighter-rouge&quot;&gt;direct:&lt;/code&gt; endpoint or logs its output, &lt;code class=&quot;highlighter-rouge&quot;&gt;verifyCompletedExchanges&lt;/code&gt; via &lt;code class=&quot;highlighter-rouge&quot;&gt;ManagedRouteMBean&lt;/code&gt; provides end-to-end proof of processing without requiring an output topic to consume from. Both completion count and failure count are checked.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;repeatOnError&lt;/code&gt; for asynchronous readiness&lt;/strong&gt; — Both &lt;code class=&quot;highlighter-rouge&quot;&gt;waitForCamelRouteStarted&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;verifyCompletedExchanges&lt;/code&gt; use &lt;code class=&quot;highlighter-rouge&quot;&gt;repeatOnError&lt;/code&gt; with a sleep interval rather than fixed &lt;code class=&quot;highlighter-rouge&quot;&gt;Thread.sleep&lt;/code&gt; calls. The test proceeds as soon as the condition is met, keeping execution time to a minimum.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Infrastructure-as-code readiness&lt;/strong&gt; — The &lt;code class=&quot;highlighter-rouge&quot;&gt;waitFor().http()&lt;/code&gt; action gates the test suite on the Pulsar admin health endpoint. Tests never start against an unready broker, eliminating a common class of container-related flakiness.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Two runtimes, one test pattern&lt;/strong&gt; — The Quarkus and Spring Boot tests express identical scenario logic. The differences are limited to bootstrap annotations (&lt;code class=&quot;highlighter-rouge&quot;&gt;@QuarkusTest&lt;/code&gt; vs &lt;code class=&quot;highlighter-rouge&quot;&gt;@SpringBootTest&lt;/code&gt;), CDI injection style, and where the &lt;code class=&quot;highlighter-rouge&quot;&gt;TestCaseRunner&lt;/code&gt; is declared. The test structure, the &lt;code class=&quot;highlighter-rouge&quot;&gt;EipTestSupport&lt;/code&gt; utilities, and the assertions are shared across both runtimes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The complete source code for this example is available on GitHub:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/citrusframework/citrus-camel-eip-examples/tree/main/examples/21-pulsar-deep-dive/quarkus&quot;&gt;Quarkus variant&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/citrusframework/citrus-camel-eip-examples/tree/main/examples/21-pulsar-deep-dive/spring-boot&quot;&gt;Spring Boot variant&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Give it a try, and let us know what you think!&lt;/p&gt;</content><author><name></name></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://citrusframework.org/img/icons/camel.png" /></entry><entry><title type="html">Testing the Outbox Pattern with Citrus</title><link href="https://citrusframework.org/samples/camel-eip/outbox-pattern/" rel="alternate" type="text/html" title="Testing the Outbox Pattern with Citrus" /><published>2026-09-23T00:00:00+02:00</published><updated>2026-09-23T00:00:00+02:00</updated><id>https://citrusframework.org/samples/camel-eip/sample-eip-outbox-pattern</id><content type="html" xml:base="https://citrusframework.org/samples/camel-eip/outbox-pattern/">&lt;p&gt;Some of the most dangerous bugs in distributed systems live at the boundary between a database and a message broker.
Consider a payment service that must do two things when it processes an order: insert a payment record into PostgreSQL and publish a &lt;code class=&quot;highlighter-rouge&quot;&gt;PaymentProcessed&lt;/code&gt; event to Kafka.
If the database insert succeeds but the Kafka publish fails, the payment is recorded but no downstream service ever learns about it — the order sits in limbo.
If the Kafka publish succeeds but the application crashes before the database commit, an event announces a payment that never actually happened.&lt;/p&gt;

&lt;p&gt;You need both operations to succeed or both to fail.
True distributed transactions (XA/two-phase commit) would solve this, but Kafka does not support XA, and even databases that do pay a steep performance penalty.
The practical solution is the &lt;strong&gt;Outbox Pattern&lt;/strong&gt;: write both the business record and the event into the &lt;em&gt;same&lt;/em&gt; database transaction, then publish the event to Kafka asynchronously from the outbox table.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&quot;https://www.enterpriseintegrationpatterns.com/patterns/messaging/TransactionalClient.html&quot;&gt;Transactional Client&lt;/a&gt; pattern described by Hohpe and Woolf captures the broader concept — making messaging operations part of a transaction.
The outbox pattern is its most widely adopted implementation.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://camel.apache.org&quot;&gt;Apache Camel&lt;/a&gt; models this with two cooperating routes: a transactional route that writes the payment and the outbox event atomically, and a polling route that reads unpublished events from the outbox table and publishes them to Kafka.
The &lt;code class=&quot;highlighter-rouge&quot;&gt;transacted()&lt;/code&gt; DSL ensures the two SQL inserts share a single database transaction, while the polling route’s &lt;code class=&quot;highlighter-rouge&quot;&gt;onConsume&lt;/code&gt; query marks each event as published after it has been successfully sent.&lt;/p&gt;

&lt;p&gt;Testing the outbox pattern end-to-end is where the real challenge lies.
A unit test can verify that the SQL statements are syntactically correct, but only an integration test can prove that the payment record and the outbox event are committed atomically, that the polling route picks up the event and publishes it to Kafka, and that the outbox row is marked as published afterward.
This is a three-phase verification across two infrastructure systems — exactly the kind of scenario where &lt;a href=&quot;https://citrusframework.org&quot;&gt;Citrus&lt;/a&gt; shines.&lt;/p&gt;

&lt;h2 id=&quot;the-scenario&quot;&gt;The scenario&lt;/h2&gt;

&lt;p&gt;A payment service consumes order events from a Kafka topic &lt;code class=&quot;highlighter-rouge&quot;&gt;eip.payments.required&lt;/code&gt;.
For each order, the service must:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Insert a payment record into the &lt;code class=&quot;highlighter-rouge&quot;&gt;payments.payments&lt;/code&gt; table with status &lt;code class=&quot;highlighter-rouge&quot;&gt;PROCESSED&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Write an outbox event into the &lt;code class=&quot;highlighter-rouge&quot;&gt;payments.outbox&lt;/code&gt; table with the payment details and a unique &lt;code class=&quot;highlighter-rouge&quot;&gt;event_id&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Both writes happen in a single database transaction — if either fails, both are rolled back.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A separate polling route runs every 5 seconds, reading unpublished rows from &lt;code class=&quot;highlighter-rouge&quot;&gt;payments.outbox&lt;/code&gt;, publishing each event’s payload to &lt;code class=&quot;highlighter-rouge&quot;&gt;kafka:eip.payments.processed&lt;/code&gt;, and marking the row as &lt;code class=&quot;highlighter-rouge&quot;&gt;published = true&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The test must verify all three phases: the payment record exists, the Kafka message was published with the correct payload, and the outbox row was marked as published.&lt;/p&gt;

&lt;h2 id=&quot;the-camel-routes&quot;&gt;The Camel routes&lt;/h2&gt;

&lt;p&gt;The outbox pattern is implemented as two routes in a single &lt;code class=&quot;highlighter-rouge&quot;&gt;RouteBuilder&lt;/code&gt;.
The first route handles the transactional write; the second handles the asynchronous publish.&lt;/p&gt;

&lt;h3 id=&quot;quarkus&quot;&gt;Quarkus&lt;/h3&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@ApplicationScoped&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;OutboxPatternRoute&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RouteBuilder&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.payments.required?brokers={{kafka.brokers}}&amp;amp;groupId=payment-outbox&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;transactional-client&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;unmarshal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Transactional Client — processing payment for order ${body[order_id]}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;transacted&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;sql:INSERT INTO payments.payments (order_id, amount, status) &quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;VALUES (:#${body[order_id]}, :#${body[amount]}, 'PROCESSED')&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;order&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getIn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getBody&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;event&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LinkedHashMap&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;gt;();&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eventId&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;UUID&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;randomUUID&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;event_id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eventId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;event_type&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;PaymentProcessed&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;aggregate_id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;valueOf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;order_id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)));&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LinkedHashMap&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;gt;();&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;order_id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;order_id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;amount&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;amount&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;status&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;PROCESSED&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;payload&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ObjectMapper&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;writeValueAsString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getIn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;setBody&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;})&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;sql:INSERT INTO payments.outbox (event_id, event_type, aggregate_id, payload) &quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;VALUES (:#${body[event_id]}, :#${body[event_type]}, &quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;:#${body[aggregate_id]}, :#${body[payload]})&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Transactional Client — payment and outbox event committed&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;sql:SELECT * FROM payments.outbox WHERE published = false &quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;ORDER BY created_at LIMIT 100&quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;?delay=5000&quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&amp;amp;onConsume=UPDATE payments.outbox SET published = true &quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;WHERE event_id = :#event_id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;outbox-publisher&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Outbox Publisher — publishing event ${body[event_id]} to Kafka&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;setBody&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;simple&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;${body[payload]}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.payments.processed?brokers={{kafka.brokers}}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The first route — &lt;code class=&quot;highlighter-rouge&quot;&gt;transactional-client&lt;/code&gt; — does the heavy lifting.
It consumes an order from Kafka, deserializes the JSON body, and enters a transaction with &lt;code class=&quot;highlighter-rouge&quot;&gt;.transacted()&lt;/code&gt;.
Inside the transaction, two SQL inserts execute in sequence: one writes the payment record to &lt;code class=&quot;highlighter-rouge&quot;&gt;payments.payments&lt;/code&gt;, and a processor builds the outbox event and writes it to &lt;code class=&quot;highlighter-rouge&quot;&gt;payments.outbox&lt;/code&gt;.
Because both inserts share the same transaction, either both are committed or both are rolled back — the database guarantees atomicity.&lt;/p&gt;

&lt;p&gt;The processor between the two inserts constructs the outbox event as a &lt;code class=&quot;highlighter-rouge&quot;&gt;Map&lt;/code&gt;.
It generates a random UUID as the &lt;code class=&quot;highlighter-rouge&quot;&gt;event_id&lt;/code&gt;, sets the &lt;code class=&quot;highlighter-rouge&quot;&gt;event_type&lt;/code&gt; to &lt;code class=&quot;highlighter-rouge&quot;&gt;PaymentProcessed&lt;/code&gt;, and serializes the payment payload as a JSON string.
The &lt;code class=&quot;highlighter-rouge&quot;&gt;aggregate_id&lt;/code&gt; is set to the &lt;code class=&quot;highlighter-rouge&quot;&gt;order_id&lt;/code&gt;, which downstream consumers can use for partitioning or correlation.&lt;/p&gt;

&lt;p&gt;The second route — &lt;code class=&quot;highlighter-rouge&quot;&gt;outbox-publisher&lt;/code&gt; — is a SQL polling consumer.
Every 5 seconds, it selects up to 100 unpublished rows from &lt;code class=&quot;highlighter-rouge&quot;&gt;payments.outbox&lt;/code&gt; ordered by creation time.
For each row, it extracts the &lt;code class=&quot;highlighter-rouge&quot;&gt;payload&lt;/code&gt; field, sends it to &lt;code class=&quot;highlighter-rouge&quot;&gt;kafka:eip.payments.processed&lt;/code&gt;, and the &lt;code class=&quot;highlighter-rouge&quot;&gt;onConsume&lt;/code&gt; query marks the row as &lt;code class=&quot;highlighter-rouge&quot;&gt;published = true&lt;/code&gt;.
The &lt;code class=&quot;highlighter-rouge&quot;&gt;ORDER BY created_at&lt;/code&gt; preserves the temporal ordering of business events, and the &lt;code class=&quot;highlighter-rouge&quot;&gt;LIMIT 100&lt;/code&gt; provides backpressure during bursts.&lt;/p&gt;

&lt;h3 id=&quot;spring-boot&quot;&gt;Spring Boot&lt;/h3&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@Component&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;OutboxPatternRoute&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RouteBuilder&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.payments.required?brokers={{kafka.brokers}}&amp;amp;groupId=payment-outbox&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;transactional-client&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;unmarshal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Transactional Client — processing payment for order ${body[order_id]}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;transacted&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;sql:INSERT INTO payments.payments (order_id, amount, status) &quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;VALUES (:#${body[order_id]}, :#${body[amount]}, 'PROCESSED')&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;order&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getIn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getBody&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;event&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LinkedHashMap&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;gt;();&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eventId&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;UUID&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;randomUUID&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;event_id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eventId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;event_type&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;PaymentProcessed&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;aggregate_id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;valueOf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;order_id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)));&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LinkedHashMap&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;gt;();&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;order_id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;order_id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;amount&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;amount&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;status&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;PROCESSED&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;payload&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ObjectMapper&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;writeValueAsString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getIn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;setBody&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;})&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;sql:INSERT INTO payments.outbox (event_id, event_type, aggregate_id, payload) &quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;VALUES (:#${body[event_id]}, :#${body[event_type]}, &quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;:#${body[aggregate_id]}, :#${body[payload]})&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Transactional Client — payment and outbox event committed&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;sql:SELECT * FROM payments.outbox WHERE published = false &quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;ORDER BY created_at LIMIT 100&quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;?delay=5000&quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&amp;amp;onConsume=UPDATE payments.outbox SET published = true &quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;WHERE event_id = :#event_id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;outbox-publisher&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Outbox Publisher — publishing event ${body[event_id]} to Kafka&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;setBody&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;simple&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;${body[payload]}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.payments.processed?brokers={{kafka.brokers}}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;@Component&lt;/code&gt; replaces &lt;code class=&quot;highlighter-rouge&quot;&gt;@ApplicationScoped&lt;/code&gt; — the route logic is identical between runtimes.&lt;/p&gt;

&lt;h3 id=&quot;the-outbox-guarantees&quot;&gt;The outbox guarantees&lt;/h3&gt;

&lt;p&gt;The two-route design provides three properties that a single route with a direct Kafka write cannot:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Property&lt;/th&gt;
      &lt;th&gt;How it works&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Atomicity&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;The payment record and the outbox event are written in the same database transaction. Either both exist or neither does.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Eventual consistency&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;The outbox publisher polls the table and publishes to Kafka. If it crashes, it retries on restart — events are published at-least-once.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Ordering&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Events are published in &lt;code class=&quot;highlighter-rouge&quot;&gt;created_at&lt;/code&gt; order, preserving the temporal ordering of business operations.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Combined with an idempotent receiver on the consumer side, the outbox pattern achieves effectively-once processing across the database-to-Kafka boundary.&lt;/p&gt;

&lt;h2 id=&quot;the-database-schema&quot;&gt;The database schema&lt;/h2&gt;

&lt;p&gt;The outbox pattern requires two tables — one for the business data, one for the outbox events.
Both are created by an init script mounted into the PostgreSQL container:&lt;/p&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;SCHEMA&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;IF&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;NOT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;EXISTS&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;payments&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;TABLE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;payments&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payments&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;         &lt;span class=&quot;n&quot;&gt;SERIAL&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;PRIMARY&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;KEY&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;order_id&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;VARCHAR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;NOT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;amount&lt;/span&gt;     &lt;span class=&quot;n&quot;&gt;DECIMAL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;k&quot;&gt;NOT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;status&lt;/span&gt;     &lt;span class=&quot;n&quot;&gt;VARCHAR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;NOT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;NULL&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;DEFAULT&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'PENDING'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;created_at&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;TIMESTAMP&lt;/span&gt;      &lt;span class=&quot;k&quot;&gt;NOT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;NULL&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;DEFAULT&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;NOW&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;TABLE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;payments&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outbox&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;event_id&lt;/span&gt;     &lt;span class=&quot;n&quot;&gt;VARCHAR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;PRIMARY&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;KEY&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;event_type&lt;/span&gt;   &lt;span class=&quot;n&quot;&gt;VARCHAR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;k&quot;&gt;NOT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;aggregate_id&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;VARCHAR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;k&quot;&gt;NOT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;      &lt;span class=&quot;n&quot;&gt;TEXT&lt;/span&gt;         &lt;span class=&quot;k&quot;&gt;NOT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;published&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;BOOLEAN&lt;/span&gt;      &lt;span class=&quot;k&quot;&gt;NOT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;NULL&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;DEFAULT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;created_at&lt;/span&gt;   &lt;span class=&quot;k&quot;&gt;TIMESTAMP&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;NOT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;NULL&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;DEFAULT&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;NOW&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;INDEX&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;idx_outbox_unpublished&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;ON&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;payments&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outbox&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;created_at&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;WHERE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;published&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;payments.payments&lt;/code&gt; table stores the business record.
The &lt;code class=&quot;highlighter-rouge&quot;&gt;payments.outbox&lt;/code&gt; table stores the events waiting to be published.
The &lt;code class=&quot;highlighter-rouge&quot;&gt;published&lt;/code&gt; column defaults to &lt;code class=&quot;highlighter-rouge&quot;&gt;false&lt;/code&gt; — the outbox publisher’s SELECT query filters on this column, and its &lt;code class=&quot;highlighter-rouge&quot;&gt;onConsume&lt;/code&gt; UPDATE flips it to &lt;code class=&quot;highlighter-rouge&quot;&gt;true&lt;/code&gt; after successful publication.&lt;/p&gt;

&lt;p&gt;The partial index &lt;code class=&quot;highlighter-rouge&quot;&gt;idx_outbox_unpublished&lt;/code&gt; is a performance optimization: it covers only rows with &lt;code class=&quot;highlighter-rouge&quot;&gt;published = false&lt;/code&gt;, so the polling query’s execution plan remains efficient even as the table grows with millions of published rows.&lt;/p&gt;

&lt;h2 id=&quot;the-outbox-pattern-test&quot;&gt;The outbox pattern test&lt;/h2&gt;

&lt;p&gt;The test exercises the full pipeline: send a payment request to Kafka, verify the payment record in PostgreSQL, verify the event on the downstream Kafka topic, and confirm the outbox row was marked as published.&lt;/p&gt;

&lt;h3 id=&quot;quarkus-1&quot;&gt;Quarkus&lt;/h3&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@QuarkusTest&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@CitrusSupport&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;EipTests&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;implements&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;EipTestSupport&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@CitrusResource&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;TestCaseRunner&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Inject&lt;/span&gt;
    &lt;span class=&quot;nd&quot;&gt;@BindToRegistry&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;DataSource&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dataSource&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Inject&lt;/span&gt;
    &lt;span class=&quot;nd&quot;&gt;@BindToRegistry&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;CamelContext&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Nested&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;TransactionalOutboxTest&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

        &lt;span class=&quot;nd&quot;&gt;@Test&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;shouldProcessPaymentAndPublishViaOutbox&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;given&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;createVariables&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;variable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;citrus:randomNumber(4)&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;variable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;amount&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;500&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;given&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;waitForCamelRouteStarted&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;transactional-client&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;given&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;waitForCamelRouteStarted&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;outbox-publisher&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.payments.required&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Resources&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;templates/order.json&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;header&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;KafkaMessageHeaders&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;MESSAGE_KEY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;org.citrusframework:citrus-website:pom:1.1.0&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;repeatOnError&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;times&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;actions&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                        &lt;span class=&quot;n&quot;&gt;sql&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dataSource&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;query&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;statement&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;SELECT order_id, status FROM payments.payments &quot;&lt;/span&gt;
                                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;WHERE order_id = 'org.citrusframework:citrus-website:pom:1.1.0'&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;validate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;order_id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;org.citrusframework:citrus-website:pom:1.1.0&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;validate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;status&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;PROCESSED&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;repeatOnError&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;times&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;autoSleep&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Duration&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;ofSeconds&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;actions&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                        &lt;span class=&quot;n&quot;&gt;receive&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.payments.processed&quot;&lt;/span&gt;
                                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;?consumerGroup=citrus-payments-group&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&quot;&quot;
                            {
                              &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;order_id&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: org.citrusframework:citrus-website:pom:1.1.0,
                              &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;amount&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: ${amount},
                              &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;PROCESSED&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;
                            }
                            &quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;repeatOnError&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;times&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;actions&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                        &lt;span class=&quot;n&quot;&gt;sql&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dataSource&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;query&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;statement&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;SELECT published FROM payments.outbox &quot;&lt;/span&gt;
                                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;WHERE aggregate_id = 'org.citrusframework:citrus-website:pom:1.1.0'&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;validate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;published&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;true&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This test has four distinct phases, each verifying a different part of the outbox pipeline.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Given — set up variables and wait for both routes.&lt;/strong&gt;
The test generates a random 4-digit &lt;code class=&quot;highlighter-rouge&quot;&gt;id&lt;/code&gt; used as the &lt;code class=&quot;highlighter-rouge&quot;&gt;order_id&lt;/code&gt; and sets the &lt;code class=&quot;highlighter-rouge&quot;&gt;amount&lt;/code&gt; to 500.
It then waits for &lt;em&gt;both&lt;/em&gt; the &lt;code class=&quot;highlighter-rouge&quot;&gt;transactional-client&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;outbox-publisher&lt;/code&gt; routes to reach &lt;code class=&quot;highlighter-rouge&quot;&gt;Started&lt;/code&gt; status.
Waiting for both is critical — the transactional route must be ready to consume from Kafka and write to the database, and the outbox publisher must be polling the outbox table before the test expects the event to appear on the downstream Kafka topic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When — send a payment request.&lt;/strong&gt;
A single order message goes to &lt;code class=&quot;highlighter-rouge&quot;&gt;kafka:eip.payments.required&lt;/code&gt; using the shared order template.
The template interpolates &lt;code class=&quot;highlighter-rouge&quot;&gt;org.citrusframework:citrus-website:pom:1.1.0&lt;/code&gt; into the &lt;code class=&quot;highlighter-rouge&quot;&gt;order_id&lt;/code&gt; field and &lt;code class=&quot;highlighter-rouge&quot;&gt;${amount}&lt;/code&gt; into the &lt;code class=&quot;highlighter-rouge&quot;&gt;amount&lt;/code&gt; field.
This is the test’s stimulus — a payment request that triggers the entire outbox pipeline.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Then (first assertion) — verify the payment record in PostgreSQL.&lt;/strong&gt;
The test queries &lt;code class=&quot;highlighter-rouge&quot;&gt;payments.payments&lt;/code&gt; to confirm the payment record was written.
The &lt;code class=&quot;highlighter-rouge&quot;&gt;repeatOnError()&lt;/code&gt; block retries up to 15 times with 1-second intervals, accommodating the time the transactional route needs to consume the Kafka message and execute the database transaction.&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;sql&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dataSource&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;query&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;statement&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;SELECT order_id, status FROM payments.payments WHERE order_id = 'org.citrusframework:citrus-website:pom:1.1.0'&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;validate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;order_id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;org.citrusframework:citrus-website:pom:1.1.0&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;validate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;status&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;PROCESSED&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This assertion verifies two things: the row exists (the query returns a result) and the status is &lt;code class=&quot;highlighter-rouge&quot;&gt;PROCESSED&lt;/code&gt; (not the default &lt;code class=&quot;highlighter-rouge&quot;&gt;PENDING&lt;/code&gt;).
If the transaction rolled back, the row would not exist at all.
If the insert succeeded but with wrong data, the validation would fail.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Then (second assertion) — verify the Kafka event.&lt;/strong&gt;
The test receives a message from &lt;code class=&quot;highlighter-rouge&quot;&gt;kafka:eip.payments.processed&lt;/code&gt; — the topic that the outbox publisher writes to.
This assertion has a longer retry window (20 retries with 2-second intervals) because it depends on two asynchronous steps: the transactional route writing the outbox event, and the outbox publisher polling the table and publishing to Kafka.
The publisher polls every 5 seconds, so the event may take up to 5 seconds to appear after the transaction commits.&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;receive&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.payments.processed?consumerGroup=citrus-payments-group&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&quot;&quot;
    {
      &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;order_id&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: org.citrusframework:citrus-website:pom:1.1.0,
      &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;amount&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: ${amount},
      &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;PROCESSED&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;
    }
    &quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The expected body is an inline JSON template.
Citrus validates each field against the received message.
The &lt;code class=&quot;highlighter-rouge&quot;&gt;order_id&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;amount&lt;/code&gt; must match the values sent in the stimulus, and the &lt;code class=&quot;highlighter-rouge&quot;&gt;status&lt;/code&gt; must be &lt;code class=&quot;highlighter-rouge&quot;&gt;PROCESSED&lt;/code&gt; — confirming that the outbox event’s payload was correctly constructed by the processor and faithfully published by the outbox route.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Then (third assertion) — verify the outbox row was marked as published.&lt;/strong&gt;
The final assertion queries the &lt;code class=&quot;highlighter-rouge&quot;&gt;payments.outbox&lt;/code&gt; table to confirm the row was updated.&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;sql&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dataSource&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;query&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;statement&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;SELECT published FROM payments.outbox WHERE aggregate_id = 'org.citrusframework:citrus-website:pom:1.1.0'&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;validate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;published&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;true&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This is the assertion that most developers would skip — and the one that matters most.
Without it, you would know the Kafka event was published, but you would not know whether the &lt;code class=&quot;highlighter-rouge&quot;&gt;onConsume&lt;/code&gt; UPDATE actually ran.
If the &lt;code class=&quot;highlighter-rouge&quot;&gt;onConsume&lt;/code&gt; query fails silently (a typo in the column name, a constraint violation, a connection timeout), the row remains &lt;code class=&quot;highlighter-rouge&quot;&gt;published = false&lt;/code&gt; and the outbox publisher would re-publish it on the next poll cycle — producing a duplicate event.&lt;/p&gt;

&lt;p&gt;By explicitly verifying &lt;code class=&quot;highlighter-rouge&quot;&gt;published = true&lt;/code&gt;, the test proves the entire lifecycle: write, publish, and mark-as-published.&lt;/p&gt;

&lt;h3 id=&quot;spring-boot-1&quot;&gt;Spring Boot&lt;/h3&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@SpringBootTest&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;classes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;EndpointsApplication&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@CamelSpringBootTest&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@CitrusSpringSupport&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@ContextConfiguration&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;classes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;EipInfraSetup&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CitrusSpringConfig&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;})&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;EipTests&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;implements&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;EipTestSupport&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Autowired&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;CamelContext&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Autowired&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;DataSource&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dataSource&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Nested&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;TransactionalOutboxTest&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

        &lt;span class=&quot;nd&quot;&gt;@CitrusResource&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;TestCaseRunner&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;nd&quot;&gt;@Test&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;shouldProcessPaymentAndPublishViaOutbox&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// Test logic is identical to the Quarkus variant&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// ...&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The test logic is identical.
The differences are only in the class-level annotations and dependency injection:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Concern&lt;/th&gt;
      &lt;th&gt;Quarkus&lt;/th&gt;
      &lt;th&gt;Spring Boot&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Test bootstrap&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;@QuarkusTest&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;@SpringBootTest&lt;/code&gt; + &lt;code class=&quot;highlighter-rouge&quot;&gt;@CamelSpringBootTest&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Citrus integration&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;@CitrusSupport&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;@CitrusSpringSupport&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;DataSource injection&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;@Inject&lt;/code&gt; + &lt;code class=&quot;highlighter-rouge&quot;&gt;@BindToRegistry&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;@Autowired&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;CamelContext injection&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;@Inject&lt;/code&gt; + &lt;code class=&quot;highlighter-rouge&quot;&gt;@BindToRegistry&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;@Autowired&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;TestCaseRunner scope&lt;/td&gt;
      &lt;td&gt;Class-level field&lt;/td&gt;
      &lt;td&gt;Nested class field with &lt;code class=&quot;highlighter-rouge&quot;&gt;@CitrusResource&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Infrastructure config&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;@CitrusConfiguration&lt;/code&gt; auto-discovered&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;@ContextConfiguration&lt;/code&gt; explicit&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;understanding-the-retry-strategies&quot;&gt;Understanding the retry strategies&lt;/h2&gt;

&lt;p&gt;The three assertions use different retry configurations, and the differences are deliberate.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;payment record assertion&lt;/strong&gt; retries 15 times at 1-second intervals.
The transactional route consumes the Kafka message, executes two SQL inserts, and commits — a fast operation that typically completes within a few seconds.
A 15-second window is generous but avoids unnecessary waiting.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Kafka event assertion&lt;/strong&gt; retries 20 times at 2-second intervals.
This is the slowest step because it depends on the outbox publisher’s poll cycle.
After the transactional route commits, the outbox row exists but is not yet published.
The publisher polls every 5 seconds (&lt;code class=&quot;highlighter-rouge&quot;&gt;delay=5000&lt;/code&gt; in the route), so the event may not appear on Kafka until up to 5 seconds after the commit.
The wider retry window (40 seconds total) accounts for this latency plus any Kafka producer buffering.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;outbox published assertion&lt;/strong&gt; retries 15 times at 1-second intervals.
By the time this assertion runs, the Kafka event has already been received — which means the outbox publisher already executed the &lt;code class=&quot;highlighter-rouge&quot;&gt;onConsume&lt;/code&gt; UPDATE.
The short retry window is a safety net for transactional propagation delays, not a wait for new asynchronous work.&lt;/p&gt;

&lt;h2 id=&quot;why-outbox-pattern-tests-are-different&quot;&gt;Why outbox pattern tests are different&lt;/h2&gt;

&lt;p&gt;Testing the outbox pattern introduces challenges that set it apart from other EIP tests.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The test verifies three separate state changes across two systems.&lt;/strong&gt;
Most EIP tests have a simple shape: send a message, verify the output.
The outbox test must verify a database record (payment), a Kafka message (event), and a database flag (published).
Each verification depends on the previous one succeeding, creating a three-step assertion chain.
Citrus’s &lt;code class=&quot;highlighter-rouge&quot;&gt;sql()&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;receive()&lt;/code&gt; actions can be freely mixed within the same test, making this cross-infrastructure verification natural.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Timing depends on a polling interval, not event delivery.&lt;/strong&gt;
The gap between the transaction commit and the Kafka event is governed by the outbox publisher’s 5-second poll delay — not by Kafka’s millisecond-scale delivery latency.
The test must wait for a full poll cycle, which is why the Kafka assertion uses a wider retry window than the database assertions.
Using &lt;code class=&quot;highlighter-rouge&quot;&gt;repeatOnError()&lt;/code&gt; instead of a fixed sleep makes the test both reliable (it waits long enough) and fast (it succeeds as soon as the message appears, not after a worst-case delay).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The final assertion catches a class of bugs that no other check reveals.&lt;/strong&gt;
The &lt;code class=&quot;highlighter-rouge&quot;&gt;published = true&lt;/code&gt; assertion specifically targets failures in the &lt;code class=&quot;highlighter-rouge&quot;&gt;onConsume&lt;/code&gt; query.
Without it, a broken &lt;code class=&quot;highlighter-rouge&quot;&gt;onConsume&lt;/code&gt; (wrong column name, missing WHERE clause, connection pool exhaustion) would go undetected: the event reaches Kafka, the test passes, but the row remains &lt;code class=&quot;highlighter-rouge&quot;&gt;published = false&lt;/code&gt;.
On the next poll cycle, the publisher re-sends the event — a duplicate that violates the pattern’s at-most-once publication guarantee.
This is the kind of subtle, asynchronous bug that only an end-to-end integration test can catch.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Two routes must be running before the test starts.&lt;/strong&gt;
Unlike most EIP tests that wait for a single route, the outbox test must wait for both &lt;code class=&quot;highlighter-rouge&quot;&gt;transactional-client&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;outbox-publisher&lt;/code&gt;.
Omitting the wait for either route produces different failure modes: a missing transactional route means the Kafka message is never consumed; a missing outbox publisher means the event is written to the database but never published.
The separate &lt;code class=&quot;highlighter-rouge&quot;&gt;waitForCamelRouteStarted&lt;/code&gt; calls for each route make the test’s dependencies explicit.&lt;/p&gt;

&lt;p&gt;For the test infrastructure setup, shared test utilities, runtime wiring, dependencies, and how to run the tests, see the &lt;a href=&quot;/samples/camel-eip/&quot;&gt;Camel EIP examples&lt;/a&gt; overview page.&lt;/p&gt;

&lt;h2 id=&quot;key-takeaways&quot;&gt;Key takeaways&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;The outbox pattern ensures atomicity without distributed transactions.&lt;/strong&gt; By writing both the business record and the event to the same database in a single transaction, the pattern avoids the complexity of XA/two-phase commit while guaranteeing that either both writes succeed or both are rolled back.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test all three state changes, not just the Kafka event.&lt;/strong&gt; The payment record, the Kafka message, and the outbox &lt;code class=&quot;highlighter-rouge&quot;&gt;published&lt;/code&gt; flag are all part of the pattern’s correctness contract. Skipping the database assertions — especially the &lt;code class=&quot;highlighter-rouge&quot;&gt;published = true&lt;/code&gt; check — leaves a class of &lt;code class=&quot;highlighter-rouge&quot;&gt;onConsume&lt;/code&gt; bugs undetected.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Match retry strategies to the asynchronous step they are waiting for.&lt;/strong&gt; Database assertions after a fast transaction need short retries. Kafka assertions after a polling delay need wider retries. Citrus’s &lt;code class=&quot;highlighter-rouge&quot;&gt;repeatOnError()&lt;/code&gt; makes this explicit: you set the retry count, the sleep interval, and the assertions — no guesswork about timing.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Wait for all cooperating routes before sending the stimulus.&lt;/strong&gt; The outbox pattern uses two routes that must both be running. Missing a &lt;code class=&quot;highlighter-rouge&quot;&gt;waitForCamelRouteStarted&lt;/code&gt; call produces intermittent failures that are difficult to diagnose — the test works when the route starts quickly and fails when it does not.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Citrus’s &lt;code class=&quot;highlighter-rouge&quot;&gt;sql()&lt;/code&gt; action bridges database and messaging assertions.&lt;/strong&gt; The same test that receives a Kafka message can query PostgreSQL to verify side effects. This cross-infrastructure verification is the outbox test’s defining characteristic and the reason an integration test framework is essential.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Two runtimes, one test pattern.&lt;/strong&gt; Whether you run on Quarkus or Spring Boot, the test structure — send a payment request, verify the database record, receive the Kafka event, check the outbox flag — stays the same. Only the bootstrap annotations and dependency injection differ.&lt;/li&gt;
&lt;/ul&gt;</content><author><name></name></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://citrusframework.org/img/icons/camel.png" /></entry><entry><title type="html">Testing the Idempotent Receiver Pattern with Citrus</title><link href="https://citrusframework.org/samples/camel-eip/idempotent-receiver/" rel="alternate" type="text/html" title="Testing the Idempotent Receiver Pattern with Citrus" /><published>2026-09-23T00:00:00+02:00</published><updated>2026-09-23T00:00:00+02:00</updated><id>https://citrusframework.org/samples/camel-eip/sample-eip-idempotent-receiver</id><content type="html" xml:base="https://citrusframework.org/samples/camel-eip/idempotent-receiver/">&lt;p&gt;Every decoupled messaging system that guarantees an at-least-once delivery has the same uncomfortable truth: your consumer &lt;em&gt;will&lt;/em&gt; see the same message more than once.
A Kafka rebalance during processing, a consumer crash after business logic completes but before the offset is committed, a network hiccup triggering a producer retry — all of these produce duplicates.
For a notification service, a duplicate means a customer receives the same “your order shipped” email twice.
Annoying, but harmless.
For a payment service, a duplicate means the customer is charged twice.
That is a production incident.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&quot;https://www.enterpriseintegrationpatterns.com/patterns/messaging/IdempotentReceiver.html&quot;&gt;Idempotent Receiver&lt;/a&gt; pattern, described by Hohpe and Woolf, addresses this.
An idempotent receiver tracks which messages have already been processed and silently skips duplicates.
It maintains a set of processed message IDs — typically backed by a database, Redis, or an in-memory store — and checks each incoming message against the set before processing it.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://camel.apache.org&quot;&gt;Apache Camel&lt;/a&gt; implements this with the &lt;code class=&quot;highlighter-rouge&quot;&gt;idempotentConsumer()&lt;/code&gt; EIP.
You provide an expression that extracts the unique message key and a repository that persists the seen keys.
Camel handles the check-and-store logic internally: if the key is already in the repository, the message is skipped; otherwise, it is processed and the key is recorded.&lt;/p&gt;

&lt;p&gt;Testing an idempotent receiver requires proving two complementary behaviors: that unique messages pass through normally, and that duplicate messages are silently dropped.
The second assertion is the harder one — you need to prove a &lt;em&gt;negative&lt;/em&gt;, that something did &lt;em&gt;not&lt;/em&gt; happen.
Integration tests with &lt;a href=&quot;https://citrusframework.org&quot;&gt;Citrus&lt;/a&gt; handle this naturally using timeout-based assertions that confirm no output appears for the duplicate.&lt;/p&gt;

&lt;h2 id=&quot;the-scenario&quot;&gt;The scenario&lt;/h2&gt;

&lt;p&gt;An order processing pipeline receives order events on a Kafka topic &lt;code class=&quot;highlighter-rouge&quot;&gt;eip.orders.placed&lt;/code&gt;.
Each order carries an &lt;code class=&quot;highlighter-rouge&quot;&gt;order_id&lt;/code&gt; that uniquely identifies it.
The idempotent receiver route consumes from this topic, deduplicates orders by &lt;code class=&quot;highlighter-rouge&quot;&gt;order_id&lt;/code&gt; using a JDBC-backed repository in PostgreSQL, and forwards unique orders to a downstream topic &lt;code class=&quot;highlighter-rouge&quot;&gt;eip.orders.deduplicated&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If the same &lt;code class=&quot;highlighter-rouge&quot;&gt;order_id&lt;/code&gt; arrives twice — because a producer retried, because a Kafka rebalance caused a redelivery, or because an upstream system replayed events — the second occurrence is silently dropped.
The downstream topic never sees it.&lt;/p&gt;

&lt;p&gt;This is the scenario we need to test end-to-end: send two identical messages, verify that exactly one arrives on the output topic, confirm that the duplicate produced no output, and check that the route processed both exchanges without errors.&lt;/p&gt;

&lt;h2 id=&quot;the-camel-route&quot;&gt;The Camel route&lt;/h2&gt;

&lt;p&gt;The route is concise.
The interesting part is the combination of &lt;code class=&quot;highlighter-rouge&quot;&gt;idempotentConsumer()&lt;/code&gt; with a &lt;code class=&quot;highlighter-rouge&quot;&gt;JdbcMessageIdRepository&lt;/code&gt; — a production-grade deduplication store backed by PostgreSQL.&lt;/p&gt;

&lt;h3 id=&quot;quarkus&quot;&gt;Quarkus&lt;/h3&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@ApplicationScoped&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;IdempotentReceiverRoute&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RouteBuilder&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Inject&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;DataSource&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dataSource&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;JdbcMessageIdRepository&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;idempotentRepo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;JdbcMessageIdRepository&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dataSource&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;payment-dedup&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.placed?brokers={{kafka.brokers}}&amp;amp;groupId=idempotent-demo&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;idempotent-receiver&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;unmarshal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;idempotentConsumer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;jsonpath&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;$.order_id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;idempotentRepo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Processing unique order ${body[order_id]}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;marshal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.deduplicated?brokers={{kafka.brokers}}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The route reads from &lt;code class=&quot;highlighter-rouge&quot;&gt;eip.orders.placed&lt;/code&gt;, deserializes the JSON body, and passes it through &lt;code class=&quot;highlighter-rouge&quot;&gt;idempotentConsumer()&lt;/code&gt;.
The expression &lt;code class=&quot;highlighter-rouge&quot;&gt;jsonpath(&quot;$.order_id&quot;)&lt;/code&gt; extracts the deduplication key from the message body.
The &lt;code class=&quot;highlighter-rouge&quot;&gt;JdbcMessageIdRepository&lt;/code&gt; stores seen keys in a PostgreSQL table named &lt;code class=&quot;highlighter-rouge&quot;&gt;camel_messageprocessed&lt;/code&gt;, keyed by the processor name &lt;code class=&quot;highlighter-rouge&quot;&gt;&quot;payment-dedup&quot;&lt;/code&gt; and the extracted &lt;code class=&quot;highlighter-rouge&quot;&gt;order_id&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;When a message with a previously seen &lt;code class=&quot;highlighter-rouge&quot;&gt;order_id&lt;/code&gt; arrives, &lt;code class=&quot;highlighter-rouge&quot;&gt;idempotentConsumer()&lt;/code&gt; silently drops it — the route processing after &lt;code class=&quot;highlighter-rouge&quot;&gt;idempotentConsumer()&lt;/code&gt; never executes for the duplicate.
Only unique messages reach the &lt;code class=&quot;highlighter-rouge&quot;&gt;marshal().json()&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;to(&quot;kafka:eip.orders.deduplicated&quot;)&lt;/code&gt; steps.&lt;/p&gt;

&lt;h3 id=&quot;spring-boot&quot;&gt;Spring Boot&lt;/h3&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@Component&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;IdempotentReceiverRoute&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RouteBuilder&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Autowired&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;DataSource&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dataSource&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;JdbcMessageIdRepository&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;idempotentRepo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;JdbcMessageIdRepository&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dataSource&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;payment-dedup&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.placed?brokers={{kafka.brokers}}&amp;amp;groupId=idempotent-demo&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;idempotent-receiver&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;unmarshal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;idempotentConsumer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;jsonpath&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;$.order_id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;idempotentRepo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Processing unique order ${body[order_id]}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;marshal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.deduplicated?brokers={{kafka.brokers}}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;@Component&lt;/code&gt; replaces &lt;code class=&quot;highlighter-rouge&quot;&gt;@ApplicationScoped&lt;/code&gt;, and &lt;code class=&quot;highlighter-rouge&quot;&gt;@Autowired&lt;/code&gt; replaces &lt;code class=&quot;highlighter-rouge&quot;&gt;@Inject&lt;/code&gt; — the route logic is identical.&lt;/p&gt;

&lt;h3 id=&quot;choosing-the-idempotent-repository&quot;&gt;Choosing the idempotent repository&lt;/h3&gt;

&lt;p&gt;Camel provides several idempotent repository implementations.
The choice depends on your durability and performance requirements:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Repository&lt;/th&gt;
      &lt;th&gt;Durability&lt;/th&gt;
      &lt;th&gt;Speed&lt;/th&gt;
      &lt;th&gt;Use case&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;MemoryIdempotentRepository&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;None (lost on restart)&lt;/td&gt;
      &lt;td&gt;Fastest&lt;/td&gt;
      &lt;td&gt;Development, testing&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;JdbcMessageIdRepository&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Persistent&lt;/td&gt;
      &lt;td&gt;Moderate&lt;/td&gt;
      &lt;td&gt;Production (when a relational DB is available)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;RedisIdempotentRepository&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Persistent, distributed&lt;/td&gt;
      &lt;td&gt;Fast&lt;/td&gt;
      &lt;td&gt;Production (recommended for high throughput)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;InfinispanIdempotentRepository&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Persistent, clustered&lt;/td&gt;
      &lt;td&gt;Fast&lt;/td&gt;
      &lt;td&gt;High-availability clusters&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Our example uses &lt;code class=&quot;highlighter-rouge&quot;&gt;JdbcMessageIdRepository&lt;/code&gt; because the application already has PostgreSQL in the stack for other purposes — no additional infrastructure required.
The repository needs a table to store processed message IDs:&lt;/p&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;TABLE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;IF&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;NOT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;EXISTS&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camel_messageprocessed&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;processorName&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;VARCHAR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;NOT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;messageId&lt;/span&gt;     &lt;span class=&quot;n&quot;&gt;VARCHAR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;NOT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;createdAt&lt;/span&gt;     &lt;span class=&quot;k&quot;&gt;TIMESTAMP&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;NOT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;NULL&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;DEFAULT&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;NOW&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;PRIMARY&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;KEY&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;processorName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;messageId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The composite primary key &lt;code class=&quot;highlighter-rouge&quot;&gt;(processorName, messageId)&lt;/code&gt; ensures that each processor instance has its own namespace.
Multiple routes using the same table can each track their own set of processed IDs independently by choosing different processor names.&lt;/p&gt;

&lt;h2 id=&quot;the-idempotent-receiver-tests&quot;&gt;The idempotent receiver tests&lt;/h2&gt;

&lt;p&gt;The test methods cover the pattern’s two complementary behaviors: deduplication of identical messages, and pass-through of unique messages.&lt;/p&gt;

&lt;h3 id=&quot;deduplicating-identical-orders&quot;&gt;Deduplicating identical orders&lt;/h3&gt;

&lt;p&gt;This is the primary test — it proves that the idempotent receiver processes the first unique order and correctly drops following duplicates.&lt;/p&gt;

&lt;h4 id=&quot;quarkus-1&quot;&gt;Quarkus&lt;/h4&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@QuarkusTest&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@CitrusSupport&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;EipTests&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;implements&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;EipTestSupport&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@CitrusResource&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;TestCaseRunner&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Inject&lt;/span&gt;
    &lt;span class=&quot;nd&quot;&gt;@BindToRegistry&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;CamelContext&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Nested&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;IdempotentReceiverTest&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

        &lt;span class=&quot;nd&quot;&gt;@Test&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;shouldDeduplicateIdenticalOrders&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;given&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;createVariables&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;variable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;citrus:randomNumber(4)&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;variable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;amount&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;given&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;waitForCamelRouteStarted&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;idempotent-receiver&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.placed&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Resources&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;templates/order.json&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;header&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;KafkaMessageHeaders&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;MESSAGE_KEY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;org.citrusframework:citrus-website:pom:1.1.0&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.placed&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Resources&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;templates/order.json&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;header&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;KafkaMessageHeaders&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;MESSAGE_KEY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;org.citrusframework:citrus-website:pom:1.1.0&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;receive&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.deduplicated?consumerGroup=citrus-dedup-group&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Resources&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;templates/order.json&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;expectTimeout&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.deduplicated?consumerGroup=citrus-dedup-group&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;timeout&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5000&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;verifyCompletedExchanges&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;idempotent-receiver&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This test has five distinct phases, each building on the previous one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Given — set up variables and wait for the route.&lt;/strong&gt;
The test generates a random 4-digit &lt;code class=&quot;highlighter-rouge&quot;&gt;id&lt;/code&gt; used to construct a unique &lt;code class=&quot;highlighter-rouge&quot;&gt;order_id&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;customer_id&lt;/code&gt;, and &lt;code class=&quot;highlighter-rouge&quot;&gt;item_sku&lt;/code&gt; via the shared order template.
It then waits for the &lt;code class=&quot;highlighter-rouge&quot;&gt;idempotent-receiver&lt;/code&gt; route to reach &lt;code class=&quot;highlighter-rouge&quot;&gt;Started&lt;/code&gt; status, ensuring the Kafka consumer group is registered and the JDBC repository is connected.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When — send the same order twice.&lt;/strong&gt;
Two identical messages are sent to &lt;code class=&quot;highlighter-rouge&quot;&gt;kafka:eip.orders.placed&lt;/code&gt;, both using the same &lt;code class=&quot;highlighter-rouge&quot;&gt;id&lt;/code&gt; variable.
Since the order template interpolates &lt;code class=&quot;highlighter-rouge&quot;&gt;org.citrusframework:citrus-website:pom:1.1.0&lt;/code&gt; into the &lt;code class=&quot;highlighter-rouge&quot;&gt;order_id&lt;/code&gt; field, both messages carry the same &lt;code class=&quot;highlighter-rouge&quot;&gt;order_id&lt;/code&gt;.
The Kafka message key is also set to &lt;code class=&quot;highlighter-rouge&quot;&gt;org.citrusframework:citrus-website:pom:1.1.0&lt;/code&gt; — this is good practice for partitioning, ensuring that both copies land on the same partition and are processed in order.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Then (first assertion) — verify the first message arrives.&lt;/strong&gt;
The test receives one message from &lt;code class=&quot;highlighter-rouge&quot;&gt;kafka:eip.orders.deduplicated&lt;/code&gt;.
The expected body matches the order template — confirming that the unique order was forwarded correctly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Then (second assertion) — verify the duplicate was dropped.&lt;/strong&gt;
This is the key assertion.
&lt;code class=&quot;highlighter-rouge&quot;&gt;expectTimeout()&lt;/code&gt; attempts to consume another message from the same Kafka topic and asserts that &lt;em&gt;nothing&lt;/em&gt; arrives within 5 seconds.
If the idempotent receiver failed to drop the duplicate, a second message would appear on &lt;code class=&quot;highlighter-rouge&quot;&gt;eip.orders.deduplicated&lt;/code&gt; and this assertion would fail.
Proving a negative — that something did &lt;em&gt;not&lt;/em&gt; happen — requires a timeout-based approach, and Citrus’s &lt;code class=&quot;highlighter-rouge&quot;&gt;expectTimeout()&lt;/code&gt; provides exactly this.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Then (third assertion) — verify both exchanges were processed.&lt;/strong&gt;
&lt;code class=&quot;highlighter-rouge&quot;&gt;verifyCompletedExchanges(&quot;idempotent-receiver&quot;, 2, camelContext)&lt;/code&gt; confirms that the route consumed and processed &lt;em&gt;both&lt;/em&gt; messages from Kafka.
This is an important distinction: the route processed two exchanges, but the &lt;code class=&quot;highlighter-rouge&quot;&gt;idempotentConsumer()&lt;/code&gt; EIP filtered one of them before the downstream &lt;code class=&quot;highlighter-rouge&quot;&gt;to()&lt;/code&gt; step.
The exchange count of 2 proves that the duplicate was not lost or rejected at the Kafka level — it was consumed and deliberately skipped by the idempotent logic.&lt;/p&gt;

&lt;h2 id=&quot;the-order-template&quot;&gt;The order template&lt;/h2&gt;

&lt;p&gt;The tests use a shared JSON template that Citrus resolves at runtime:&lt;/p&gt;

&lt;div class=&quot;language-json highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;order_id&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;err&quot;&gt;org.citrusframework&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;citrus-website&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;pom&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.1&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;customer_id&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;CUST-00org.citrusframework:citrus-website:pom:1.1.0&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;item_sku&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;SKU-SHIP-org.citrusframework:citrus-website:pom:1.1.0&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;quantity&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;amount&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;err&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;amount&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;org.citrusframework:citrus-website:pom:1.1.0&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;${amount}&lt;/code&gt; placeholders are replaced by Citrus variables before sending.
When used in a &lt;code class=&quot;highlighter-rouge&quot;&gt;receive()&lt;/code&gt; assertion, the same template serves as the expected body — Citrus validates each field against the received message.
This dual use of templates as both input and expectation is a Citrus convenience that keeps tests concise and eliminates discrepancies between sent and expected data.&lt;/p&gt;

&lt;h2 id=&quot;why-idempotent-receiver-tests-are-different&quot;&gt;Why idempotent receiver tests are different&lt;/h2&gt;

&lt;p&gt;Testing an idempotent receiver introduces challenges that most other EIP tests do not have.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You must prove a negative.&lt;/strong&gt;
Most pattern tests verify that something &lt;em&gt;happened&lt;/em&gt;: a message was routed, split, filtered, or aggregated.
An idempotent receiver test must also verify that something did &lt;em&gt;not&lt;/em&gt; happen — that the duplicate message did not produce output.
Citrus’s &lt;code class=&quot;highlighter-rouge&quot;&gt;expectTimeout()&lt;/code&gt; is purpose-built for this: it attempts to consume from an endpoint and fails if a message &lt;em&gt;does&lt;/em&gt; arrive within the timeout window.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The route processes more exchanges than it produces output for.&lt;/strong&gt;
In a content-based router or splitter, every input exchange produces at least one output.
The idempotent receiver deliberately drops exchanges — but they are still &lt;em&gt;processed&lt;/em&gt; by the route.
Citrus’s route statistics verification provides visibility into this: &lt;code class=&quot;highlighter-rouge&quot;&gt;verifyCompletedExchanges&lt;/code&gt; confirms that both messages were consumed and processed, even though only one was forwarded downstream.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Consumer groups must be isolated per test.&lt;/strong&gt;
Because Kafka consumer groups track offsets, two tests sharing the same group can interfere with each other.
One test’s &lt;code class=&quot;highlighter-rouge&quot;&gt;receive()&lt;/code&gt; call might consume a message intended for the other test.
Assigning a unique consumer group per test method — &lt;code class=&quot;highlighter-rouge&quot;&gt;citrus-dedup-group&lt;/code&gt; for the deduplication test eliminates this risk.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The deduplication store is stateful across the test.&lt;/strong&gt;
The JDBC repository persists &lt;code class=&quot;highlighter-rouge&quot;&gt;order_id&lt;/code&gt; values in PostgreSQL.
If the deduplication test runs before the pass-through test with the same &lt;code class=&quot;highlighter-rouge&quot;&gt;order_id&lt;/code&gt;, the pass-through test would fail because the ID is already in the repository.
The random &lt;code class=&quot;highlighter-rouge&quot;&gt;id&lt;/code&gt; variable generated by &lt;code class=&quot;highlighter-rouge&quot;&gt;citrus:randomNumber(4)&lt;/code&gt; ensures each test run uses a unique &lt;code class=&quot;highlighter-rouge&quot;&gt;order_id&lt;/code&gt;, avoiding cross-test contamination.&lt;/p&gt;

&lt;p&gt;For the test infrastructure setup, shared test utilities, runtime wiring, dependencies, and how to run the tests, see the &lt;a href=&quot;/samples/camel-eip/&quot;&gt;Camel EIP examples&lt;/a&gt; overview page.&lt;/p&gt;

&lt;h2 id=&quot;key-takeaways&quot;&gt;Key takeaways&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Idempotent receivers prevent duplicate processing.&lt;/strong&gt; With at-least-once delivery, duplicates are inevitable. The idempotent receiver pattern tracks processed message IDs and silently skips messages it has already seen — essential for payment processing, inventory updates, and any operation with side effects.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;expectTimeout()&lt;/code&gt; proves that duplicates are dropped.&lt;/strong&gt; Testing a negative — that a message was &lt;em&gt;not&lt;/em&gt; forwarded — requires a timeout-based assertion. Citrus provides &lt;code class=&quot;highlighter-rouge&quot;&gt;expectTimeout()&lt;/code&gt; for exactly this purpose, failing the test only if a message unexpectedly appears.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;verifyCompletedExchanges&lt;/code&gt; distinguishes consumption from forwarding.&lt;/strong&gt; The route consumes both messages from Kafka but forwards only one. Citrus’s route statistics verification reveals the true exchange count, confirming that the duplicate was consumed and deliberately filtered — not lost.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Isolated consumer groups prevent test interference.&lt;/strong&gt; Each test method should use its own Kafka consumer group. Shared groups cause unpredictable offset tracking, where one test’s &lt;code class=&quot;highlighter-rouge&quot;&gt;receive()&lt;/code&gt; call may consume messages intended for another.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Random IDs prevent cross-test contamination.&lt;/strong&gt; The JDBC idempotent repository is persistent — a duplicate ID from a previous test run would cause false deduplication. Citrus’s &lt;code class=&quot;highlighter-rouge&quot;&gt;citrus:randomNumber()&lt;/code&gt; function generates unique IDs per test execution.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Two runtimes, one test pattern.&lt;/strong&gt; Whether you run on Quarkus or Spring Boot, the test structure — send the same message twice, verify one output, confirm no second output, check exchange counts — stays the same. Only the bootstrap annotations and dependency injection differ.&lt;/li&gt;
&lt;/ul&gt;</content><author><name></name></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://citrusframework.org/img/icons/camel.png" /></entry><entry><title type="html">Testing the Polling Consumer Pattern with Citrus</title><link href="https://citrusframework.org/samples/camel-eip/polling-consumer/" rel="alternate" type="text/html" title="Testing the Polling Consumer Pattern with Citrus" /><published>2026-09-22T00:00:00+02:00</published><updated>2026-09-22T00:00:00+02:00</updated><id>https://citrusframework.org/samples/camel-eip/sample-eip-polling-consumer</id><content type="html" xml:base="https://citrusframework.org/samples/camel-eip/polling-consumer/">&lt;p&gt;Most messaging patterns covered so far — content-based routers, splitters, message filters — are event-driven.
A message arrives, the route processes it, and an output appears almost immediately.
But not every data source can push messages to your application.
Files land in a directory at unpredictable intervals.
Database tables receive new rows from legacy systems that have no event notification mechanism.
FTP servers accumulate uploads silently.
In all these cases, the only way to detect new data is to &lt;em&gt;ask&lt;/em&gt; for it — repeatedly, on a schedule.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&quot;https://www.enterpriseintegrationpatterns.com/patterns/messaging/PollingConsumer.html&quot;&gt;Polling Consumer&lt;/a&gt; pattern, described by Hohpe and Woolf, addresses this.
A polling consumer actively checks a channel for new messages at regular intervals.
It initiates the receive operation — the messaging system does not push messages to it.
This is the “pull” model, and it is the natural fit for sources that cannot push: file systems, databases, FTP servers, and scheduled batch jobs.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://camel.apache.org&quot;&gt;Apache Camel&lt;/a&gt; implements the polling consumer in two ways.
Many components — &lt;code class=&quot;highlighter-rouge&quot;&gt;file&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;ftp&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;sql&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;timer&lt;/code&gt; — are polling consumers by nature: the &lt;code class=&quot;highlighter-rouge&quot;&gt;from()&lt;/code&gt; endpoint polls its source on a configurable schedule.
For event-driven routes that occasionally need to pull a message on demand, Camel provides &lt;code class=&quot;highlighter-rouge&quot;&gt;pollEnrich()&lt;/code&gt;, which combines a timer trigger with an explicit poll from a second endpoint.&lt;/p&gt;

&lt;p&gt;Testing a polling consumer introduces a timing challenge that event-driven patterns do not have.
The test cannot simply send a message and expect an immediate response.
It must account for the poll interval: the message might sit in the source for seconds before the consumer picks it up.
Integration tests with &lt;a href=&quot;https://citrusframework.org&quot;&gt;Citrus&lt;/a&gt; handle this gracefully — retry-based assertions naturally accommodate the poll delay without resorting to brittle fixed sleeps.&lt;/p&gt;

&lt;p&gt;This post covers two variants of the polling consumer: a timer-driven poll from Kafka using &lt;code class=&quot;highlighter-rouge&quot;&gt;pollEnrich()&lt;/code&gt;, and a SQL polling consumer that reads rows from PostgreSQL and publishes them to Kafka.
The SQL variant is the more realistic and interesting case — it demonstrates database-to-messaging integration with automatic row status updates, and the Citrus test exercises both the database and Kafka sides of the pipeline.&lt;/p&gt;

&lt;h2 id=&quot;the-scenario&quot;&gt;The scenario&lt;/h2&gt;

&lt;h3 id=&quot;timer-based-polling-consumer&quot;&gt;Timer-based polling consumer&lt;/h3&gt;

&lt;p&gt;A timer fires every 10 seconds.
On each tick, the route uses &lt;code class=&quot;highlighter-rouge&quot;&gt;pollEnrich()&lt;/code&gt; to check a Kafka topic for a waiting message.
If a message is available, it is consumed and logged.
If no message arrives within a 5-second timeout, the route logs that the poll cycle was empty.
This is the simplest form of polling consumer — useful when you want explicit control over &lt;em&gt;when&lt;/em&gt; messages are consumed, rather than letting the Kafka client manage the fetch loop.&lt;/p&gt;

&lt;h3 id=&quot;sql-polling-consumer&quot;&gt;SQL polling consumer&lt;/h3&gt;

&lt;p&gt;A more common real-world scenario: a database table receives new order rows from a legacy system.
There is no event notification — the Camel route polls the &lt;code class=&quot;highlighter-rouge&quot;&gt;orders.orders&lt;/code&gt; table every 30 seconds, looking for rows with &lt;code class=&quot;highlighter-rouge&quot;&gt;status = 'PLACED'&lt;/code&gt;.
Each row is read, marshalled to JSON, and published to a Kafka topic.
After successful processing, the &lt;code class=&quot;highlighter-rouge&quot;&gt;onConsume&lt;/code&gt; query updates the row’s status to &lt;code class=&quot;highlighter-rouge&quot;&gt;'PROCESSING'&lt;/code&gt;, preventing it from being picked up again on the next poll.&lt;/p&gt;

&lt;p&gt;This two-phase behavior — read then update — is exactly what makes the SQL polling consumer worth testing end-to-end.
A unit test could verify the SQL query syntax, but only an integration test proves that the row is actually read, the Kafka message is published, and the status update takes effect.&lt;/p&gt;

&lt;h2 id=&quot;the-camel-routes&quot;&gt;The Camel routes&lt;/h2&gt;

&lt;h3 id=&quot;timer-based-polling-consumer-1&quot;&gt;Timer-based polling consumer&lt;/h3&gt;

&lt;h4 id=&quot;quarkus&quot;&gt;Quarkus&lt;/h4&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@ApplicationScoped&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;PollingConsumerRoute&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RouteBuilder&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;timer:poll-trigger?period=10000&amp;amp;delay=5000&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;polling-consumer&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Polling consumer triggered — checking for messages …&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;pollEnrich&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.consumer.poll?brokers={{kafka.brokers}}&quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&amp;amp;groupId=polling-consumer&amp;amp;autoOffsetReset=earliest&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5000&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;choice&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;isNull&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;())&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;No message available during this poll cycle&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;otherwise&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;unmarshal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Polled message: order ${body[order_id]}, type=${body[event_type]}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The route starts from a &lt;code class=&quot;highlighter-rouge&quot;&gt;timer&lt;/code&gt;, not from Kafka directly.
Every 10 seconds, the timer fires and &lt;code class=&quot;highlighter-rouge&quot;&gt;pollEnrich()&lt;/code&gt; attempts to pull one message from the &lt;code class=&quot;highlighter-rouge&quot;&gt;eip.consumer.poll&lt;/code&gt; topic with a 5-second timeout.
The &lt;code class=&quot;highlighter-rouge&quot;&gt;choice()&lt;/code&gt; block handles the two outcomes: a null body means no message was available; otherwise, the message is deserialized and logged.&lt;/p&gt;

&lt;p&gt;This is fundamentally different from a standard &lt;code class=&quot;highlighter-rouge&quot;&gt;from(&quot;kafka:...&quot;)&lt;/code&gt; consumer.
A Kafka &lt;code class=&quot;highlighter-rouge&quot;&gt;from()&lt;/code&gt; consumer is event-driven — Camel manages the poll loop internally and your route logic runs whenever messages arrive.
With &lt;code class=&quot;highlighter-rouge&quot;&gt;pollEnrich()&lt;/code&gt;, &lt;em&gt;you&lt;/em&gt; control the timing: the poll happens exactly when the timer fires, and at most one message is consumed per cycle.&lt;/p&gt;

&lt;h4 id=&quot;spring-boot&quot;&gt;Spring Boot&lt;/h4&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@Component&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;PollingConsumerRoute&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RouteBuilder&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;timer:poll-trigger?period=10000&amp;amp;delay=5000&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;polling-consumer&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Polling consumer triggered — checking for messages …&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;pollEnrich&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.consumer.poll?brokers={{kafka.brokers}}&quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&amp;amp;groupId=polling-consumer&amp;amp;autoOffsetReset=earliest&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5000&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;choice&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;isNull&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;())&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;No message available during this poll cycle&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;otherwise&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;unmarshal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Polled message: order ${body[order_id]}, type=${body[event_type]}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;@Component&lt;/code&gt; replaces &lt;code class=&quot;highlighter-rouge&quot;&gt;@ApplicationScoped&lt;/code&gt; — the route logic is identical.&lt;/p&gt;

&lt;h3 id=&quot;sql-polling-consumer-1&quot;&gt;SQL polling consumer&lt;/h3&gt;

&lt;p&gt;The SQL polling consumer is more interesting because it bridges two infrastructure systems: PostgreSQL as the source and Kafka as the destination.&lt;/p&gt;

&lt;h4 id=&quot;quarkus-1&quot;&gt;Quarkus&lt;/h4&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@ApplicationScoped&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;SqlPollingConsumerRoute&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RouteBuilder&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;sql:SELECT * FROM orders.orders WHERE status = 'PLACED' &quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;ORDER BY created_at LIMIT 10&quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;?delay=30000&quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&amp;amp;onConsume=UPDATE orders.orders SET status = 'PROCESSING' WHERE id = :#id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;polling-consumer-sql&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;SQL Polling Consumer — processing order from DB: &quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;id=${body[id]}, customer=${body[customer_id]}, sku=${body[item_sku]}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;marshal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.placed?brokers={{kafka.brokers}}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;from(&quot;sql:...&quot;)&lt;/code&gt; component is a natural polling consumer.
Every 30 seconds (controlled by &lt;code class=&quot;highlighter-rouge&quot;&gt;delay=30000&lt;/code&gt;), Camel executes the SELECT query and creates one exchange per row.
The query selects at most 10 rows ordered by creation time — this is the backpressure mechanism, preventing the consumer from overwhelming the downstream Kafka topic during a burst of new orders.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;onConsume&lt;/code&gt; parameter is the key to reliable processing.
After each row is &lt;em&gt;successfully&lt;/em&gt; processed (marshalled to JSON and published to Kafka), Camel executes the UPDATE statement, setting the row’s status from &lt;code class=&quot;highlighter-rouge&quot;&gt;'PLACED'&lt;/code&gt; to &lt;code class=&quot;highlighter-rouge&quot;&gt;'PROCESSING'&lt;/code&gt;.
The &lt;code class=&quot;highlighter-rouge&quot;&gt;:#id&lt;/code&gt; syntax is a named parameter that Camel resolves from the current exchange body — it refers to the &lt;code class=&quot;highlighter-rouge&quot;&gt;id&lt;/code&gt; column of the row being processed.
On the next poll cycle, the WHERE clause &lt;code class=&quot;highlighter-rouge&quot;&gt;status = 'PLACED'&lt;/code&gt; naturally excludes already-processed rows.&lt;/p&gt;

&lt;h4 id=&quot;spring-boot-1&quot;&gt;Spring Boot&lt;/h4&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@Component&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;SqlPollingConsumerRoute&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RouteBuilder&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;sql:SELECT * FROM orders.orders WHERE status = 'PLACED' &quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;ORDER BY created_at LIMIT 10&quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;?delay=30000&quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&amp;amp;onConsume=UPDATE orders.orders SET status = 'PROCESSING' WHERE id = :#id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;polling-consumer-sql&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;SQL Polling Consumer — processing order from DB: &quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;id=${body[id]}, customer=${body[customer_id]}, sku=${body[item_sku]}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;marshal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.placed?brokers={{kafka.brokers}}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;yaml-dsl&quot;&gt;YAML DSL&lt;/h4&gt;

&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;route&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;polling-consumer-sql&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;uri&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;sql:SELECT&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;FROM&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;orders.orders&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;WHERE&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'PLACED'&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;ORDER&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;BY&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;created_at&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;LIMIT&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;10&quot;&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;parameters&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;delay&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;30000&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;onConsume&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;UPDATE&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;orders.orders&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;SET&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'PROCESSING'&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;WHERE&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;:#id&quot;&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;steps&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;SQL&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Polling&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Consumer&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;—&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;processing&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;DB:&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;id=${body[id]},&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;customer=${body[customer_id]},&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;sku=${body[item_sku]}&quot;&lt;/span&gt;
        &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;marshal&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
              &lt;span class=&quot;na&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Jackson&lt;/span&gt;
        &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;uri&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;kafka:eip.orders.placed&quot;&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;parameters&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
              &lt;span class=&quot;na&quot;&gt;brokers&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{{kafka.brokers}}&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;polling-parameters&quot;&gt;Polling parameters&lt;/h3&gt;

&lt;p&gt;Camel’s polling consumers share a common set of scheduling parameters:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Parameter&lt;/th&gt;
      &lt;th&gt;Description&lt;/th&gt;
      &lt;th&gt;Default&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;delay&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Milliseconds between polls&lt;/td&gt;
      &lt;td&gt;500&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;maxMessagesPerPoll&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Maximum messages to process per poll cycle&lt;/td&gt;
      &lt;td&gt;0 (unlimited)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;greedy&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Poll again immediately if messages were found&lt;/td&gt;
      &lt;td&gt;false&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;sendEmptyMessageWhenIdle&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Send an empty exchange if no messages found&lt;/td&gt;
      &lt;td&gt;false&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;greedy&lt;/code&gt; option is particularly useful for database polling.
With &lt;code class=&quot;highlighter-rouge&quot;&gt;greedy=true&lt;/code&gt; and a high &lt;code class=&quot;highlighter-rouge&quot;&gt;delay&lt;/code&gt;, the consumer polls rapidly when rows are available but backs off to the long interval when the table is empty.
This avoids the wasted CPU and database connections that come from aggressive short-interval polling on an empty table.&lt;/p&gt;

&lt;h2 id=&quot;the-polling-consumer-test&quot;&gt;The polling consumer test&lt;/h2&gt;

&lt;p&gt;The timer-based polling consumer test is straightforward: send a message to Kafka, then wait for the poll cycle to pick it up.&lt;/p&gt;

&lt;h3 id=&quot;quarkus-test&quot;&gt;Quarkus test&lt;/h3&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@QuarkusTest&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@CitrusSupport&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;EipTests&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;implements&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;EipTestSupport&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@CitrusResource&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;TestCaseRunner&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Inject&lt;/span&gt;
    &lt;span class=&quot;nd&quot;&gt;@BindToRegistry&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;CamelContext&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Nested&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;PollingConsumerTest&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

        &lt;span class=&quot;nd&quot;&gt;@Test&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;shouldPollMessageFromKafka&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;given&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;createVariables&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;variable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;citrus:randomNumber(4)&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;variable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;eventType&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;order_placed&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;variable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;amount&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;99&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;given&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;waitForCamelRouteStarted&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;polling-consumer&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.consumer.poll&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Resources&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;templates/order.json&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;header&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;KafkaMessageHeaders&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;MESSAGE_KEY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;org.citrusframework:citrus-website:pom:1.1.0&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;verifyRouteStats&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;polling-consumer&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&quot;&quot;
                    { &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exchangesCompleted&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: &quot;&lt;/span&gt;&lt;span class=&quot;nd&quot;&gt;@greaterThan&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot; }
                &quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Given — set up variables and wait for the route.&lt;/strong&gt;
The test generates a random order ID and sets up the event type and amount for the order template.
It then waits for the &lt;code class=&quot;highlighter-rouge&quot;&gt;polling-consumer&lt;/code&gt; route to reach &lt;code class=&quot;highlighter-rouge&quot;&gt;Started&lt;/code&gt; status — important because the timer-driven route needs to be active and the &lt;code class=&quot;highlighter-rouge&quot;&gt;pollEnrich()&lt;/code&gt; Kafka consumer group needs to be registered before a message can be consumed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When — send an order to the polled topic.&lt;/strong&gt;
A single order message goes to &lt;code class=&quot;highlighter-rouge&quot;&gt;kafka:eip.consumer.poll&lt;/code&gt; — the topic that the &lt;code class=&quot;highlighter-rouge&quot;&gt;pollEnrich()&lt;/code&gt; call reads from.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Then — assert the route processed exchanges.&lt;/strong&gt;
The test does &lt;em&gt;not&lt;/em&gt; try to receive the message from another Kafka topic, because the polling consumer route only logs the message — it does not forward it anywhere.
Instead, it uses &lt;code class=&quot;highlighter-rouge&quot;&gt;verifyRouteStats&lt;/code&gt; with a JSON stats expression &lt;code class=&quot;highlighter-rouge&quot;&gt;{ &quot;exchangesCompleted&quot;: &quot;@greaterThan(1)@&quot; }&lt;/code&gt;.
The &lt;code class=&quot;highlighter-rouge&quot;&gt;@greaterThan(1)@&lt;/code&gt; matcher checks that more than one exchange has completed on the &lt;code class=&quot;highlighter-rouge&quot;&gt;polling-consumer&lt;/code&gt; route.
Why more than one?
Because the timer fires repeatedly, producing exchanges even when no message is available (the “no message” branch of the &lt;code class=&quot;highlighter-rouge&quot;&gt;choice()&lt;/code&gt;).
The assertion retries until the route has processed at least one exchange &lt;em&gt;with&lt;/em&gt; the polled message.&lt;/p&gt;

&lt;p&gt;This is a key insight for testing polling consumers: when the consumer only logs or internally processes the message without producing output on a verifiable endpoint, Camel’s management API provides an alternative verification path.&lt;/p&gt;

&lt;h2 id=&quot;the-sql-polling-consumer-test&quot;&gt;The SQL polling consumer test&lt;/h2&gt;

&lt;p&gt;The SQL polling consumer test is richer than the timer-based variant because it exercises two infrastructure systems and verifies three things: a database row is consumed, a Kafka message is produced, and the database row is updated.&lt;/p&gt;

&lt;h3 id=&quot;quarkus-test-1&quot;&gt;Quarkus test&lt;/h3&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@QuarkusTest&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@CitrusSupport&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;EipTests&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;implements&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;EipTestSupport&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@CitrusResource&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;TestCaseRunner&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Inject&lt;/span&gt;
    &lt;span class=&quot;nd&quot;&gt;@BindToRegistry&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;DataSource&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dataSource&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Inject&lt;/span&gt;
    &lt;span class=&quot;nd&quot;&gt;@BindToRegistry&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;CamelContext&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Nested&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;SqlPollingConsumerTest&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

        &lt;span class=&quot;nd&quot;&gt;@Test&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;shouldHandleSqlPollingConsumer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;given&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;createVariables&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;variable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;citrus:randomNumber(4)&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;variable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;amount&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;40&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;given&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;waitForCamelRouteStarted&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;polling-consumer-sql&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;sql&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dataSource&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;statement&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;INSERT INTO orders.orders &quot;&lt;/span&gt;
                        &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;(customer_id, item_sku, quantity, amount) &quot;&lt;/span&gt;
                        &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;VALUES ('CUST-00org.citrusframework:citrus-website:pom:1.1.0', 'SKU-org.citrusframework:citrus-website:pom:1.1.0', '1', '${amount}')&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;repeatOnError&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;times&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;actions&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                        &lt;span class=&quot;n&quot;&gt;receive&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.orders.placed?consumerGroup=citrus-placed-group&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&quot;&quot;
                            {
                              &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: &quot;&lt;/span&gt;&lt;span class=&quot;nd&quot;&gt;@variable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;order_id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;,
                              &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;customer_id&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CUST&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mo&quot;&gt;00&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;org&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;citrusframework&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;citrus&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;website:pom:&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;,
                              &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;PLACED&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;,
                              &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;amount&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: ${amount}.0,
                              &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;item_sku&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SKU&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;org&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;citrusframework&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;citrus&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;website:pom:&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;,
                              &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;quantity&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: 1,
                              &quot;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;created_at&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;: &quot;&lt;/span&gt;&lt;span class=&quot;nd&quot;&gt;@ignore&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;
                            }
                            &quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;sql&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dataSource&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;query&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;statement&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;SELECT status FROM orders.orders WHERE id = '${order_id}'&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;validate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;status&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;PROCESSING&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This test has four distinct phases that exercise the full polling consumer pipeline.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Given — set up variables and wait for the route.&lt;/strong&gt;
The test generates a random ID used to construct a unique &lt;code class=&quot;highlighter-rouge&quot;&gt;customer_id&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;item_sku&lt;/code&gt;.
It then waits for the &lt;code class=&quot;highlighter-rouge&quot;&gt;polling-consumer-sql&lt;/code&gt; route to start.
This is critical: if the INSERT happens before the route is polling, the row could sit in the database for an entire 30-second delay interval before being picked up.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When — insert a test row into PostgreSQL.&lt;/strong&gt;
Citrus’s &lt;code class=&quot;highlighter-rouge&quot;&gt;sql()&lt;/code&gt; action inserts a new order row directly into the &lt;code class=&quot;highlighter-rouge&quot;&gt;orders.orders&lt;/code&gt; table.
The row is created with the default status &lt;code class=&quot;highlighter-rouge&quot;&gt;'PLACED'&lt;/code&gt;, making it immediately eligible for the SQL consumer’s SELECT query.
This is the test’s “stimulus” — instead of sending a message to a Kafka topic, the test writes directly to the database that the polling consumer reads from.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Then (first assertion) — verify the Kafka output.&lt;/strong&gt;
The test receives a message from &lt;code class=&quot;highlighter-rouge&quot;&gt;kafka:eip.orders.placed&lt;/code&gt; — the topic that the SQL polling consumer publishes to.
The &lt;code class=&quot;highlighter-rouge&quot;&gt;repeatOnError()&lt;/code&gt; block retries up to 15 times with 1-second intervals, giving the poll cycle time to fire and process the row.&lt;/p&gt;

&lt;p&gt;The expected body is an inline JSON template that validates the row’s data.
Two Citrus features are at work here:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;@variable(order_id)@&lt;/code&gt; captures the database-generated &lt;code class=&quot;highlighter-rouge&quot;&gt;id&lt;/code&gt; value into a Citrus variable named &lt;code class=&quot;highlighter-rouge&quot;&gt;order_id&lt;/code&gt; rather than asserting a specific value. The ID is auto-generated by PostgreSQL’s &lt;code class=&quot;highlighter-rouge&quot;&gt;SERIAL&lt;/code&gt; column, so the test cannot predict it in advance. By extracting it into a variable, the test can reference it in subsequent assertions.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;@ignore@&lt;/code&gt; skips validation of the &lt;code class=&quot;highlighter-rouge&quot;&gt;created_at&lt;/code&gt; timestamp, which depends on the database server’s clock.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Then (second assertion) — verify the database status update.&lt;/strong&gt;
The final &lt;code class=&quot;highlighter-rouge&quot;&gt;sql().query()&lt;/code&gt; action reads the row back from PostgreSQL using the captured &lt;code class=&quot;highlighter-rouge&quot;&gt;${order_id}&lt;/code&gt; and asserts that its status has changed from &lt;code class=&quot;highlighter-rouge&quot;&gt;'PLACED'&lt;/code&gt; to &lt;code class=&quot;highlighter-rouge&quot;&gt;'PROCESSING'&lt;/code&gt;.
This verifies the &lt;code class=&quot;highlighter-rouge&quot;&gt;onConsume&lt;/code&gt; query — the UPDATE that Camel executes after successfully processing each row.&lt;/p&gt;

&lt;p&gt;This second assertion is what makes the test truly end-to-end.
Without it, you would know that the row was read and a Kafka message was produced, but you would not know whether the status update actually ran.
A failure in the &lt;code class=&quot;highlighter-rouge&quot;&gt;onConsume&lt;/code&gt; query would cause the same row to be processed again on the next poll cycle — a subtle bug that only an integration test covering both the read and the update can catch.&lt;/p&gt;

&lt;p&gt;For the test infrastructure setup, shared test utilities, runtime wiring, dependencies, and how to run the tests, see the &lt;a href=&quot;/samples/camel-eip/&quot;&gt;Camel EIP examples&lt;/a&gt; overview page.&lt;/p&gt;

&lt;h2 id=&quot;why-polling-consumer-tests-are-different&quot;&gt;Why polling consumer tests are different&lt;/h2&gt;

&lt;p&gt;Polling consumer tests have characteristics that set them apart from event-driven pattern tests:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The poll interval is the test’s timing constraint.&lt;/strong&gt;
With an event-driven consumer, a message sent to Kafka is processed within milliseconds.
With a polling consumer, the message sits in the source — a Kafka topic, a database table, a file directory — until the next poll cycle fires.
The test must wait at least one full interval.
Citrus’s &lt;code class=&quot;highlighter-rouge&quot;&gt;repeatOnError()&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;timeout&lt;/code&gt; parameters handle this gracefully, retrying until the poll cycle picks up the test data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The test produces input in a different medium than the route consumes.&lt;/strong&gt;
For the SQL polling consumer, the test does not send a Kafka message — it inserts a database row.
The test and the route operate on different infrastructure: the test writes to PostgreSQL, the route reads from PostgreSQL and writes to Kafka, and the test verifies on Kafka.
This cross-infrastructure flow is a natural fit for integration testing and would be impossible to verify with unit tests alone.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Side effects are first-class assertions.&lt;/strong&gt;
The &lt;code class=&quot;highlighter-rouge&quot;&gt;onConsume&lt;/code&gt; status update is a side effect that is just as important as the Kafka output.
The test verifies it explicitly with a SQL query after receiving the Kafka message.
If the &lt;code class=&quot;highlighter-rouge&quot;&gt;onConsume&lt;/code&gt; query fails silently, the row would be reprocessed on the next poll — a production bug that only a test covering both the output and the side effect can detect.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;verifyRouteStats&lt;/code&gt; provides a fallback verification path.&lt;/strong&gt;
When a polling consumer only logs messages internally (like the timer-based variant), there is no output endpoint to receive from.
Citrus’s route statistics verification lets the test verify that the route processed exchanges without errors — a useful technique for any route that does not produce verifiable output on an external endpoint.&lt;/p&gt;

&lt;h2 id=&quot;key-takeaways&quot;&gt;Key takeaways&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Polling consumers are pull-based.&lt;/strong&gt; They actively check for new data on a schedule, making them the right choice for sources that cannot push: databases, files, FTP, and scheduled batch jobs. The poll interval and &lt;code class=&quot;highlighter-rouge&quot;&gt;maxMessagesPerPoll&lt;/code&gt; provide natural backpressure control.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;pollEnrich()&lt;/code&gt; turns any route into a polling consumer.&lt;/strong&gt; A timer-triggered route with &lt;code class=&quot;highlighter-rouge&quot;&gt;pollEnrich()&lt;/code&gt; gives you explicit control over &lt;em&gt;when&lt;/em&gt; messages are consumed — useful when you need to decouple the consumption schedule from the source’s availability.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;SQL polling with &lt;code class=&quot;highlighter-rouge&quot;&gt;onConsume&lt;/code&gt; is a two-phase operation.&lt;/strong&gt; The SELECT reads the row; the &lt;code class=&quot;highlighter-rouge&quot;&gt;onConsume&lt;/code&gt; UPDATE marks it as processed. Both phases must be verified in the test — the Kafka output proves the read worked, and the SQL assertion proves the update ran.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;@variable(name)@&lt;/code&gt; captures dynamic values from the system under test.&lt;/strong&gt; Database-generated IDs cannot be predicted by the test. Citrus’s variable extraction lets you capture these values from the first assertion and use them in subsequent verifications.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;repeatOnError()&lt;/code&gt; accommodates poll timing naturally.&lt;/strong&gt; Rather than inserting fixed sleeps matching the poll interval, Citrus retries the assertion until it succeeds or the retry limit is reached — making tests both reliable and as fast as possible.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;verifyRouteStats&lt;/code&gt; verifies routes without external output.&lt;/strong&gt; When a polling consumer only logs or internally processes messages, Citrus’s Camel route statistics verification provides exchange counts as an alternative verification mechanism, with support for flexible matchers like &lt;code class=&quot;highlighter-rouge&quot;&gt;@greaterThan()@&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Three runtimes, one test pattern.&lt;/strong&gt; Whether you run on Quarkus, Spring Boot, or YAML DSL with Camel JBang, the test structure — seed the source, wait for the poll, verify the output and side effects — stays the same. Only the bootstrap annotations and infrastructure wiring change.&lt;/li&gt;
&lt;/ul&gt;</content><author><name></name></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://citrusframework.org/img/icons/camel.png" /></entry><entry><title type="html">Testing the Message Dispatcher Pattern with Citrus</title><link href="https://citrusframework.org/samples/camel-eip/message-dispatcher/" rel="alternate" type="text/html" title="Testing the Message Dispatcher Pattern with Citrus" /><published>2026-09-22T00:00:00+02:00</published><updated>2026-09-22T00:00:00+02:00</updated><id>https://citrusframework.org/samples/camel-eip/sample-eip-message-dispatcher</id><content type="html" xml:base="https://citrusframework.org/samples/camel-eip/message-dispatcher/">&lt;p&gt;As the number of event types flowing through a system grows, a common pattern emerges: a single Kafka topic carries messages of different types — orders placed, orders cancelled, orders refunded — and each type requires different processing logic.
You could duplicate a content-based router in every consuming service, but that scatters the routing logic across the codebase and makes it hard to see which types are handled where.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&quot;https://www.enterpriseintegrationpatterns.com/patterns/messaging/MessageDispatcher.html&quot;&gt;Message Dispatcher&lt;/a&gt; pattern, described by Hohpe and Woolf, centralizes this fan-out.
A single consumer reads from a channel and distributes each message to a type-specific handler based on a field in the message body.
The dispatcher is the only component that knows about the type-to-handler mapping — the handlers themselves are simple, focused routes that process one event type each.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://camel.apache.org&quot;&gt;Apache Camel&lt;/a&gt; implements this with &lt;code class=&quot;highlighter-rouge&quot;&gt;toD()&lt;/code&gt; (dynamic to), which resolves the target endpoint URI at runtime from the message content.
Combined with &lt;code class=&quot;highlighter-rouge&quot;&gt;direct:&lt;/code&gt; routes as handler endpoints, &lt;code class=&quot;highlighter-rouge&quot;&gt;toD()&lt;/code&gt; creates a clean dispatcher-handler architecture — one Kafka consumer, N handler routes, and a single routing expression that ties them together.&lt;/p&gt;

&lt;p&gt;This pattern is closely related to the content-based router but differs in intent and structure.
A content-based router decides &lt;em&gt;where&lt;/em&gt; a message goes (which channel, which queue).
A message dispatcher decides &lt;em&gt;who&lt;/em&gt; handles it (which handler route within the same application).
The router is about external routing; the dispatcher is about internal fan-out.&lt;/p&gt;

&lt;p&gt;Testing a message dispatcher requires a different approach than testing patterns that produce output on a Kafka topic.
The dispatcher’s handlers typically log, persist, or call internal services — they do not always publish to an external endpoint that the test can consume from.
Integration tests with &lt;a href=&quot;https://citrusframework.org&quot;&gt;Citrus&lt;/a&gt; handle this by leveraging Camel’s management API to verify that the correct handler route processed each message, including the edge case of unknown event types that no handler should accept.&lt;/p&gt;

&lt;h2 id=&quot;the-scenario&quot;&gt;The scenario&lt;/h2&gt;

&lt;p&gt;Order events arrive on the &lt;code class=&quot;highlighter-rouge&quot;&gt;eip.consumer.dispatch&lt;/code&gt; Kafka topic.
Each message carries an &lt;code class=&quot;highlighter-rouge&quot;&gt;event_type&lt;/code&gt; field that determines which handler processes it:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;order_placed&lt;/code&gt; events go to the order creation handler&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;order_cancelled&lt;/code&gt; events go to the cancellation handler&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;order_refunded&lt;/code&gt; events go to the refund handler&lt;/li&gt;
  &lt;li&gt;Unknown event types are caught by a fallback handler that logs and drops the message&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The dispatcher validates the event type against a whitelist before routing.
This is a deliberate security measure — without validation, a malicious or malformed &lt;code class=&quot;highlighter-rouge&quot;&gt;event_type&lt;/code&gt; value could cause &lt;code class=&quot;highlighter-rouge&quot;&gt;toD()&lt;/code&gt; to resolve to an unexpected endpoint, since the endpoint URI is constructed from user-controlled data.&lt;/p&gt;

&lt;h2 id=&quot;the-camel-route&quot;&gt;The Camel route&lt;/h2&gt;

&lt;h3 id=&quot;quarkus&quot;&gt;Quarkus&lt;/h3&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@ApplicationScoped&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;MessageDispatcherRoute&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RouteBuilder&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Set&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ALLOWED_EVENT_TYPES&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Set&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;of&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;s&quot;&gt;&quot;order_placed&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;order_cancelled&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;order_refunded&quot;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.consumer.dispatch?brokers={{kafka.brokers}}&quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&amp;amp;groupId=message-dispatcher&amp;amp;autoOffsetReset=earliest&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;message-dispatcher&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;unmarshal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Dispatcher received: order ${body[order_id]}, type=${body[event_type]}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;choice&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
                    &lt;span class=&quot;kt&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getIn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getBody&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;java&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;util&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
                    &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eventType&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;event_type&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
                    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eventType&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ALLOWED_EVENT_TYPES&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;contains&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;eventType&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;})&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;toD&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;direct:handle-${body[event_type]}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;otherwise&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;direct:handle-order_unknown&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;direct:handle-order_placed&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;handle-order-placed&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Handling ORDER PLACED: order ${body[order_id]}, &quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;amount=${body[amount]}, sku=${body[item_sku]}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;direct:handle-order_cancelled&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;handle-order-cancelled&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Handling ORDER CANCELLED: order ${body[order_id]}, &quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;refund pending for amount=${body[amount]}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;direct:handle-order_refunded&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;handle-order-refunded&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Handling ORDER REFUNDED: order ${body[order_id]}, &quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;amount=${body[amount]} returned to customer ${body[customer_id]}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;direct:handle-order_unknown&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;handle-order-unknown&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Unknown event_type '${body[event_type]}' — skipping&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;There are five routes in a single &lt;code class=&quot;highlighter-rouge&quot;&gt;RouteBuilder&lt;/code&gt;, and understanding their relationship is the key to understanding the pattern.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The dispatcher route&lt;/strong&gt; (&lt;code class=&quot;highlighter-rouge&quot;&gt;message-dispatcher&lt;/code&gt;) is the only route that consumes from Kafka.
It deserializes the JSON message and immediately enters a &lt;code class=&quot;highlighter-rouge&quot;&gt;choice()&lt;/code&gt; block.
The &lt;code class=&quot;highlighter-rouge&quot;&gt;when()&lt;/code&gt; predicate checks whether the &lt;code class=&quot;highlighter-rouge&quot;&gt;event_type&lt;/code&gt; field is present and belongs to the &lt;code class=&quot;highlighter-rouge&quot;&gt;ALLOWED_EVENT_TYPES&lt;/code&gt; set.
If the type is valid, &lt;code class=&quot;highlighter-rouge&quot;&gt;toD(&quot;direct:handle-${body[event_type]}&quot;)&lt;/code&gt; dynamically resolves the handler endpoint — for example, an &lt;code class=&quot;highlighter-rouge&quot;&gt;event_type&lt;/code&gt; of &lt;code class=&quot;highlighter-rouge&quot;&gt;order_placed&lt;/code&gt; routes to &lt;code class=&quot;highlighter-rouge&quot;&gt;direct:handle-order_placed&lt;/code&gt;.
If the type is invalid or missing, the &lt;code class=&quot;highlighter-rouge&quot;&gt;otherwise()&lt;/code&gt; branch routes to &lt;code class=&quot;highlighter-rouge&quot;&gt;direct:handle-order_unknown&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The handler routes&lt;/strong&gt; each consume from a &lt;code class=&quot;highlighter-rouge&quot;&gt;direct:&lt;/code&gt; endpoint and perform type-specific processing.
In this example, the handlers only log — in a production system, they would call services, write to databases, or publish to other topics.
Each handler has its own &lt;code class=&quot;highlighter-rouge&quot;&gt;routeId&lt;/code&gt;, which is what makes them individually verifiable in the tests.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;toD()&lt;/code&gt; call is the most powerful and the most dangerous part of this pattern.
It constructs an endpoint URI from the message body at runtime.
Without the &lt;code class=&quot;highlighter-rouge&quot;&gt;ALLOWED_EVENT_TYPES&lt;/code&gt; validation, a message with &lt;code class=&quot;highlighter-rouge&quot;&gt;event_type: &quot;../../admin&quot;&lt;/code&gt; would cause Camel to attempt resolving &lt;code class=&quot;highlighter-rouge&quot;&gt;direct:handle-../../admin&lt;/code&gt; as an endpoint — which would fail with a &lt;code class=&quot;highlighter-rouge&quot;&gt;ResolveEndpointFailedException&lt;/code&gt;, but the attempt itself is a code smell.
The whitelist approach ensures that only known, expected endpoints are ever resolved.&lt;/p&gt;

&lt;h3 id=&quot;spring-boot&quot;&gt;Spring Boot&lt;/h3&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@Component&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;MessageDispatcherRoute&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RouteBuilder&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Set&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ALLOWED_EVENT_TYPES&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Set&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;of&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;s&quot;&gt;&quot;order_placed&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;order_cancelled&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;order_refunded&quot;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.consumer.dispatch?brokers={{kafka.brokers}}&quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&amp;amp;groupId=message-dispatcher&amp;amp;autoOffsetReset=earliest&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;message-dispatcher&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;unmarshal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Dispatcher received: order ${body[order_id]}, type=${body[event_type]}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;choice&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
                    &lt;span class=&quot;kt&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getIn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getBody&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;java&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;util&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;Map&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
                    &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eventType&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;event_type&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
                    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eventType&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ALLOWED_EVENT_TYPES&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;contains&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;eventType&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;})&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;toD&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;direct:handle-${body[event_type]}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;otherwise&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;direct:handle-order_unknown&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;direct:handle-order_placed&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;handle-order-placed&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Handling ORDER PLACED: order ${body[order_id]}, &quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;amount=${body[amount]}, sku=${body[item_sku]}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;direct:handle-order_cancelled&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;handle-order-cancelled&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Handling ORDER CANCELLED: order ${body[order_id]}, &quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;refund pending for amount=${body[amount]}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;direct:handle-order_refunded&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;handle-order-refunded&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Handling ORDER REFUNDED: order ${body[order_id]}, &quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;amount=${body[amount]} returned to customer ${body[customer_id]}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;direct:handle-order_unknown&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;routeId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;handle-order-unknown&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Unknown event_type '${body[event_type]}' — skipping&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;@Component&lt;/code&gt; replaces &lt;code class=&quot;highlighter-rouge&quot;&gt;@ApplicationScoped&lt;/code&gt; — the route logic is identical across both runtimes.&lt;/p&gt;

&lt;h2 id=&quot;dispatcher-vs-content-based-router&quot;&gt;Dispatcher vs. content-based router&lt;/h2&gt;

&lt;p&gt;The message dispatcher looks similar to a content-based router, and the two patterns are often confused.
The distinction matters for testing:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Aspect&lt;/th&gt;
      &lt;th&gt;Content-Based Router&lt;/th&gt;
      &lt;th&gt;Message Dispatcher&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Purpose&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Route to different &lt;em&gt;channels&lt;/em&gt;&lt;/td&gt;
      &lt;td&gt;Dispatch to different &lt;em&gt;handlers&lt;/em&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;External endpoints (Kafka topics, queues)&lt;/td&gt;
      &lt;td&gt;Internal &lt;code class=&quot;highlighter-rouge&quot;&gt;direct:&lt;/code&gt; routes&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Test verification&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Receive from the output channel&lt;/td&gt;
      &lt;td&gt;Check which handler route ran&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Routing expression&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Static (&lt;code class=&quot;highlighter-rouge&quot;&gt;to()&lt;/code&gt;) or dynamic (&lt;code class=&quot;highlighter-rouge&quot;&gt;toD()&lt;/code&gt;)&lt;/td&gt;
      &lt;td&gt;Typically dynamic (&lt;code class=&quot;highlighter-rouge&quot;&gt;toD()&lt;/code&gt;)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Scope&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Inter-service routing&lt;/td&gt;
      &lt;td&gt;Intra-service fan-out&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;A content-based router test sends a message and receives it from the correct output topic — a 1:1 input-to-output verification.
A message dispatcher test sends a message and verifies that the correct &lt;em&gt;handler route&lt;/em&gt; processed it — a verification against Camel’s internal route management, not an external channel.&lt;/p&gt;

&lt;h2 id=&quot;message-template&quot;&gt;Message template&lt;/h2&gt;

&lt;p&gt;The tests use a JSON template with Citrus variable placeholders:&lt;/p&gt;

&lt;div class=&quot;language-json highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;order_id&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;err&quot;&gt;org.citrusframework&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;citrus-website&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;pom&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.1&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;customer_id&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;CUST-00org.citrusframework:citrus-website:pom:1.1.0&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;event_type&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;${eventType}&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;amount&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;err&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;amount&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;item_sku&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;SKU-org.citrusframework:citrus-website:pom:1.1.0&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;quantity&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;event_type&lt;/code&gt; field is the dispatch key — the variable &lt;code class=&quot;highlighter-rouge&quot;&gt;${eventType}&lt;/code&gt; is set differently in each test to exercise different handler routes.
The same template is reused across all four test cases; only the variables change.&lt;/p&gt;

&lt;h2 id=&quot;the-dispatcher-tests&quot;&gt;The dispatcher tests&lt;/h2&gt;

&lt;p&gt;The message dispatcher requires four test cases — one for each known event type plus one for the unknown type fallback.
Each test sends a single message with a specific &lt;code class=&quot;highlighter-rouge&quot;&gt;event_type&lt;/code&gt; and verifies that the corresponding handler route processed it.&lt;/p&gt;

&lt;h3 id=&quot;quarkus-tests&quot;&gt;Quarkus tests&lt;/h3&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@QuarkusTest&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@CitrusSupport&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;EipTests&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;implements&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;EipTestSupport&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@CitrusResource&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;TestCaseRunner&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Inject&lt;/span&gt;
    &lt;span class=&quot;nd&quot;&gt;@BindToRegistry&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;CamelContext&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Nested&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;MessageDispatcherTest&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

        &lt;span class=&quot;nd&quot;&gt;@Test&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;shouldDispatchOrderPlacedEvent&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;given&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;createVariables&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;variable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;citrus:randomNumber(4)&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;variable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;eventType&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;order_placed&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;variable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;amount&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;120&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;given&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;waitForCamelRouteStarted&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;message-dispatcher&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.consumer.dispatch&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Resources&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;templates/order.json&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;header&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;KafkaMessageHeaders&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;MESSAGE_KEY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;org.citrusframework:citrus-website:pom:1.1.0&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;verifyCompletedExchanges&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;handle-order-placed&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;nd&quot;&gt;@Test&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;shouldDispatchOrderCancelledEvent&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;given&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;createVariables&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;variable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;citrus:randomNumber(4)&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;variable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;eventType&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;order_cancelled&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;variable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;amount&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;80&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;given&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;waitForCamelRouteStarted&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;message-dispatcher&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.consumer.dispatch&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Resources&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;templates/order.json&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;header&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;KafkaMessageHeaders&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;MESSAGE_KEY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;org.citrusframework:citrus-website:pom:1.1.0&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;verifyCompletedExchanges&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;handle-order-cancelled&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;nd&quot;&gt;@Test&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;shouldDispatchOrderRefundedEvent&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;given&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;createVariables&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;variable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;citrus:randomNumber(4)&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;variable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;eventType&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;order_refunded&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;variable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;amount&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;55&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;given&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;waitForCamelRouteStarted&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;message-dispatcher&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.consumer.dispatch&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Resources&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;templates/order.json&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;header&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;KafkaMessageHeaders&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;MESSAGE_KEY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;org.citrusframework:citrus-website:pom:1.1.0&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;verifyCompletedExchanges&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;handle-order-refunded&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;nd&quot;&gt;@Test&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;shouldSkipUnknownEventType&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;given&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;createVariables&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;variable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;citrus:randomNumber(4)&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;variable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;eventType&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;order_unknown&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;variable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;amount&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;40&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;given&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;waitForCamelRouteStarted&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;message-dispatcher&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.consumer.dispatch&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Resources&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;templates/order.json&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;header&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;KafkaMessageHeaders&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;MESSAGE_KEY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;org.citrusframework:citrus-website:pom:1.1.0&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;verifyCompletedExchanges&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;handle-order-unknown&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;All four tests follow the same given-when-then structure.
The only thing that changes between them is the &lt;code class=&quot;highlighter-rouge&quot;&gt;eventType&lt;/code&gt; variable and the handler route ID passed to &lt;code class=&quot;highlighter-rouge&quot;&gt;verifyCompletedExchanges&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Given — set up variables and wait for the dispatcher.&lt;/strong&gt;
Each test generates a random order ID and sets the &lt;code class=&quot;highlighter-rouge&quot;&gt;eventType&lt;/code&gt; to the value that should trigger a specific handler.
The test then waits for the &lt;code class=&quot;highlighter-rouge&quot;&gt;message-dispatcher&lt;/code&gt; route to reach &lt;code class=&quot;highlighter-rouge&quot;&gt;Started&lt;/code&gt; status.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When — send an event to the dispatch topic.&lt;/strong&gt;
A single message goes to &lt;code class=&quot;highlighter-rouge&quot;&gt;kafka:eip.consumer.dispatch&lt;/code&gt; using the shared &lt;code class=&quot;highlighter-rouge&quot;&gt;order.json&lt;/code&gt; template.
The &lt;code class=&quot;highlighter-rouge&quot;&gt;eventType&lt;/code&gt; variable is resolved into the &lt;code class=&quot;highlighter-rouge&quot;&gt;event_type&lt;/code&gt; field of the JSON body.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Then — verify the correct handler processed the message.&lt;/strong&gt;
&lt;code class=&quot;highlighter-rouge&quot;&gt;verifyCompletedExchanges&lt;/code&gt; checks that the expected handler route completed exactly one exchange.
For &lt;code class=&quot;highlighter-rouge&quot;&gt;shouldDispatchOrderPlacedEvent&lt;/code&gt;, it asserts against &lt;code class=&quot;highlighter-rouge&quot;&gt;handle-order-placed&lt;/code&gt;.
For &lt;code class=&quot;highlighter-rouge&quot;&gt;shouldSkipUnknownEventType&lt;/code&gt;, it asserts against &lt;code class=&quot;highlighter-rouge&quot;&gt;handle-order-unknown&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id=&quot;the-unknown-event-type-test&quot;&gt;The unknown event type test&lt;/h3&gt;

&lt;p&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;shouldSkipUnknownEventType&lt;/code&gt; test deserves special attention because it verifies the dispatcher’s safety behavior.&lt;/p&gt;

&lt;p&gt;The test sets &lt;code class=&quot;highlighter-rouge&quot;&gt;eventType&lt;/code&gt; to &lt;code class=&quot;highlighter-rouge&quot;&gt;&quot;order_unknown&quot;&lt;/code&gt; — a value that is &lt;em&gt;not&lt;/em&gt; in the &lt;code class=&quot;highlighter-rouge&quot;&gt;ALLOWED_EVENT_TYPES&lt;/code&gt; set.
When the dispatcher receives this message, the &lt;code class=&quot;highlighter-rouge&quot;&gt;choice()&lt;/code&gt; predicate returns &lt;code class=&quot;highlighter-rouge&quot;&gt;false&lt;/code&gt;, and the &lt;code class=&quot;highlighter-rouge&quot;&gt;otherwise()&lt;/code&gt; branch routes the message to &lt;code class=&quot;highlighter-rouge&quot;&gt;direct:handle-order_unknown&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This test proves two things:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;The whitelist works.&lt;/strong&gt; An unknown event type does not reach &lt;code class=&quot;highlighter-rouge&quot;&gt;toD()&lt;/code&gt; — it is caught by the &lt;code class=&quot;highlighter-rouge&quot;&gt;choice()&lt;/code&gt; and routed to the fallback handler instead. Without this test, a code change that accidentally removes the whitelist check would go undetected.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;The fallback handler exists and processes successfully.&lt;/strong&gt; If the &lt;code class=&quot;highlighter-rouge&quot;&gt;direct:handle-order_unknown&lt;/code&gt; route were missing, the test would fail with a &lt;code class=&quot;highlighter-rouge&quot;&gt;NoSuchEndpointException&lt;/code&gt;. The &lt;code class=&quot;highlighter-rouge&quot;&gt;verifyCompletedExchanges&lt;/code&gt; check also verifies that the fallback handler completed without errors.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is a test that cannot be reasonably written with mocked endpoints.
The &lt;code class=&quot;highlighter-rouge&quot;&gt;toD()&lt;/code&gt; resolution, the &lt;code class=&quot;highlighter-rouge&quot;&gt;choice()&lt;/code&gt; predicate evaluation, and the &lt;code class=&quot;highlighter-rouge&quot;&gt;direct:&lt;/code&gt; endpoint dispatch all happen inside Camel’s routing engine — mocking any of these would bypass the exact logic being tested.&lt;/p&gt;

&lt;h3 id=&quot;spring-boot-tests&quot;&gt;Spring Boot tests&lt;/h3&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@SpringBootTest&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;classes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ConsumerPatternsApplication&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@CamelSpringBootTest&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@CitrusSpringSupport&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@ContextConfiguration&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;classes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;EipInfraSetup&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CitrusSpringConfig&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;})&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;EipTests&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;implements&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;EipTestSupport&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Autowired&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;CamelContext&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@Nested&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;MessageDispatcherTest&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

        &lt;span class=&quot;nd&quot;&gt;@CitrusResource&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;TestCaseRunner&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;nd&quot;&gt;@Test&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;shouldDispatchOrderPlacedEvent&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;given&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;createVariables&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;variable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;id&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;citrus:randomNumber(4)&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;variable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;eventType&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;order_placed&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;variable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;amount&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;120&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;given&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;waitForCamelRouteStarted&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;message-dispatcher&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;endpoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;kafka:eip.consumer.dispatch&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Resources&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;templates/order.json&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;))&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;header&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;KafkaMessageHeaders&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;MESSAGE_KEY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;org.citrusframework:citrus-website:pom:1.1.0&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;verifyCompletedExchanges&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;handle-order-placed&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;camelContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;nd&quot;&gt;@Test&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;shouldDispatchOrderCancelledEvent&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// Same structure — eventType=&quot;order_cancelled&quot;,&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// asserts against &quot;handle-order-cancelled&quot;&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// ...&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;nd&quot;&gt;@Test&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;shouldDispatchOrderRefundedEvent&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// Same structure — eventType=&quot;order_refunded&quot;,&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// asserts against &quot;handle-order-refunded&quot;&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// ...&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;nd&quot;&gt;@Test&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;shouldSkipUnknownEventType&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// Same structure — eventType=&quot;order_unknown&quot;,&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// asserts against &quot;handle-order-unknown&quot;&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// ...&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;what-the-tests-prove&quot;&gt;What the tests prove&lt;/h2&gt;

&lt;p&gt;The four tests together form a complete coverage of the dispatcher’s routing logic:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Positive dispatch tests&lt;/strong&gt; (&lt;code class=&quot;highlighter-rouge&quot;&gt;shouldDispatchOrderPlacedEvent&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;shouldDispatchOrderCancelledEvent&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;shouldDispatchOrderRefundedEvent&lt;/code&gt;) verify that each known event type reaches its designated handler.
They exercise the &lt;code class=&quot;highlighter-rouge&quot;&gt;toD()&lt;/code&gt; resolution with three different dynamic endpoint URIs:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;event_type=order_placed&lt;/code&gt; → &lt;code class=&quot;highlighter-rouge&quot;&gt;toD(&quot;direct:handle-order_placed&quot;)&lt;/code&gt; → route &lt;code class=&quot;highlighter-rouge&quot;&gt;handle-order-placed&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;event_type=order_cancelled&lt;/code&gt; → &lt;code class=&quot;highlighter-rouge&quot;&gt;toD(&quot;direct:handle-order_cancelled&quot;)&lt;/code&gt; → route &lt;code class=&quot;highlighter-rouge&quot;&gt;handle-order-cancelled&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;event_type=order_refunded&lt;/code&gt; → &lt;code class=&quot;highlighter-rouge&quot;&gt;toD(&quot;direct:handle-order_refunded&quot;)&lt;/code&gt; → route &lt;code class=&quot;highlighter-rouge&quot;&gt;handle-order-refunded&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Negative dispatch test&lt;/strong&gt; (&lt;code class=&quot;highlighter-rouge&quot;&gt;shouldSkipUnknownEventType&lt;/code&gt;) verifies that the whitelist rejects unknown types and routes them to the fallback handler.
This is the security-relevant test — it proves that arbitrary &lt;code class=&quot;highlighter-rouge&quot;&gt;event_type&lt;/code&gt; values cannot reach &lt;code class=&quot;highlighter-rouge&quot;&gt;toD()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Together, these tests verify the full routing table.
If a new event type is added to the application but not to the &lt;code class=&quot;highlighter-rouge&quot;&gt;ALLOWED_EVENT_TYPES&lt;/code&gt; set, it will be routed to the unknown handler — and a corresponding test should be added to cover the new type.&lt;/p&gt;

&lt;h2 id=&quot;the-test-design-pattern&quot;&gt;The test design pattern&lt;/h2&gt;

&lt;p&gt;The message dispatcher test suite demonstrates a repeatable pattern for testing internal fan-out:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;One test per dispatch target.&lt;/strong&gt; Each handler route gets its own test case with the corresponding input. This makes failures immediately diagnosable — if &lt;code class=&quot;highlighter-rouge&quot;&gt;shouldDispatchOrderRefundedEvent&lt;/code&gt; fails, you know exactly which path is broken.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;The dispatch key is the only variable that changes.&lt;/strong&gt; All four tests use the same template, the same topic, and the same given-when-then structure. Only &lt;code class=&quot;highlighter-rouge&quot;&gt;eventType&lt;/code&gt; and the assertion target differ. This minimizes the surface area for test bugs.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Verification targets the handler route, not the dispatcher.&lt;/strong&gt; The test does not assert against the &lt;code class=&quot;highlighter-rouge&quot;&gt;message-dispatcher&lt;/code&gt; route — it asserts against the &lt;em&gt;handler&lt;/em&gt; route that should have been invoked. This is deliberate: verifying the handler’s exchange count proves that the dispatcher made the correct routing decision &lt;em&gt;and&lt;/em&gt; that the &lt;code class=&quot;highlighter-rouge&quot;&gt;direct:&lt;/code&gt; dispatch succeeded.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Always test the fallback path.&lt;/strong&gt; The unknown event type test is not an afterthought — it verifies the dispatcher’s safety net. In production systems, unknown event types can appear due to schema evolution, message corruption, or cross-version compatibility issues. The fallback handler and its test ensure the dispatcher does not throw exceptions or route to unexpected endpoints when this happens.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;why-verifycompletedexchanges-is-the-right-tool-here&quot;&gt;Why &lt;code class=&quot;highlighter-rouge&quot;&gt;verifyCompletedExchanges&lt;/code&gt; is the right tool here&lt;/h2&gt;

&lt;p&gt;For patterns that produce output on a Kafka topic, the natural Citrus assertion is &lt;code class=&quot;highlighter-rouge&quot;&gt;receive()&lt;/code&gt; — consume from the output topic and validate the message body.
The message dispatcher’s handlers do not produce external output, so &lt;code class=&quot;highlighter-rouge&quot;&gt;receive()&lt;/code&gt; has nothing to consume.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;verifyCompletedExchanges&lt;/code&gt; solves this by using Citrus’s built-in Camel route statistics verification:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Exchange count.&lt;/strong&gt; Has the handler route completed exactly the expected number of exchanges? For a dispatcher test that sends one message, the expected count is 1.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Error detection.&lt;/strong&gt; The route statistics verification checks for failed exchanges automatically. A &lt;code class=&quot;highlighter-rouge&quot;&gt;ResolveEndpointFailedException&lt;/code&gt; from a bad &lt;code class=&quot;highlighter-rouge&quot;&gt;toD()&lt;/code&gt; target, a serialization error in the handler, or any other exception is detected, providing a clear signal.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Retry tolerance.&lt;/strong&gt; The &lt;code class=&quot;highlighter-rouge&quot;&gt;repeatOnError()&lt;/code&gt; wrapper retries up to 20 times with 1-second intervals. This accommodates Kafka consumer lag — the dispatcher route might not have consumed and dispatched the message by the time the assertion first runs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This pattern applies to any route that processes messages internally without producing verifiable output on an external channel: logging routes, metric-emitting routes, routes that call internal services, and — as in this case — dispatcher handler routes.&lt;/p&gt;

&lt;p&gt;For the test infrastructure setup, shared test utilities, runtime wiring, dependencies, and how to run the tests, see the &lt;a href=&quot;/samples/camel-eip/&quot;&gt;Camel EIP examples&lt;/a&gt; overview page.&lt;/p&gt;

&lt;h2 id=&quot;key-takeaways&quot;&gt;Key takeaways&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Message dispatchers centralize type-based routing.&lt;/strong&gt; A single Kafka consumer with &lt;code class=&quot;highlighter-rouge&quot;&gt;toD()&lt;/code&gt; fans out to N handler routes, keeping the routing logic in one place rather than scattered across consuming services.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Whitelist validation is essential with &lt;code class=&quot;highlighter-rouge&quot;&gt;toD()&lt;/code&gt;.&lt;/strong&gt; Because &lt;code class=&quot;highlighter-rouge&quot;&gt;toD()&lt;/code&gt; constructs endpoint URIs from message content, untrusted values must be validated against a known set before reaching the dynamic expression. The &lt;code class=&quot;highlighter-rouge&quot;&gt;ALLOWED_EVENT_TYPES&lt;/code&gt; set and the &lt;code class=&quot;highlighter-rouge&quot;&gt;choice()&lt;/code&gt; guard implement this pattern.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Test every dispatch target, including the fallback.&lt;/strong&gt; One test per handler route ensures complete coverage of the routing table. The unknown event type test verifies that the safety net works — it is not optional.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;verifyCompletedExchanges&lt;/code&gt; verifies internal routing decisions.&lt;/strong&gt; When handler routes do not produce external output, Citrus’s Camel route statistics verification provides exchange counts as an alternative verification mechanism. This makes the test independent of what the handler actually does.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;One template, N tests.&lt;/strong&gt; The same message template serves all four test cases. Only the &lt;code class=&quot;highlighter-rouge&quot;&gt;eventType&lt;/code&gt; variable and the assertion target change — this keeps the test suite focused on the routing decision, not the message structure.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Two runtimes, one test pattern.&lt;/strong&gt; The test logic is identical across Quarkus and Spring Boot. Only the bootstrap annotations and dependency injection differ — the given-when-then flow, the template, and the assertions stay the same.&lt;/li&gt;
&lt;/ul&gt;</content><author><name></name></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://citrusframework.org/img/icons/camel.png" /></entry></feed>