Skip to content

Can't load counter kamelet with a bean #2771

Description

@skin27

I try to run the Counter Kamelet:

https://github.com/apache/camel-kamelets/blob/main/kamelets/counter-source.kamelet.yaml

This Kamelet defines a bean:

apiVersion: camel.apache.org/v1

kind: Kamelet

metadata:

  name: counter-source

  labels:

    camel.apache.org/kamelet.type: "source"

spec:

  definition:

    title: "Counter Source"

    description: "Generates sequential number events starting from a configurable value, incrementing by a specified step. Useful for testing, scheduled tasks, or creating ordered event sequences."

    type: object

    properties:

      period:

        title: Period

        description: The time interval between two numbers

        type: integer

        default: 1000

      start:

        title: Starting Number

        description: The starting number

        type: integer

        default: 1

      numbers:

        title: Numbers

        description: How many numbers to generate

        type: integer

      in:

        title: "Source Endpoint"

        type: "string"

        default: "kamelet:source"

      out:

        title: "Sink Endpoint"

        type: "string"

        default: "kamelet:sink"

      routeId:

        title: "Route ID"

        type: "string"

      routeConfigurationId:

        title: "Route Configuration ID"

        type: "string"

        default: "0"

  dependencies:

    - "camel:timer"

    - "camel:core"

    - "camel:bean"

    - "camel:kamelet"

  template:

    beans:

      - name: counter

        type: java.util.concurrent.atomic.AtomicInteger

        constructors:

          "0": "{{start}}"

    route:

      routeConfigurationId: "{{routeConfigurationId}}"

      from:

        uri: "timer:counter"

        parameters:

          period: "{{period}}"

          repeatCount: "{{?numbers}}"

        steps:

          - bean:

              ref: "{{counter}}"

              method: getAndIncrement

          - setHeader:

              name: "Content-Type"

              constant: "text/plain"

          - to: "{{out}}"

When running it with {{counter}} I get:

Property with key [counter] not found in properties from text: {{counter}}

I also tried with a few other syntax such as:

          - bean:

              ref: "counter"

              method: getAndIncrement

or

steps:
          - to: "bean:counter?method=getAndIncrement"

However, in those cases I get:

No bean could be found in the registry for: counter

Note: It seems that when the bean is defined within the Kamelet it's not registered/in scope of the registry. I am using a SimpleRegistry:

private final SimpleRegistry registry = new SimpleRegistry();

When I define beans globally/programmatically it works fine (camel-bean is on my classpath).

What is the correct syntax?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions