This is an automated email from the ASF dual-hosted git repository.
oscerd pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-kamelets.git
The following commit(s) were added to refs/heads/main by this push:
new 1282e14e7 Fix #2771: drop the AtomicInteger bean from counter-source
(#3025)
1282e14e7 is described below
commit 1282e14e789be8726dcf5e85adde4c5dcaa177d2
Author: Andrea Cosentino <[email protected]>
AuthorDate: Mon Sep 14 10:42:07 2026 +0200
Fix #2771: drop the AtomicInteger bean from counter-source (#3025)
A template bean is registered under a generated name. Inside the template
{{counter}} resolves to it, which is why the Kamelet works under Camel K and
JBang, but the bean is not addressable from a registry the user builds
programmatically -- the reporter saw it registered as myBean01 and could
reach it neither as #myBean nor by the literal name.
The counter does not need a bean. A route scoped variable gives the same
sequence with no registry involvement, so the Kamelet now seeds
route:counter from start on the first firing and increments it afterwards.
camel:bean is no longer required and is dropped from the dependencies.
Behaviour is unchanged: start, start+1, start+2 ... as Integer with
Content-Type text/plain, matching AtomicInteger.getAndIncrement. Verified
against the previous implementation with the same parameters -- both emit
7, 8, 9 for start=7.
The implementation is the one @skin27 worked out and posted on the issue
after hitting the bean problem.
Claude-Session: https://claude.ai/code/session_01Bh2BAL99hwQ6o6uuALi9od
Co-authored-by: Claude Opus 5 <[email protected]>
---
kamelets/counter-source.kamelet.yaml | 32 +++++++++++++++++++++++---------
1 file changed, 23 insertions(+), 9 deletions(-)
diff --git a/kamelets/counter-source.kamelet.yaml
b/kamelets/counter-source.kamelet.yaml
index 0a79acab6..6be1e0d07 100644
--- a/kamelets/counter-source.kamelet.yaml
+++ b/kamelets/counter-source.kamelet.yaml
@@ -52,23 +52,37 @@ spec:
dependencies:
- "camel:timer"
- "camel:core"
- - "camel:bean"
- "camel:kamelet"
template:
- beans:
- - name: counter
- type: java.util.concurrent.atomic.AtomicInteger
- constructors:
- "0": "{{start}}"
from:
uri: timer:counter
parameters:
period: "{{period}}"
repeatCount: "{{?numbers}}"
steps:
- - bean:
- ref: "{{counter}}"
- method: getAndIncrement
+ # The counter is held in a route scoped variable rather than an
+ # AtomicInteger bean. A template bean is registered under a generated
+ # name, which resolves through {{counter}} inside the template but is
not
+ # addressable from a programmatically built registry, so the bean form
+ # could not be used outside Camel K and JBang. See #2771.
+ - 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}"
- setHeader:
name: "Content-Type"
constant: "text/plain"