apache camel - How to stop file transferring in spring-batch -
i have created spring-batch job reading files local directory , upload remote directory through ftp using camel-spring-batch. doing same using chunk. spring batch job configuration looks :
<bean id="consumertemplate" class="org.apache.camel.impl.defaultconsumertemplate" init-method="start" destroy-method="stop"> <constructor-arg ref="camelcontext"/> </bean> <bean id="producertemplate" class="org.apache.camel.impl.defaultproducertemplate" scope="step" init-method="start" destroy-method="stop"> <constructor-arg ref="camelcontext"/> </bean> <bean id="localfilereader" class="com.camel.springbatch.reader.localfilereader" scope="step" destroy-method="stop"> <constructor-arg value="file:#{jobparameters['dirpath']}"/> <constructor-arg ref="consumertemplate"/> </bean> <bean id="ftpfilewriter" class="com.camel.springbatch.writer.ftpfilewriter" scope="step"> <constructor-arg ref="producertemplate"/> <constructor-arg value="ftp://#{jobparameters['host']}?username=#{jobparameters['user']}&password=#{jobparameters['password']}"/> </bean>
job configuration :
<batch:job id="ftpreadwrite"> <batch:step id="readfromlocalwritetoftp" next="readfromftpwritetolocal"> <batch:tasklet> <batch:chunk reader="localfilereader" writer="ftpfilewriter" commit-interval="5" /> </batch:tasklet> </batch:step>
and "localfilereader" , "ftpfilewriter" looks :
import org.apache.camel.consumertemplate; import org.apache.camel.component.spring.batch.support.camelitemreader; import org.slf4j.logger; import org.slf4j.loggerfactory; public class localfilereader extends camelitemreader { private logger log= loggerfactory.getlogger(this.getclass()); consumertemplate consumertemplate; string endpointuri; public localfilereader(consumertemplate consumertemplate, string endpointuri) { super(consumertemplate, endpointuri); this.consumertemplate=consumertemplate; this.endpointuri=endpointuri; } @override public object read() throws exception { object item = consumertemplate.receivebody(endpointuri); return item; }
}
"ftp file writer"
import org.apache.camel.producertemplate; import org.apache.camel.component.spring.batch.support.camelitemwriter; import org.slf4j.logger; import org.slf4j.loggerfactory; import java.util.list; public class ftpfilewriter extends camelitemwriter { private logger log= loggerfactory.getlogger(this.getclass()); producertemplate producertemplate; string endpointuri; public ftpfilewriter(producertemplate producertemplate, string endpointuri) { super(producertemplate, endpointuri); this.producertemplate=producertemplate; this.endpointuri=endpointuri; } @override public void write(list items) throws exception { system.out.println("************************writing item ftp "+items); (object item : items) { system.out.println("writing item [{}]..."+item); producertemplate.sendbody(endpointuri, item); log.debug("wrote item"); } } }
it works fine if have 5 file in local directory. read 5 file local directory , send writer , writer send ftp server commit-interval=5. if have 6 file in in local directory send first chunk of 5 file writer , again start reading remaining file , time there 1 file remaining. read 1 file , start waiting 4 files , never send writer. tried commit-interval=1 send 6 files server , again start waiting next file. here need stop process once file have been processed.
please me resolved issue...
from consumertemplate
's javadoc receivebody
waits until there response; need work timeout (check timeoutpolicy in spring-batch) or different way mark reader 'exhausted' (return null reader) stop reader reading
Comments
Post a Comment