Hi, I created a project, I want that the route stops when the Camel Batch are
complete, I used 
SimpleScheduledRoutePolicy but you have to define a start an end date, and
always stop the route before the route finish to process. I did this, works
fine, but I think there is a better way


//Creamos una ruta adicional en el contexto
        context.addRoutes(new RouteBuilder() {
                
                
            public void configure() {
            
onException(Exception.class).setRedeliveryPolicy(redeliveryPolicy);
                
                
                from("smb://"+ inputXrtSmbDomain +";"+ inputXrtSmbUser +"@"+
inputXrtSmbServer +"/"+ inputXrtSmbFolder +"?password="+ inputXrtSmbPassword
+ "&delete=false&delay=60000")
                .routeId("sap-xrt-connect-interface-receive-" + fileNameOnly)
            
.setProperty("CamelBatchComplete").simple("${property.CamelBatchComplete}")
                .process(new Processor() {
                        @Override
                                public void process(Exchange exchange) throws 
Exception {
                        
                                CamelBatchComplete =
exchange.getProperty("CamelBatchComplete").toString();
                                }
                })
                .filter().method(new GenericFileFilter<T> (){
                                                
                        @Override
                        public boolean accept(GenericFile<T> file) {
                                    
                                Date fileNameLastModified = new
Date(file.getLastModified());
                                                        
                                
                                //Se realiza la comprobacion de fechas
                                
if(fileNameLastModified.after(documentDateBefore) &&
fileNameLastModified.before(documentDateAfter)){
                                        return true;
                                }else{
                                        return false;
                                }
                                
                        }
                }).process(new Processor() {
                        @Override
                                public void process(Exchange exchange) throws 
Exception {
                        
                                GenericFileMessage<File> msg =
exchange.getIn(GenericFileMessage.class);
                        String fileName []=
msg.getGenericFile().getFileNameOnly().split("\\.");                      
                        
                        // Se realiza la validacion de cuando el fichero
tiene extension o no
                        String destinationPath = String.format("%s%s_%s",
fileNameOnly,fileName[0], 2 <= fileName.length ? fileName[1] : "");    
                        
                        exchange.getOut().setBody(msg.getBody());
                                exchange.getOut().setHeader(Exchange.FILE_NAME,
destinationPath);
                                
                   }
                })
                .to("sftp://"+ outputSapFtpUser +"@"+ outputSapFtpServer
+"/"+ outputSapFtpPFolder +"?flatten=true&password="+ outputSapFtpPassword
+"&passiveMode="+ outputSapFtpPassiveMode +"&binary=true&autoCreate=false")
                .log("sent file ${file:name} to SAP");
            }
        });


The Stop Code


if(context.getRouteStatus("sap-xrt-connect-interface-receive-" +
fileNameOnly).isStarted()){  // Se verifica si se inicio la ruta
                
                int CamelBatchValidator = 0; 
                do{
                        
                        Thread.sleep(10000); // Se realiza la verificacion cada 
10
segundos si la interfaz culmino su procesamiento 
                                
                        if (CamelBatchComplete=="true"){
                                        
                                  Thread.sleep(20000); // Tiempo adicional para 
verificar que
todo ha culminado
                                                             
                                  
context.stopRoute("sap-xrt-connect-interface-receive-" +
fileNameOnly);
                                  
                                  Thread.sleep(10000);
                                  
                                  
context.removeRoute("sap-xrt-connect-interface-receive-" +
fileNameOnly);
                                  
                              CamelBatchValidator=1;
                              CamelBatchComplete = null;
                        }else{
                                
                                //Si la ruta esta vacia o hay error al conectar 
, esto hara que
entre en el IF de arriba y elimine la ruta
                                if(CamelBatchComplete == null){
                                        
                                        CamelBatchComplete="true";
                                }
                                
                        }
                        
                        
                }while(CamelBatchValidator==0);



--
View this message in context: 
http://camel.465427.n5.nabble.com/How-to-stop-a-dynamic-route-tp5783385.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to