Search in sources :

Example 1 with RouteConfigurationsBuilder

use of org.apache.camel.RouteConfigurationsBuilder in project camel-quarkus by apache.

the class CamelContextRecorder method addRoutes.

public void addRoutes(RuntimeValue<CamelContext> context, List<String> nonCdiRoutesBuilderClassNames) {
    List<RoutesBuilder> allRoutesBuilders = new ArrayList<>();
    try {
        for (String nonCdiRoutesBuilderClassName : nonCdiRoutesBuilderClassNames) {
            Class<RoutesBuilder> nonCdiRoutesBuilderClass = context.getValue().getClassResolver().resolveClass(nonCdiRoutesBuilderClassName, RoutesBuilder.class);
            allRoutesBuilders.add(context.getValue().getInjector().newInstance(nonCdiRoutesBuilderClass));
        }
        for (LambdaRouteBuilder builder : context.getValue().getRegistry().findByType(LambdaRouteBuilder.class)) {
            allRoutesBuilders.add(new RouteBuilder() {

                @Override
                public void configure() throws Exception {
                    builder.accept(this);
                }
            });
        }
        for (RoutesBuilder cdiRoutesBuilder : context.getValue().getRegistry().findByType(RoutesBuilder.class)) {
            allRoutesBuilders.add(cdiRoutesBuilder);
        }
        // Add RouteConfigurationsBuilders before RoutesBuilders
        for (RoutesBuilder routesBuilder : allRoutesBuilders) {
            if (routesBuilder instanceof RouteConfigurationsBuilder) {
                context.getValue().addRoutesConfigurations((RouteConfigurationsBuilder) routesBuilder);
            }
        }
        for (RoutesBuilder routesBuilder : allRoutesBuilders) {
            if (!(routesBuilder instanceof RouteConfigurationsBuilder)) {
                context.getValue().addRoutes(routesBuilder);
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : RouteConfigurationsBuilder(org.apache.camel.RouteConfigurationsBuilder) LambdaRouteBuilder(org.apache.camel.builder.LambdaRouteBuilder) RouteBuilder(org.apache.camel.builder.RouteBuilder) ArrayList(java.util.ArrayList) LambdaRouteBuilder(org.apache.camel.builder.LambdaRouteBuilder) RoutesBuilder(org.apache.camel.RoutesBuilder)

Aggregations

ArrayList (java.util.ArrayList)1 RouteConfigurationsBuilder (org.apache.camel.RouteConfigurationsBuilder)1 RoutesBuilder (org.apache.camel.RoutesBuilder)1 LambdaRouteBuilder (org.apache.camel.builder.LambdaRouteBuilder)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1