camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Zoran Regvart <zo...@regvart.com>
Subject Re: Using ConsumerTemplate to fetch files.
Date Fri, 31 Mar 2017 18:41:27 GMT
Hi Dilip,
this to me seems to be an overly complicated solution to a simple
problem. If I understand your problem correctly: you gather a file
from ftp server1 and push to two different ftp servers, serverA and
serverB, the serverA gets the transformed file and serverB gets the
original file (backup)?

Why not do simply:

from("ftp:server1").multicast().to("direct:backup", "direct:transform");
from("direct:transform").bean(responseTranslator,
"translate").to("ftp:serverA");
from("direct:backup").to("ftp:serverB");

Might not be 100% your use case, but you can see it's simpler with
multicast EIP[1]

zoran

[1] https://camel.apache.org/multicast.html

On Fri, Mar 31, 2017 at 4:08 PM, dilip.pashupathi
<dilip.pashupathi@gmail.com> wrote:
> Hi,
> I was working with something similar to this problem. But I am not able to
> capture the exceptions properly.
>
> Setps:
> 1. Download the existing file from the FTP
> 2. Push the file to backup folder and append the file name with current date
> 3. Push a new file to the FTP which has a complete new file
>
> Here is gist of what I am trying to achieve
>
> in RouteBuilder:
>  public void configure() throws Exception {
>
>         onException(Exception.class)
>                 .log("Exception returned due: ${exception.message}")
>                 .to(INTERNAL_ERROR_HANDLER_ENDPOINT_URI)
>                 .to(logError(PACKAGE_NAME))
>                 .handled(true);
>
>        from(INTERNAL_ERROR_HANDLER_ENDPOINT_URI)
>                 .log("File error route triggered due to :
> ${exception?.class}")
>                 .transform().simple("Error ${exception.message}")
>                 .bean(responseTranslator, "translateError")
>                 .end();
>
>        from(ENDPOINT_URI)
>                 .to(log(PACKAGE_NAME))
>                 .process(contentBackupProcessor)
>                 .to(INTERNAL_ENDPOINT_URI)
>                 .end();
>
>        from(INTERNAL_ENDPOINT_URI)
>                 .process(requestProcessor)
>                 .to(ftpHostConfiguration.ftpEndpointForPublishing())
>                 .bean(responseTranslator, "translate")
>                 .to(log(PACKAGE_NAME));
>     }
>
> ContentBackupProcessor:
>
>        logger.debug("File backup processor called.");
>         CamelContext context = exchange.getContext();
>         Endpoint ftp =
> context.getEndpoint(ftpHostConfiguration.ftpConsumerEndpointForBackupProcessor());
>         PollingConsumer consumer = ftp.createPollingConsumer();
>         logger.debug("FTP Consumer created for backup");
>         Endpoint producerFtp =
> context.getEndpoint(ftpHostConfiguration.ftpProducerEndpointForBackupProcessor());
>         ProducerTemplate template =
> exchange.getContext().createProducerTemplate();
>         logger.debug("FTP Producer created for backup");
>         consumer.start();
>         while(true){
>             Exchange result = consumer.receive(5000);
>             if(result == null){
>                 break;
>             }
>             template.send(producerFtp, result);
>         }
>         consumer.stop();
>     }
>
> And this is how my FTP URL Looks like
> URL 1: Consumer URL for downloading the file
> ftp://XXXXC@localhost:8899/?password=XXXXC&consumer.bridgeErrorHandler=true&throwExceptionOnConnectFailed=true&maximumReconnectAttempts=0&useList=true&delete=true
>
> URL 2: Producer URL for moving to backup folder and adding current date to
> the fileName
> ftp://XXXXC@localhost:8899/backup?password=XXXXC&consumer.bridgeErrorHandler=true&throwExceptionOnConnectFailed=true&maximumReconnectAttempts=0&useList=true&fileName=${file:name.noext}_${date:now:yyyyMMdd.hhmmss}.js
>
>
> ftp://XXXX@localhost:8899/?password=XXXX&consumer.bridgeErrorHandler=true&throwExceptionOnConnectFailed=true&maximumReconnectAttempts=0
>
> Since URL 1 and URL 2 is written inside the processor when exception happens
> like unable to connect to FTP, onException is not able to handle that
> properly. And the route ends with a lot of stack trace.
>
> Kindly help. This is a bit urgent since we have a service that needs to be
> delivered urgently.
>
> Thanks & Regards
> Dilip H Pashupathi
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Using-ConsumerTemplate-to-fetch-files-tp3304671p5796786.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Zoran Regvart

Mime
View raw message