2013-06-02 258 views
0

我有這個駱駝路線,其中從一個url的json值插入到我的數據庫。 代碼:apache駱駝休眠插入

@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); 

正如你可以看到所有jenkinsBuilds被加載到一個列表:

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

,當我運行的程序列表是空的第一次。 第二次運行程序時,該列表可以從我的數據庫中獲取所需值。

我的問題是:如何配置我的路線,使列表包含相同的值,如當我第二次運行它?

是否有可能重新啓動整個Configure()方法?

在此先感謝

回答

0

的configure()方法在RouteBuilder只是援引一次時駱駝啓動(或者,如果你在運行時添加路由)。

所以也許你需要的是有一些邏輯來檢查是否有任何jenkins配置數據。如果沒有,然後等待或你需要做什麼。當有數據時,您可以在這個邏輯中創建一個新的RouteBuilder實例並將這些路由添加到正在運行的CamelContext中 - 例如在運行時添加路由。