Explicitly define Camel Routes in Quarkus

Viewed 120

Current behaviour: When I'm running a Quarkus App with Camel it automatically starts all the RouteBuilder Extensions as Routes.

What I want to achieve: On startup only the Routes that I configured are started.

What I tried:

  1. With the following snippet it's possible to explicitly start the CamelMainApplication but I dont know how to get control over e.g. the CamelContext at this point where I would be able to configure my routes.
@QuarkusMain
public class Main {
    public static void main(String[] args) throws Exception {
        Quarkus.run(CamelMainApplication.class, args);
    }
}
  1. On the Route I can use .noAutoStartup() to disable the route on startup. But this means that it's not the default for all routes to be disabled at first and second I don't know where to activate them as I don't know where in a Quarkus App I can get a hand on the Camel Context to activate the route.

  2. With the following in my application.yml I can disable the automatic route discovery but then the remaining question is how I can manually start the route, e.g. in my QuarkusMain class.

quarkus:
 camel:
   routes-discovery:
     enabled: false
2 Answers

I think it is best way. Quarkus has properties for include and exclude route as pattern. this properties is List You can add one to N

quarkus.camel.routes-discovery.exclude-patterns=tes.Comp,tes.package.MyRoute
quarkus.camel.routes-discovery.include-patterns=test.mypackage.XX

I had this same problem I ended up doing something like the following:

@QuarkusMain
public class Main implements QuarkusApplication {

   @Inject
   OrderService orderService;

    @Override
    public int run(String... args) throws Exception {
        CamelRuntime runtime = Arc.container().instance(CamelRuntime.class).get();
        runtime.start(new String[]{});

        orderService.handleOrders(args[0]); //this would inject the camelContext and start the route. 


        return 0;
    }

Related