Skip to content

Latest commit

 

History

History
 
 

timer-log-main

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Custom main(): A Camel Quarkus example

{cq-description}

A custom main() method may be useful if you need to implement some custom logic that needs to be executed before starting the Camel context. In this example we do some processing of the command line parameters.

Tip
IDEs typically allow for starting main() methods directly from an open editor. This may come in handy when developing.
Tip
Check the Camel Quarkus User guide for prerequisites and other general information.

Start in the Development mode

The main() method implemented in the org.acme.timer.Main requires two arguments: a greeting and a number how many times should the greeting be printed in the log. So we need to pass these two via -Dquarkus.args so that the dev mode does not start with an error:

$ mvn clean compile quarkus:dev -Dquarkus.args='Hello 2'

The above command compiles the project, starts the application and lets the Quarkus tooling watch for changes in your workspace. Any modifications in your project will automatically take effect in the running application.

Tip
Please refer to the Development mode section of Camel Quarkus User guide for more details.

Then look at the log output in the console. As we run the example in Quarkus Dev Mode, you can edit the source code and have live updates. For example try to change greeting = args[i];` to `greeting = args[i] + "!!!"; in the main() method and you should see the application being recompiled, restarted and the greeting with three exclamation marks should appear in the console.

Package and run the application

Once you are done with developing you may want to package and run the application.

Tip
Find more details about the JVM mode and Native mode in the Package and run section of Camel Quarkus User guide

JVM mode

$ mvn clean package
$ java -jar target/quarkus-app/quarkus-run.jar Hello 2
...
[example] (Camel (camel-6) thread #8 - timer://foo) Exchange[Body: Hello]
[example] (Camel (camel-6) thread #8 - timer://foo) Exchange[Body: Hello]
...

Native mode

Important
Native mode requires having GraalVM and other tools installed. Please check the Prerequisites section of Camel Quarkus User guide.

To prepare a native executable using GraalVM, run the following command:

$ mvn clean package -Pnative
$ ./target/*-runner Hello 2
...
[example] (Camel (camel-6) thread #8 - timer://foo) Exchange[Body: Hello]
[example] (Camel (camel-6) thread #8 - timer://foo) Exchange[Body: Hello]
...

Feedback

Please report bugs and propose improvements via GitHub issues of Camel Quarkus project.