Hello Steffen, and welcome to Apache Camel :)
The problem you're facing is related to the way you're coding the yaml as
the ID is a configuration you can override for the route (as you can also
see in the xml dsl). Try this one instead:
- route:
id: myRoute2
from:
uri: "timer:yaml"
parameters:
period: "1000"
steps:
- setBody:
simple: "Hello Camel from ${routeId}"
- log: "${body}"
$ camel run test.yaml
2023-10-19 13:07:17.876 INFO 439921 --- [ main]
org.apache.camel.main.MainSupport : Apache Camel (JBang) 4.0.0 is starting
2023-10-19 13:07:18.056 INFO 439921 --- [ main]
org.apache.camel.main.MainSupport : Using Java 17.0.7 with PID 439921.
Started by squake in /home/squake/workspace/fuse-camel-k-image
2023-10-19 13:07:18.830 INFO 439921 --- [ main]
mel.cli.connector.LocalCliConnector : Camel CLI enabled (local)
2023-10-19 13:07:18.909 INFO 439921 --- [ main]
el.impl.engine.AbstractCamelContext : Apache Camel 4.0.0 (test) is starting
2023-10-19 13:07:19.077 INFO 439921 --- [ main]
el.impl.engine.AbstractCamelContext : Routes startup (started:1)
2023-10-19 13:07:19.077 INFO 439921 --- [ main]
el.impl.engine.AbstractCamelContext : Started myRoute2 (timer://yaml)
2023-10-19 13:07:19.078 INFO 439921 --- [ main]
el.impl.engine.AbstractCamelContext : Apache Camel 4.0.0 (test) started in
168ms (build:0ms init:0ms start:168ms)
2023-10-19 13:07:20.101 INFO 439921 --- [ - timer://yaml] test.yaml:13
: Hello Camel from myRoute2
Cheers,
Pasquale.
On Thu, Oct 19, 2023 at 11:50 AM Steffen Salewski
<[email protected]> wrote:
> Hello,
>
> first of all: This is my very first mail in this mailing list, and I am
> still learning the potential of Camel, so please give me any advise if I
> can make better 🙂
>
> Summary:
> I want to manage routes at runtime, and for this it is essential that I
> can identify a rule by its ID so that I am able to modify or remove it. I
> choosed YAML as my preferred DSL, but it seems that the ID attribute is not
> regarded and the route still gets its generic name instead. This seems like
> a bug for me, as with XML, the ID is used as expected. So before I fill in
> a bug report I ask (as requested) here if I am doing anything wrong or if
> you think that this is really a bug.
>
> Test case:
> A very simple Spring-Boot/Camel project:
>
> pom.xml:
> <?xml version="1.0" encoding="UTF-8"?>
> <project xmlns="http://maven.apache.org/POM/4.0.0"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
> http://maven.apache.org/xsd/maven-4.0.0.xsd">
> <modelVersion>4.0.0</modelVersion>
>
> <groupId>my.camel.testing</groupId>
> <artifactId>camle-testing</artifactId>
> <version>1.0-SNAPSHOT</version>
>
> <properties>
> <maven.compiler.source>17</maven.compiler.source>
> <maven.compiler.target>17</maven.compiler.target>
> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
>
> <camel.version>4.0.1</camel.version>
> </properties>
>
> <dependencies>
> <dependency>
> <groupId>org.apache.camel.springboot</groupId>
> <artifactId>camel-spring-boot</artifactId>
> <version>${camel.version}</version>
> </dependency>
> <dependency>
> <groupId>org.apache.camel.springboot</groupId>
> <artifactId>camel-spring-boot-starter</artifactId>
> <version>${camel.version}</version>
> </dependency>
> <dependency>
> <groupId>org.apache.camel</groupId>
> <artifactId>camel-xml-io</artifactId>
> <version>${camel.version}</version>
> </dependency>
> <dependency>
> <groupId>org.apache.camel</groupId>
> <artifactId>camel-xml-io-dsl</artifactId>
> <version>${camel.version}</version>
> </dependency>
> <dependency>
> <groupId>org.apache.camel</groupId>
> <artifactId>camel-yaml-dsl</artifactId>
> <version>${camel.version}</version>
> </dependency>
> </dependencies>
> </project>
>
> Application.java:
> @SpringBootApplication
> public class Application {
> public static void main(String[] args) {
> SpringApplication.run(Application.class, args);
> }
> }
>
> Routes (placed in $PROJECT_HOME/camel/, autodetected by
> camel-spring-boot-starter):
> myroute1.xml:
> <routes xmlns="http://camel.apache.org/schema/spring">
> <route id="myRoute1">
> <from uri="timer:tick"/>
> <setBody>
> <constant>Hello Camel!</constant>
> </setBody>
> <to uri="log:info1"/>
> </route>
> </routes>
>
> myroute2.yaml:
> - from:
> id: myRoute2
> uri: timer:tick
> steps:
> - setBody:
> constant: Hello Camel!
> - to:
> uri: log:info2
>
> I understand that both routes should be doing the same thing and the only
> difference is the ID.
>
> When I start the application, the log shows this:
> ...
> 023-10-19T10:41:34.142+02:00 INFO 17160 --- [ main]
> o.a.c.impl.engine.AbstractCamelContext : Routes startup (started:2)
> 2023-10-19T10:41:34.142+02:00 INFO 17160 --- [ main]
> o.a.c.impl.engine.AbstractCamelContext : Started myRoute1
> (timer://tick)
> 2023-10-19T10:41:34.142+02:00 INFO 17160 --- [ main]
> o.a.c.impl.engine.AbstractCamelContext : Started route1 (timer://tick)
> 2023-10-19T10:41:34.142+02:00 INFO 17160 --- [ main]
> o.a.c.impl.engine.AbstractCamelContext : Apache Camel 4.0.1 (camel-1)
> started in 15ms (build:0ms init:0ms start:15ms)
> ...
>
> Note that the XML route was loaded using the correct ID (myRoute1), but
> the YAML is using a generic ID (route1). I would expect that the output is:
> Routes startup (started:2)
> Started myRoute1 (timer://tick)
> Started myRoute2 (timer://tick)
> Apache Camel 4.0.1 (camel-1) started in ...
>
> Tested and verified with Camel v4.0.1 and v4.1.0
>
> So, it seems like a bug in the YAML route builder. What do you think?
>
> Thank you & kind regards,
> Steffen
>
> // added to skip company footer: 27948 //