You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "oscerd (via GitHub)" <gi...@apache.org> on 2026/09/14 07:58:15 UTC

[PR] Fix #2771: drop the AtomicInteger bean from counter-source [camel-kamelets]

oscerd opened a new pull request, #3025:
URL: https://github.com/apache/camel-kamelets/pull/3025

   Fixes #2771.
   
   @skin27 was right, and the workaround he posted is the fix — this ships it.
   
   ## What was wrong
   
   A Kamelet template bean is registered under a **generated** name. `{{counter}}` resolves to that name *inside* the template, which is why `counter-source` works fine under Camel K and Camel JBang. But the bean is not addressable from a registry built programmatically — he saw it registered as `myBean01`, reachable neither as `#myBean` nor by the literal name:
   
   ```
   Property with key [counter] not found in properties from text: {{counter}}
   No bean could be found in the registry for: counter
   ```
   
   So the Kamelet was effectively unusable outside the runtimes that instantiate it as a route template.
   
   ## The fix
   
   The counter never needed a bean. A route-scoped variable gives the same sequence with no registry involvement:
   
   ```yaml
           - choice:
               when:
                 - simple: "${variable.route:counter} == null"
                   steps:
                     - setVariable:
                         name: route:counter
                         simple:
                           expression: "{{start}}"
                           resultType: java.lang.Integer
               otherwise:
                 steps:
                   - setVariable:
                       name: route:counter
                       simple:
                         expression: "${variable.route:counter}++"
                         resultType: java.lang.Integer
           - setBody:
               simple: "${variable.route:counter}"
   ```
   
   `camel:bean` is no longer needed and is dropped from `spec.dependencies`.
   
   This is @skin27's implementation, worked out on the issue after he hit the problem. Credited in the commit.
   
   ## Behaviour is unchanged
   
   Verified both implementations side by side with the same parameters (`start=7`):
   
   | | first three emissions | body type | Content-Type |
   |---|---|---|---|
   | `AtomicInteger` bean (before) | 7, 8, 9 | `Integer` | `text/plain` |
   | route variable (after) | 7, 8, 9 | `Integer` | `text/plain` |
   
   Matching `AtomicInteger.getAndIncrement()` semantics — the first firing emits `start`, not `start+1`.
   
   ## One difference worth naming
   
   `AtomicInteger` is atomic; a variable read-modify-write is not. That is not a regression in practice — the source is driven by `timer:counter`, which is single-threaded, so there is no concurrent increment to lose. Worth knowing if anyone later makes the consumer concurrent.
   
   `setVariable` and route-scoped variables need Camel 4.4+; the catalog targets 4.22, so there is no floor problem here.
   
   ## Verification
   
   `script/validator` reports no errors, `script/generator` produces no doc changes, `mvn clean install` passes with tests from the repository root.
   
   ---
   _Claude Code on behalf of Andrea Cosentino_
   


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix #2771: drop the AtomicInteger bean from counter-source [camel-kamelets]

Posted by "oscerd (via GitHub)" <gi...@apache.org>.
oscerd merged PR #3025:
URL: https://github.com/apache/camel-kamelets/pull/3025


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org