allthingssecurity opened a new pull request, #30467: URL: https://github.com/apache/camel/pull/30467
# Description [CAMEL-27211](https://issues.apache.org/jira/browse/CAMEL-27211) `TahuHostConsumer` took its `TahuHostApplication` from a static map keyed by the host id, and built one only for the first consumer of that host id in the JVM. That host application gives the Sparkplug messages to the methods of the consumer that built it, and connects with the servers and credentials of that consumer's endpoint; nothing ever removed it from the map. Any later consumer of the same host id got the old host application: the consumer of a route that is reloaded (route reload, `camel run --dev`), removed and added again, or a route of another CamelContext in the same JVM (a CamelContext started again, tests that start several contexts). Its start started the old host application again, which gave every message to the old, stopped consumer: the new route received nothing, and changed `servers`, `clientId` or credentials were ignored. A consumer stopped and started again (the same instance) was not affected. Fix: - Each `TahuHostConsumer` builds its own host application, with its own endpoint's configuration and its own message and metric handlers. The static map is removed. - `TahuHostApplication` keeps its event handler and gives it out (`getEventHandler()`), and the consumer has a package-private `getTahuHostApplication()`, both used by the test. Two consumers that run at the same time with the same host id were not supported before either (the messages went to the first consumer only, and stopping either stopped the host application of both); with the fix each one connects on its own, with the client id of its endpoint. Tests: `TahuHostConsumerHostApplicationTest` (no MQTT server: the consumers are only initialized, as starting connects) gives an NDATA message to the event handler of a consumer's host application, as Tahu does for a message it receives: a second consumer created for the same host id (as for a route that is reloaded, or removed and added again) gets the message, with a host application of its own, and consumers of two CamelContexts with the same host id each get their own. Runs: both tests fail on main (with only the two accessors added, so that the test compiles: the message goes to the first consumer); they pass with the fix; camel-tahu module unit tests 20 run, 0 failures (the ITs need an MQTT broker container and were not run locally; CI runs them); the new test class 20 times in one JVM: 40 of 40. # Target - [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch) # Tracking - [x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it): [CAMEL-27211](https://issues.apache.org/jira/browse/CAMEL-27211). # Apache Camel coding standards and style - [x] I checked that each commit in the pull request has a meaningful subject line and body. - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes. (I built the core modules and camel-tahu with the formatter and import-sort plugins. No option or doc changed. I did not run the full root build.) # AI-assisted contributions - [x] If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR description identifies the AI tool used. This PR was prepared with Claude Code (Claude Opus 5.5). The commit carries a `Co-Authored-By` trailer. _Claude Code on behalf of allthingssecurity_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
