0

I have this camel route where json values from an url are inserted into my database. code:

@Override
public void configure() throws Exception {
    //voor elke tabel een andere route want bij wijzigingen json formaat crashed enkel 1 routebuilder
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    DataFormat jenkinsConfigFormat = new JacksonDataFormat(objectMapper, JenkinsConfiguration.class);

    jenkinsConfigurations = configurationService.listJenkinsConfigurations();
    logger.info("Starting routes for " + jenkinsConfigurations.size() + " jenkins configurations");

    for (JenkinsConfiguration configuration : jenkinsConfigurations) {
        from("timer://foo?fixedRate=true&period=120s&delay=20s")
                .to(configuration.getUrl() + "/api/json")
                .routeId(BUILD_ROUTE)
                .unmarshal(jenkinsConfigFormat)
                .enrich("direct:jenkinsconfig", new UseLatestAggregationStrategy())
                .split(simple("${body.builds}"))
                .choice()
                .when(buildNumberAlreadyExists())
                .otherwise()
                .to("hibernate:be.kdg.teamf.model.Build")
                .end();

        from("timer://foo?fixedRate=true&period=120s&delay=20s")
                .routeId(HEALTH_ROUTE)
                .to(configuration.getUrl() + "/api/json")
                .unmarshal(jenkinsConfigFormat)
                .enrich("direct:jenkinsconfig", new UseLatestAggregationStrategy())
                .split(simple("${body.healthReport}"))
                .choice()
                .when(healthReportAlreadyExists())
                .otherwise()
                .to("hibernate:be.kdg.teamf.model.HealthReport")
                .end();

        from("timer://foo?fixedRate=true&period=120s&delay=20s")
                .routeId(MODULE_ROUTE)
                .to(configuration.getUrl() + "/api/json")
                .unmarshal(jenkinsConfigFormat)
                .enrich("direct:jenkinsconfig", new UseLatestAggregationStrategy())
                .split(simple("${body.modules}"))
                .choice()
                .when(moduleAlreadyExists())
                .otherwise()
                .to("hibernate:be.kdg.teamf.model.Module")
                .end();

        List<Build> jenkinsBuilds = buildService.getBuildsJenkinsProject(configuration);
        DataFormat buildConfigFormat = new JacksonDataFormat(objectMapper, BuildDetail.class);

As you can see all jenkinsBuilds are loaded into a list:

List<Build> jenkinsBuilds = buildService.getBuildsJenkinsProject(configuration);

The first time when I run the program the list is empty. The second time when I run the program the list is able to get the wanted values from my database.

My question is: How can I configure my routes so the list contains the same values like when i run it the second time?

Is it maybe possible to restart the whole Configure() method?

thanks in advance

4

1 回答 1

0

RouteBuilder 中的 configure() 方法仅在 Camel 启动时调用一次(或者如果您在运行时添加路由)。

所以也许你需要的是有一些逻辑来检查是否有任何 jenkins 配置数据。如果没有,请等待或您需要做什么。当有数据时,您可以在此逻辑中创建一个新的 RouteBuilder 实例并将这些路由添加到正在运行的 CamelContext - 例如在运行时添加路由。

于 2013-06-03T13:53:45.247 回答