有一条路由会在30分钟后从SFTP读取
public class ApplicationRoutesBuilder extends RouteBuilder {
"sftp://10.10.10.10/emp"
+ "?username=xxx"
+ "&password=yyy" // Stored on wildfly server
+ "&download=true" //Shall be read chunk by chunk to avoid heap space issues. Earlier download=true was used:
+ "&useList=true"
+ "&stepwise=false"
+ "&disconnect=true"
+ "&passiveMode=true"
+ "&reconnectDelay=1800000"
+ "&bridgeErrorHandler=true"
+ "&delay=30000"
//+ "&fileName=" + sftpFileName
+ "&include="+ sftpFileName
+ "&preMove=$simple{file:onlyname}.$simple{date:now:yyyy-MM-dd'T'hh-mm-ss}.processing"
+ "&move=$simple{file:onlyname.noext}.$simple{date:now:yyyy-MM-dd'T'hh-mm-ss}.success"
+ "&moveFailed=$simple{file:onlyname.noext}.$simple{date:now:yyyy-MM-dd'T'hh-mm-ss}.failed"
+ "&readLock=idempotent-changed"
+ "&idempotentRepository=#infinispan"
+ "&readLockRemoveonCommit=true"
//ROUTE IS
from("ABOVE SFTP STRING")
.onException(GenericfileOperationFailedException.class)
.onWhen(exchange -> {
Throwable cause = exchange.getException(GenericfileOperationFailedException.class).getcause();
return (cause != null && cause.toString().equalsIgnoreCase("2: No such file"));
})
.handled(true)
.logExhausted(true)
.logExhaustedMessageHistory(true)
// For troubleshooting. TODO: remove on final deploy
.log("Could not find file")
.end()
.to(archiveReceivedFile(sftpFileName))
.log("Archived Successfully in HRM Archive Directory")
.bean("service1","enrichFromAd")
.log("Loaded IFS and AD Successfully into Memory")
.split(body().tokenizeXML("EmploymentRequest","EmploymentRequests")) // Split and tokenize the requests,streaming individual requests to message queue
.unmarshal(new JaxbdataFormat(JAXBContext.newInstance(EmploymentRequest.class)))
.bean("service1","updateEmployeeData")
.marshal(new JaxbdataFormat(JAXBContext.newInstance(EmploymentRequest.class)))
.inOnly(EMPLOYEES_QUEUE)
.choice()
.when(header("CamelSplitComplete"))
.log("Download xml file completed");
我想手动触发此路线。我们如何使用Apache Camel做到这一点?
//到目前为止,我们正在重新加载或取消部署,部署或重新启动服务器,以在负载时触发路由或将时间减少到30秒。但是我不想要这个。我可以创建Trig文件或重命名,也可以使用JSP页面进行Trig。但是什么代码将触发该线程?
以下是上下文初始化:
@ApplicationScoped
public class ApplicationCamelContext extends DefaultCamelContext {
private static final Logger LOGGER = LoggerFactory.getLogger( ApplicationCamelContext.class.getName() );
@PostConstruct
void customize() {
LOGGER.info("Started ApplicationCamelContext: customize");
setName("employee-import");
getShutdownStrategy().setTimeout(2L);
LOGGER.info("Shutdown ApplicationCamelContext: customize");
}
}