Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CAMEL-19308: Add minimal support of native mode #857

Merged
merged 1 commit into from Jun 20, 2023

Conversation

essobedo
Copy link
Contributor

@essobedo essobedo commented Jun 16, 2023

fix for https://issues.apache.org/jira/browse/CAMEL-19308

Motivation

Spring Boot 3 proposes the native mode out of the box, we would like to allow Camel SB users to leverage this new feature to build native images from routes written using the Java, XML, and/or YAML DSL.

Modifications:

  • Workarounds the limitations of the native mode that prevented a Camel SB application from starting in native mode
  • Adds a new starter for JAXB to be able to provide the hints/substitutions required for the native mode. The code is more or less equivalent to what is done in the JAXB extension of Quarkus (Needed for the XML DSL)
  • Adds general hints required for a Camel SB application

Result

Simple routes (without complex components) written in Java, XML, and YAML DSL can be compiled and launched in native mode.

JVM mode

2023-06-16T18:38:25.323+02:00  INFO 6783 --- [           main] c.e.cameldemo.CameldemoApplication       : Starting CameldemoApplication using Java 17.0.7 with PID 6783 (/Users/nicolasfilotto/test/cameldemo/target/classes started by nicolasfilotto in /Users/nicolasfilotto/test/cameldemo)
2023-06-16T18:38:25.327+02:00  INFO 6783 --- [           main] c.e.cameldemo.CameldemoApplication       : No active profile set, falling back to 1 default profile: "default"
2023-06-16T18:38:27.189+02:00  INFO 6783 --- [           main] o.a.c.impl.engine.AbstractCamelContext   : Apache Camel 4.0.0-SNAPSHOT (camel-1) is starting
2023-06-16T18:38:27.202+02:00  INFO 6783 --- [           main] c.s.b.CamelSpringBootApplicationListener : Starting CamelMainRunController to ensure the main thread keeps running
2023-06-16T18:38:27.202+02:00  INFO 6783 --- [inRunController] org.apache.camel.main.MainSupport        : Apache Camel (Main) 4.0.0-SNAPSHOT is starting
2023-06-16T18:38:27.212+02:00  INFO 6783 --- [           main] o.a.c.impl.engine.AbstractCamelContext   : Routes startup (started:8)
2023-06-16T18:38:27.212+02:00  INFO 6783 --- [           main] o.a.c.impl.engine.AbstractCamelContext   :     Started MyCamelRouter (timer://hello)
2023-06-16T18:38:27.213+02:00  INFO 6783 --- [           main] o.a.c.impl.engine.AbstractCamelContext   :     Started timer-route (timer://myTimer)
2023-06-16T18:38:27.213+02:00  INFO 6783 --- [           main] o.a.c.impl.engine.AbstractCamelContext   :     Started route1 (timer://yaml)
2023-06-16T18:38:27.213+02:00  INFO 6783 --- [           main] o.a.c.impl.engine.AbstractCamelContext   :     Started hello (timer://hello)
2023-06-16T18:38:27.213+02:00  INFO 6783 --- [           main] o.a.c.impl.engine.AbstractCamelContext   :     Started route6 (timer://one)
2023-06-16T18:38:27.213+02:00  INFO 6783 --- [           main] o.a.c.impl.engine.AbstractCamelContext   :     Started route7 (timer://deux)
2023-06-16T18:38:27.213+02:00  INFO 6783 --- [           main] o.a.c.impl.engine.AbstractCamelContext   :     Started route8 (timer://one)
2023-06-16T18:38:27.213+02:00  INFO 6783 --- [           main] o.a.c.impl.engine.AbstractCamelContext   :     Started route9 (timer://deux)
2023-06-16T18:38:27.213+02:00  INFO 6783 --- [           main] o.a.c.impl.engine.AbstractCamelContext   : Apache Camel 4.0.0-SNAPSHOT (camel-1) started in 22ms (build:0ms init:0ms start:22ms)
2023-06-16T18:38:27.223+02:00  INFO 6783 --- [           main] c.e.cameldemo.CameldemoApplication       : Started CameldemoApplication in 2.273 seconds (process running for 2.618)

8 routes (a mix of Java, XML, and YAML) started in a little bit less than 3 seconds

Native mode

2023-06-16T18:37:28.868+02:00  INFO 6562 --- [           main] c.e.cameldemo.CameldemoApplication       : Starting AOT-processed CameldemoApplication using Java 17.0.7 with PID 6562 (/Users/nicolasfilotto/test/cameldemo/target/cameldemo started by nicolasfilotto in /Users/nicolasfilotto/test/cameldemo)
2023-06-16T18:37:28.868+02:00  INFO 6562 --- [           main] c.e.cameldemo.CameldemoApplication       : No active profile set, falling back to 1 default profile: "default"
2023-06-16T18:37:29.173+02:00  INFO 6562 --- [           main] o.a.c.impl.engine.AbstractCamelContext   : Apache Camel 4.0.0-SNAPSHOT (camel-1) is starting
2023-06-16T18:37:29.173+02:00  INFO 6562 --- [           main] c.s.b.CamelSpringBootApplicationListener : Starting CamelMainRunController to ensure the main thread keeps running
2023-06-16T18:37:29.173+02:00  INFO 6562 --- [inRunController] org.apache.camel.main.MainSupport        : Apache Camel (Main) 4.0.0-SNAPSHOT is starting
2023-06-16T18:37:29.174+02:00  INFO 6562 --- [           main] o.a.c.impl.engine.AbstractCamelContext   : Routes startup (started:8)
2023-06-16T18:37:29.174+02:00  INFO 6562 --- [           main] o.a.c.impl.engine.AbstractCamelContext   :     Started MyCamelRouter (timer://hello)
2023-06-16T18:37:29.174+02:00  INFO 6562 --- [           main] o.a.c.impl.engine.AbstractCamelContext   :     Started timer-route (timer://myTimer)
2023-06-16T18:37:29.174+02:00  INFO 6562 --- [           main] o.a.c.impl.engine.AbstractCamelContext   :     Started route1 (timer://yaml)
2023-06-16T18:37:29.174+02:00  INFO 6562 --- [           main] o.a.c.impl.engine.AbstractCamelContext   :     Started hello (timer://hello)
2023-06-16T18:37:29.174+02:00  INFO 6562 --- [           main] o.a.c.impl.engine.AbstractCamelContext   :     Started route6 (timer://one)
2023-06-16T18:37:29.174+02:00  INFO 6562 --- [           main] o.a.c.impl.engine.AbstractCamelContext   :     Started route7 (timer://deux)
2023-06-16T18:37:29.174+02:00  INFO 6562 --- [           main] o.a.c.impl.engine.AbstractCamelContext   :     Started route8 (timer://one)
2023-06-16T18:37:29.174+02:00  INFO 6562 --- [           main] o.a.c.impl.engine.AbstractCamelContext   :     Started route9 (timer://deux)
2023-06-16T18:37:29.174+02:00  INFO 6562 --- [           main] o.a.c.impl.engine.AbstractCamelContext   : Apache Camel 4.0.0-SNAPSHOT (camel-1) started in 0ms (build:0ms init:0ms start:0ms)
2023-06-16T18:37:29.174+02:00  INFO 6562 --- [           main] c.e.cameldemo.CameldemoApplication       : Started CameldemoApplication in 0.326 seconds (process running for 0.338)

8 routes (a mix of Java, XML, and YAML) started in a little bit more than 300 milliseconds

pom.xml Outdated Show resolved Hide resolved
@davsclaus
Copy link
Contributor

I wonder if the SB aot stuff can be in its own module in core, eg core/camel-spring-boot-aot

@essobedo
Copy link
Contributor Author

I wonder if the SB aot stuff can be in its own module in core, eg core/camel-spring-boot-aot

Well, it depends on what is your objective behind?

Technically speaking it is of course doable, but in practice, you will need to do the same for each existing starter which means twice more modules to build/publish/test/maintain/release... Moreover, if I did it like this it is because it is how it is done in Spring / Spring Boot, the aot code is a specific package in each module as you can see by yourself for example for spring-beans https://github.com/spring-projects/spring-framework/tree/main/spring-beans/src/main/java/org/springframework/beans/factory/aot

@essobedo
Copy link
Contributor Author

Related ticket created in Spring spring-projects/spring-framework#30654

@essobedo essobedo force-pushed the CAMEL-19308/add-minimal-aot-support branch 2 times, most recently from 8562d4f to 611a74f Compare June 20, 2023 09:02
@essobedo essobedo force-pushed the CAMEL-19308/add-minimal-aot-support branch from 611a74f to 92f34ac Compare June 20, 2023 09:04
@essobedo
Copy link
Contributor Author

@davsclaus Is it ok as it is, or would you prefer a dedicated module for AOT?

@davsclaus
Copy link
Contributor

Yeah its okay.

However I am just concerned that maintaining this can be causing pain with graalvm changes and mysterious aot issues. The quarkus team have spent endless time with all of this.

And the outcome is that < 1% uses this today.

BTW for XML DSL then use camel-xml-io instead of jaxb based, then its fast and light OOTB and dont need any AOT magic. The JAXB is legacy and hopefully in Camel v5 we can remove JAXB DSLs

@essobedo
Copy link
Contributor Author

BTW for XML DSL then use camel-xml-io instead of jaxb based, then its fast and light OOTB and dont need any AOT magic. The JAXB is legacy and hopefully in Camel v5 we can remove JAXB DSLs

Oups, good catch, I forgot it, let me retry with camel-xml-io

@davsclaus
Copy link
Contributor

Where you would need jaxb is if you use Spring XML files, eg <beans> which has spring bean stuff as well. If you only have Camel XML routes then xml-io parser is better to use.

@essobedo
Copy link
Contributor Author

I confirm that it works properly with camel-xml-io, so let's merge it

@essobedo essobedo merged commit 813fd72 into main Jun 20, 2023
2 checks passed
@essobedo essobedo deleted the CAMEL-19308/add-minimal-aot-support branch June 20, 2023 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants