Corrupted files with Camel Ftp component - apache-camel

I'm using apache camel to make a ftp client for downloading some files to some local directory. The program reads a xml file to get the name of the file that will be fetched from the ftp.The program seems to work except that the files downloaded are corrupted. Right now I'm trying to download some image files but the ones I get are 14.9Kb and corrupted, no error message shown.
This is my code:
main
public void main() throws FileNotFoundException {
BasicConfigurator.configure();
RutaFtp routeBuilder = new RutaFtp();
CamelContext ctx = new DefaultCamelContext();
try {
ctx.addRoutes(routeBuilder);
ctx.start();
Thread.sleep(10000);
ctx.stop();
}
catch (Exception e) {
e.printStackTrace();
}
}
camel route:
from("file:./?fileName=Datos.xml&noop=true")
.split(xpath("//Datos/imagen/text()"))
.setProperty("rutaArchivo", this.body())
.log(LoggingLevel.INFO, "imagen: ${body}")
.process(ExtraerNombre).to("direct:ftp").end();
from("direct:ftp")
.pollEnrich("ftp://"+user+"#"+ftp+"/?password="+password+"&recursive=true&passiveMode=true&fileName=${body}&delete="+borrado+"")
.to("file:C:/outputFolder?flatten=true").end();
}
I've tried using the streamDownload parameter but tha prevents the files to be downloaded (I don't know why)
.pollEnrich("ftp://"+user+"#"+ftp+"/?password="+password+"&recursive=true&passiveMode=true&streamDownload=true&fileName=${body}&delete="+borrado+"")
console log:
INFO | Apache Camel 2.15.1.redhat-621084 (CamelContext: camel-1) is
starting 0 [main] INFO org.apache.camel.impl.DefaultCamelContext -
Apache Camel 2.15.1.redhat-621084 (CamelContext: camel-1) is starting
INFO | JMX is enabled 10 [main] INFO
org.apache.camel.management.ManagedManagementStrategy - JMX is
enabled INFO | Loaded 185 type converters 208 [main] INFO
org.apache.camel.impl.converter.DefaultTypeConverter - Loaded 185
type converters INFO | AllowUseOriginalMessage is enabled. If access
to the original message is not needed, then its recommended to turn
this option off as it may improve performance. 395 [main] INFO
org.apache.camel.impl.DefaultCamelContext - AllowUseOriginalMessage
is enabled. If access to the original message is not needed, then its
recommended to turn this option off as it may improve performance.
INFO | StreamCaching is not in use. If using streams then its
recommended to enable stream caching. See more details at
http://camel.apache.org/stream-caching.html 395 [main] INFO
org.apache.camel.impl.DefaultCamelContext - StreamCaching is not in
use. If using streams then its recommended to enable stream caching.
See more details at http://camel.apache.org/stream-caching.html INFO
| Endpoint is configured with noop=true so forcing endpoint to be
idempotent as well 395 [main] INFO
org.apache.camel.component.file.FileEndpoint - Endpoint is configured
with noop=true so forcing endpoint to be idempotent as well INFO |
Using default memory based idempotent repository with cache max size:
1000 395 [main] INFO org.apache.camel.component.file.FileEndpoint -
Using default memory based idempotent repository with cache max size:
1000 INFO | Route: route1 started and consuming from:
Endpoint[file://./?fileName=Datos.xml&noop=true] 502 [main] INFO
org.apache.camel.impl.DefaultCamelContext - Route: route1 started and
consuming from: Endpoint[file://./?fileName=Datos.xml&noop=true] INFO
| Route: route2 started and consuming from: Endpoint[direct://ftp] 504
[main] INFO org.apache.camel.impl.DefaultCamelContext - Route: route2
started and consuming from: Endpoint[direct://ftp] INFO | Total 2
routes, of which 2 is started. 504 [main] INFO
org.apache.camel.impl.DefaultCamelContext - Total 2 routes, of which
2 is started. INFO | Apache Camel 2.15.1.redhat-621084 (CamelContext:
camel-1) started in 0.504 seconds 507 [main] INFO
org.apache.camel.impl.DefaultCamelContext - Apache Camel
2.15.1.redhat-621084 (CamelContext: camel-1) started in 0.504 seconds INFO | Created default XPathFactory
com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl#5434283f 1533
[Camel (camel-1) thread #0 - file://./] INFO
org.apache.camel.builder.xml.XPathBuilder - Created default
XPathFactory
com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl#5434283f INFO
| imagen: ftp://190.0.56.190:8021/pruebasumman/conductor/71708375.jpg
1635 [Camel (camel-1) thread #0 - file://./] INFO route1 - imagen:
ftp://190.0.56.190:8021/pruebasumman/conductor/71708375.jpg INFO |
Apache Camel 2.15.1.redhat-621084 (CamelContext: camel-1) is shutting
down 10521 [main] INFO org.apache.camel.impl.DefaultCamelContext -
Apache Camel 2.15.1.redhat-621084 (CamelContext: camel-1) is shutting
down INFO | Starting to graceful shutdown 2 routes (timeout 300
seconds) 10524 [main] INFO
org.apache.camel.impl.DefaultShutdownStrategy - Starting to graceful
shutdown 2 routes (timeout 300 seconds) INFO | Waiting as there are
still 3 inflight and pending exchanges to complete, timeout in 300
seconds. 10524 [Camel (camel-1) thread #2 - ShutdownTask] INFO
org.apache.camel.impl.DefaultShutdownStrategy - Waiting as there are
still 3 inflight and pending exchanges to complete, timeout in 300
seconds. INFO | Waiting as there are still 3 inflight and pending
exchanges to complete, timeout in 299 seconds. 11525 [Camel (camel-1)
thread #2 - ShutdownTask] INFO
org.apache.camel.impl.DefaultShutdownStrategy - Waiting as there are
still 3 inflight and pending exchanges to complete, timeout in 299
seconds. INFO | Waiting as there are still 3 inflight and pending
exchanges to complete, timeout in 298 seconds. 12528 [Camel (camel-1)
thread #2 - ShutdownTask] INFO
org.apache.camel.impl.DefaultShutdownStrategy - Waiting as there are
still 3 inflight and pending exchanges to complete, timeout in 298
seconds. INFO | Waiting as there are still 3 inflight and pending
exchanges to complete, timeout in 297 seconds. 13529 [Camel (camel-1)
thread #2 - ShutdownTask] INFO
org.apache.camel.impl.DefaultShutdownStrategy - Waiting as there are
still 3 inflight and pending exchanges to complete, timeout in 297
seconds. INFO | Waiting as there are still 3 inflight and pending
exchanges to complete, timeout in 296 seconds. 14540 [Camel (camel-1)
thread #2 - ShutdownTask] INFO
org.apache.camel.impl.DefaultShutdownStrategy - Waiting as there are
still 3 inflight and pending exchanges to complete, timeout in 296
seconds. INFO | Waiting as there are still 3 inflight and pending
exchanges to complete, timeout in 295 seconds. 15555 [Camel (camel-1)
thread #2 - ShutdownTask] INFO
org.apache.camel.impl.DefaultShutdownStrategy - Waiting as there are
still 3 inflight and pending exchanges to complete, timeout in 295
seconds. INFO | Waiting as there are still 3 inflight and pending
exchanges to complete, timeout in 294 seconds. 16568 [Camel (camel-1)
thread #2 - ShutdownTask] INFO
org.apache.camel.impl.DefaultShutdownStrategy - Waiting as there are
still 3 inflight and pending exchanges to complete, timeout in 294
seconds. INFO | Waiting as there are still 3 inflight and pending
exchanges to complete, timeout in 293 seconds. 17569 [Camel (camel-1)
thread #2 - ShutdownTask] INFO
org.apache.camel.impl.DefaultShutdownStrategy - Waiting as there are
still 3 inflight and pending exchanges to complete, timeout in 293
seconds. INFO | Waiting as there are still 3 inflight and pending
exchanges to complete, timeout in 292 seconds. 18574 [Camel (camel-1)
thread #2 - ShutdownTask] INFO
org.apache.camel.impl.DefaultShutdownStrategy - Waiting as there are
still 3 inflight and pending exchanges to complete, timeout in 292
seconds.
Thanks in advance.

Download image file in binary mode
By default, Camel FTP is downloading file by ASCII mode.
Add binary=true into your ftp route will turn from ASCII mode to binary mode

Related

Apache Camel Route is working under Windows but not Linux

I am executing Camel code in Windows using Eclipse and it is working fine.
However, when I execute the same code in standalone from Linux, the route has print first log but when fetching file it stops without any error.
Here is my code:
from("timer://alertstrigtimer?period=90s&repeatCount=1")
.log(LoggingLevel.INFO, "*******************************Job-Alert-System: Started: alertstrigtimer******************************" + getFileURI(getWorkFilePath(), getWorkFileName()))
.pollEnrich(getFileURI(getWorkFilePath(), getWorkFileName()))
.log(LoggingLevel.INFO, "*******************************Job-Alert-System: Started: alertstrigtimer******************************" + getFileURI(getWorkFilePath(), getWorkFileName()))
.choice()
.when(header("CamelFileName").isNull())
.log(LoggingLevel.INFO, "No File")
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
log.info("Job-Alert-System: No Date File Exist!!!! Calculate 15 Minutes Back and fetching data from Masterdata");
// Do something
}
})
.otherwise()
.log(LoggingLevel.INFO, "Job Alert System: Date File Loaded: ${header.CamelFileName} at ${header.CamelFileLastModified}")
.process(new Processor() {
// Do something by a processor
})
public static String getFileURI(String filePath, String fileName) {
return "file://" + filePath + "?fileName=" + fileName
+ "&preMove=$simple{file:onlyname.noext}.$simple{date:now:yyyy-MM-dd'T'hh-mm-ss}";
}
Here are my logs from the Linux environment:
[main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.21.1 (CamelContext: camel-1) is starting
[main] INFO org.apache.camel.management.ManagedManagementStrategy - JMX is enabled
[main] INFO org.apache.camel.impl.converter.DefaultTypeConverter - Type converters loaded (core: 194, classpath: 0)
[main] INFO org.apache.camel.impl.DefaultCamelContext - StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
[main] INFO org.apache.camel.impl.DefaultCamelContext - Route: route1 started and consuming from: timer://alertstrigtimer?period=90s&repeatCount=1
[main] INFO org.apache.camel.impl.DefaultCamelContext - Route: loadDataAndAlerts started and consuming from: direct://loadDataAndAlerts
[main] INFO org.apache.camel.impl.DefaultCamelContext - Total 2 routes, of which 2 are started
[main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.21.1 (CamelContext: camel-1) started in 0.664 seconds
[Camel (camel-1) thread #1 - timer://alertstrigtimer] INFO route1 - *******************************Job-Alert-System: Started: alertstrigtimer******************************file:///shared/wildfly/work-files/alerts?fileName=LastExecutionTime_JobAlerts.txt&preMove=.2020-10-12T06-48-16
It stops here. It creates a directory structure, but does not move forward.
Logs from My Local Machine:
[main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.21.1 (CamelContext: camel-1) is starting
[main] INFO org.apache.camel.management.ManagedManagementStrategy - JMX is enabled
[main] INFO org.apache.camel.impl.converter.DefaultTypeConverter - Type converters loaded (core: 194, classpath: 5)
[main] INFO org.apache.camel.impl.DefaultCamelContext - StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
[main] INFO org.apache.camel.impl.DefaultCamelContext - Route: route1 started and consuming from: timer://alertstrigtimer?period=90s&repeatCount=1
[main] INFO org.apache.camel.impl.DefaultCamelContext - Route: loadDataAndAlerts started and consuming from: direct://loadDataAndAlerts
[main] INFO org.apache.camel.impl.DefaultCamelContext - Total 2 routes, of which 2 are started
[main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.21.1 (CamelContext: camel-1) started in 0.845 seconds
[Camel (camel-1) thread #1 - timer://alertstrigtimer] INFO route1 - *******************************Job-Alert-System: Started: alertstrigtimer******************************file://null?fileName=null&preMove=null.2020-10-12T10-28-51
[Camel (camel-1) thread #1 - timer://alertstrigtimer] INFO route1 - Job Alert System: Date File Loaded: null.2020-10-12T10-28-51 at 0
It creates directory structure in addition to a file, but the file is not present and it moves forward.

Flink 1.10.0 - The heartbeat of ResourceManager with id xxxx timed out

I am running flink standalone cluster HA in kubernetes. The same setup runs perfectly when using Flink 1.9 but getting below error continuously when using Flink 1.10.
INFO org.apache.flink.runtime.taskexecutor.TaskExecutor - The heartbeat of ResourceManager with id 783439e4ead380c60498e32a8e1c0ce3 timed out.
DEBUG org.apache.flink.runtime.taskexecutor.TaskExecutor - Close ResourceManager connection 783439e4ead380c60498e32a8e1c0ce3.
org.apache.flink.runtime.taskexecutor.exceptions.TaskManagerException: The heartbeat of ResourceManager with id 783439e4ead380c60498e32a8e1c0ce3 timed out.
at org.apache.flink.runtime.taskexecutor.TaskExecutor$ResourceManagerHeartbeatListener.notifyHeartbeatTimeout(TaskExecutor.java:1842)
at org.apache.flink.runtime.heartbeat.HeartbeatMonitorImpl.run(HeartbeatMonitorImpl.java:109)
flink-conf.yaml :
jobmanager.rpc.address: xx.xxx.xx.xxx
jobmanager.rpc.port: 6123
jobmanager.heap.size: 1500m
taskmanager.memory.process.size: 4000m
taskmanager.numberOfTaskSlots: 1
parallelism.default: 1
jobmanager.execution.failover-strategy: region
state.backend: filesystem
state.checkpoints.dir: file:///checkpoints
state.savepoints.dir: file:///savepoints
high-availability: zookeeper
high-availability.jobmanager.port: 50010
high-availability.zookeeper.quorum: xx.xx.xx.xx:xxxx
high-availability.zookeeper.path.root: /flink
high-availability.cluster-id: /ABCD
high-availability.storageDir: file:///recovery
heartbeat.interval: 60000
heartbeat.timeout: 60000
taskmanager.debug.memory.log: true
taskmanager.debug.memory.log-interval: 10000
taskmanager.memory.managed.fraction: 0.1
blob.server.port: 6124
query.server.port: 6125

camel Atomikos XA continually reconecting

I have recently moved my routes over to use XA, I am not sure if this is normal behavior or a problem but I am seeing continual reconnecting in the log and the transaction logs are growing when there is no activity as such on the jms queue.
The logs show the following
16:14:19.777 [Camel (camel-1) thread #0 - JmsConsumer[AAA.TESTQ1]] INFO com.atomikos.datasource.xa.XAResourceTransaction-logInfo - XAResource.start ( 31302E3136322E3230382E3130322E746D30303030323030303032:31302E3136322E3230382E3130322E746D32 , XAResource.TMNOFLAGS ) on resource ConnectionFactoryTESTQM represented by XAResource instance com.ibm.mq.jmqi.JmqiXAResource#27520e8f
16:14:20.806 [Camel (camel-1) thread #0 - JmsConsumer[AAA.TESTQ1]] INFO com.atomikos.jms.AtomikosJmsXaSessionProxy-logInfo - atomikos xa session proxy for resource ConnectionFactoryTESTQM: calling getTransacted on JMS driver session...
16:14:20.806 [Camel (camel-1) thread #0 - JmsConsumer[AAA.TESTQ1]] INFO com.atomikos.jms.AtomikosJmsMessageConsumerProxy-logInfo - atomikos MessageConsumer proxy for com.ibm.mq.jms.MQQueueReceiver#690215c4: close...
16:14:20.822 [Camel (camel-1) thread #0 - JmsConsumer[AAA.TESTQ1]] INFO com.atomikos.datasource.xa.XAResourceTransaction-logInfo - XAResource.end ( 31302E3136322E3230382E3130322E746D30303030323030303032:31302E3136322E3230382E3130322E746D32 , XAResource.TMSUCCESS ) on resource ConnectionFactoryTESTQM represented by XAResource instance com.ibm.mq.jmqi.JmqiXAResource#27520e8f
16:14:20.838 [Camel (camel-1) thread #0 - JmsConsumer[AAA.TESTQ1]] INFO com.atomikos.jms.AtomikosJmsXaSessionProxy-logInfo - atomikos xa session proxy for resource ConnectionFactoryTESTQM: closing session atomikos xa session proxy for resource ConnectionFactoryTESTQM - is terminated ? false
16:14:20.838 [Camel (camel-1) thread #0 - JmsConsumer[AAA.TESTQ1]] INFO com.atomikos.jms.AtomikosJmsConnectionProxy-logInfo - atomikos connection proxy for resource ConnectionFactoryTESTQM: close()...
16:14:20.838 [Camel (camel-1) thread #0 - JmsConsumer[AAA.TESTQ1]] INFO com.atomikos.icatch.imp.CompositeTransactionImp-logInfo - commit() done (by application) of transaction 10.162.208.102.tm0000200002
16:14:20.978 [Camel (camel-1) thread #0 - JmsConsumer[AAA.TESTQ1]] INFO com.atomikos.datasource.xa.XAResourceTransaction-logInfo - XAResource.commit ( 31302E3136322E3230382E3130322E746D30303030323030303032:31302E3136322E3230382E3130322E746D32 , true ) on resource ConnectionFactoryTESTQM represented by XAResource instance com.ibm.mq.jmqi.JmqiXAResource#27520e8f
16:14:21.009 [Camel (camel-1) thread #0 - JmsConsumer[AAA.TESTQ1]] INFO com.atomikos.icatch.imp.BaseTransactionManager-logInfo - createCompositeTransaction ( 300000 ): created new ROOT transaction with id 10.162.208.102.tm0000300002
16:14:21.009 [Camel (camel-1) thread #0 - JmsConsumer[AAA.TESTQ1]] INFO com.atomikos.jms.AtomikosConnectionFactoryBean-logInfo - AtomikosConnectionFactoryBean 'ConnectionFactoryTESTQM': createConnection()...
16:14:21.009 [Camel (camel-1) thread #0 - JmsConsumer[AAA.TESTQ1]] INFO com.atomikos.jms.AtomikosConnectionFactoryBean-logInfo - AtomikosConnectionFactoryBean 'ConnectionFactoryTESTQM': init...
16:14:21.009 [Camel (camel-1) thread #0 - JmsConsumer[AAA.TESTQ1]] INFO com.atomikos.jms.AtomikosJmsConnectionProxy-logInfo - atomikos connection proxy for resource ConnectionFactoryTESTQM: creating XA-capable session...
16:14:21.134 [Camel (camel-1) thread #0 - JmsConsumer[AAA.TESTQ1]] INFO com.atomikos.jms.AtomikosJmsConnectionProxy-logInfo - atomikos connection proxy for resource ConnectionFactoryTESTQM: calling hashCode on JMS driver...
16:14:21.134 [Camel (camel-1) thread #0 - JmsConsumer[AAA.TESTQ1]] INFO com.atomikos.jms.AtomikosJmsConnectionProxy-logInfo - atomikos connection proxy for resource ConnectionFactoryTESTQM: calling hashCode on JMS driver...
16:14:21.134 [Camel (camel-1) thread #0 - JmsConsumer[AAA.TESTQ1]] INFO com.atomikos.jms.AtomikosJmsConnectionProxy-logInfo - atomikos connection proxy for resource ConnectionFactoryTESTQM: calling start on JMS driver...
16:14:21.134 [Camel (camel-1) thread #0 - JmsConsumer[AAA.TESTQ1]] INFO com.atomikos.jms.AtomikosJmsXaSessionProxy-logInfo - atomikos xa session proxy for resource ConnectionFactoryTESTQM: calling createQueue on JMS driver session...
16:14:21.134 [Camel (camel-1) thread #0 - JmsConsumer[AAA.TESTQ1]] INFO com.atomikos.jms.AtomikosJmsXaSessionProxy-logInfo - atomikos xa session proxy for resource ConnectionFactoryTESTQM: calling createConsumer on JMS driver session com.ibm.mq.jms.MQXASession#41a4d0d0
16:14:21.150 [Camel (camel-1) thread #0 - JmsConsumer[AAA.TESTQ1]] INFO com.atomikos.jms.AtomikosJmsMessageConsumerProxy-logInfo - atomikos MessageConsumer proxy for com.ibm.mq.jms.MQQueueReceiver#3cb81a5f: receive ( 1000 )...
16:14:21.150 [Camel (camel-1) thread #0 - JmsConsumer[AAA.TESTQ1]] INFO com.atomikos.jms.AtomikosJmsMessageConsumerProxy-logInfo - atomikos MessageConsumer proxy for com.ibm.mq.jms.MQQueueReceiver#3cb81a5f: receive ( 1000 , null )...
16:14:21.150 [Camel (camel-1) thread #0 - JmsConsumer[AAA.TESTQ1]] INFO com.atomikos.icatch.imp.CompositeTransactionImp-logInfo - registerSynchronization ( com.atomikos.jms.ConsumerProducerSupport$JmsRequeueSynchronization#4d70e77 ) for transaction 10.162.208.102.tm0000300002
16:14:21.150 [Camel (camel-1) thread #0 - JmsConsumer[AAA.TESTQ1]] INFO com.atomikos.icatch.imp.CompositeTransactionImp-logInfo - addParticipant ( XAResourceTransaction: 31302E3136322E3230382E3130322E746D30303030333030303032:31302E3136322E3230382E3130322E746D33 ) for transaction 10.162.208.102.tm0000300002
If this is normal then I will just surpress the logging but I figured it worth checking.
thanks
Paul

Apache Camel: wireTap and graceful shutdown

While I was debugging my Camel application I realized, that the graceful shutdown of a route ignores the outstanding tasks that have been triggered by wireTap().
If I have a route definition like this:
from("direct:start")
.wireTap("bean:myWireTapBean")
.to("mock:result");
and I set a debugging breakpoint in myWireTapBean (i.e. suspend the asynchronous processing of wireTap) then a CamelContext.stopRoute(routeId) call produces the following log messages:
11:36:12.352 [Thread-1] INFO o.a.camel.spring.SpringCamelContext - Apache Camel 2.19.1 (CamelContext: camel-1) is shutting down
11:36:12.352 [Thread-1] INFO o.a.c.impl.DefaultShutdownStrategy - Starting to graceful shutdown 1 routes (timeout 300 seconds)
11:36:12.352 [Camel (camel-1) thread #6 - ShutdownTask] INFO o.a.c.impl.DefaultShutdownStrategy - Route: route1 shutdown complete, was consuming from: direct://myRoute
11:36:12.352 [Thread-1] INFO o.a.c.impl.DefaultShutdownStrategy - Graceful shutdown of 1 routes completed in 0 seconds
11:36:12.478 [Thread-1] WARN o.a.c.impl.DefaultInflightRepository - Shutting down while there are still 1 inflight exchanges.
11:36:12.478 [Thread-1] INFO o.a.camel.spring.SpringCamelContext - Apache Camel 2.19.1 (CamelContext: camel-1) uptime 1.411 seconds
11:36:12.478 [Thread-1] INFO o.a.camel.spring.SpringCamelContext - Apache Camel 2.19.1 (CamelContext: camel-1) is shutdown in 0.126 seconds
Is there any way to prevent Camel from shutting down while there are still inflight exchanges in the DefaultInflightRepository that have been created by wireTap?
I've already read the FAQ: How can I stop a route from a route but this doesn't seem to be an answer to this question.
Yeah the current implementation of WireTap does not take in account of active tasks if they are not being routed.
I logged a ticket to add support for deferring shutdown of the WireTap EIP if it has inflight tasks: https://issues.apache.org/jira/browse/CAMEL-11539
The workaround is to create a route such as direct and then call that route where you can then call the bean, then when you shutdown Camel the direct route will have inflight exchanges and therefore wait for it to complete.
The DefaultShutdownStrategy's default behavior is to complete route shutdowns, so it is one of those things where the default works for many scenarios, but not all and you are in the latter. If the exchange is run within a transaction, it would rollback, you might look at sourcing from a JMS queue or other so you can rollback and resume processing.
The Javadocs have good information on the behavior and various options you can use to configure the DefaultShutdownStrategy before considering writing a custom one:
DefaultShutdownStrategy

Apache camel file component not moving files

I'm using apache camel 2.12.1 to create a route and then move some files in my local directory, the exmple runs fine but the files are never moved, this is the code for the class.
public class MoveFilesTest {
private static final Log LOG = LogFactory.getLog(MoveFilesTest.class);
public static void main(String args[]) throws Exception {
LOG.debug("create CamelContext");
CamelContext context = new DefaultCamelContext();
// add our route to the CamelContext
context.addRoutes(new RouteBuilder() {
File file = null;
public void configure() {
from("file:data/inbox?delay=100&noop=true")
.process( new Processor() {
public void process(Exchange msg) throws Exception {
File file = msg.getIn().getBody(File.class);
LOG.debug("Processing file: " + file.getName());
}
})
.to("file:data/outbox").end();
}
});
LOG.debug("start the route and let it do its work");
context.start();
context.stop();
}
}
as a note, this code just to work, now i'm working on mac os x 10.7, this is the debug log. i added the noop=false and the delete=true, but the result is the same. thank you
DEBUG [main] (MoveFilesTest.java:24) - create CamelContext
DEBUG [main] (MoveFilesTest.java:45) - start the route and let it do its work
INFO [main] (DefaultCamelContext.java:1498) - Apache Camel 2.12.1 (CamelContext: camel-1) is starting
INFO [main] (ManagedManagementStrategy.java:187) - JMX is enabled
INFO [main] (DefaultTypeConverter.java:50) - Loaded 176 type converters
INFO [main] (DefaultCamelContext.java:1689) - StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
INFO [main] (FileEndpoint.java:83) - Endpoint is configured with noop=true so forcing endpoint to be idempotent as well
INFO [main] (FileEndpoint.java:89) - Using default memory based idempotent repository with cache max size: 1000
INFO [main] (DefaultCamelContext.java:2183) - Route: route1 started and consuming from: Endpoint[file://data/inbox?delay=100&noop=true]
INFO [main] (DefaultCamelContext.java:1533) - Total 1 routes, of which 1 is started.
INFO [main] (DefaultCamelContext.java:1534) - Apache Camel 2.12.1 (CamelContext: camel-1) started in 8.936 seconds
INFO [main] (DefaultCamelContext.java:1706) - Apache Camel 2.12.1 (CamelContext: camel-1) is shutting down
INFO [main] (DefaultShutdownStrategy.java:172) - Starting to graceful shutdown 1 routes (timeout 300 seconds)
INFO [Camel (camel-1) thread #2 - ShutdownTask] (DefaultShutdownStrategy.java:600) - Route: route1 shutdown complete, was consuming from: Endpoint[file://data/inbox?delay=100&noop=true]
INFO [main] (DefaultShutdownStrategy.java:217) - Graceful shutdown of 1 routes completed in 0 seconds
INFO [main] (DefaultCamelContext.java:1780) - Apache Camel 2.12.1 (CamelContext: camel-1) uptime 8.953 seconds
INFO [main] (DefaultCamelContext.java:1781) - Apache Camel 2.12.1 (CamelContext: camel-1) is shutdown in 0.013 seconds
Yes, you start Camel and stop it immediately. So, when you put a file to a folder. It wont process cuz camel is already stopped.
Camel contains Main implementation to keep Camel running in standalone application.
There is link: http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html
CamelContext.start does not block, so basically you are starting the context and then immediately stopping it. You need to wait or block on something until the context should stop. You can reference this thread for some ways of doing this.
I had a similar problem but that was to do with streamCaching() not getting set properly and so the code below was failing
context.getStreamCachingStrategy().setSpoolDirectory(spoolDirectory);
from(uri.toString()).streamCaching().to(destination);
I set the Streaming directly on CamelContext and that solved the problem
CamelContext context = getContext();
context.setStreamCaching(true);
context.getStreamCachingStrategy().setSpoolDirectory(localSpoolDirectory);
context.getStreamCachingStrategy().setSpoolThreshold(Long.parseLong(spoolThreshold.trim()));
context.getStreamCachingStrategy().setBufferSize(Integer.parseInt(bufferSize.trim()));

Resources